2019-06-15 12:23:12 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "require.h"
|
|
|
|
#include "uplink.h"
|
2019-06-21 13:24:06 +01:00
|
|
|
#include "helpers.h"
|
2019-06-15 12:23:12 +01:00
|
|
|
|
|
|
|
void handle_project(ProjectRef project);
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
2019-06-24 03:06:14 +01:00
|
|
|
with_test_project(&handle_project);
|
2019-06-15 12:23:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_project(ProjectRef project) {
|
|
|
|
char *_err = "";
|
|
|
|
char **err = &_err;
|
|
|
|
|
2019-06-21 13:24:06 +01:00
|
|
|
char *bucket_names[] = {"test-bucket1", "test-bucket2", "test-bucket3", "test-bucket4"};
|
2019-06-15 12:23:12 +01:00
|
|
|
int num_of_buckets = sizeof(bucket_names) / sizeof(bucket_names[0]);
|
|
|
|
|
|
|
|
// TODO: test with different bucket configs
|
2019-06-21 13:24:06 +01:00
|
|
|
{ // Create buckets
|
2019-06-15 12:23:12 +01:00
|
|
|
for (int i=0; i < num_of_buckets; i++) {
|
|
|
|
char *bucket_name = bucket_names[i];
|
|
|
|
|
|
|
|
BucketConfig config = test_bucket_config();
|
|
|
|
BucketInfo info = create_bucket(project, bucket_name, &config, err);
|
|
|
|
require_noerror(*err);
|
|
|
|
|
|
|
|
require(strcmp(bucket_name, info.name) == 0);
|
|
|
|
require(info.created != 0);
|
|
|
|
|
|
|
|
require(config.encryption_parameters.cipher_suite == info.encryption_parameters.cipher_suite);
|
|
|
|
require(config.encryption_parameters.block_size == info.encryption_parameters.block_size);
|
|
|
|
|
|
|
|
require(config.redundancy_scheme.algorithm == info.redundancy_scheme.algorithm);
|
|
|
|
require(config.redundancy_scheme.share_size == info.redundancy_scheme.share_size);
|
|
|
|
require(config.redundancy_scheme.required_shares == info.redundancy_scheme.required_shares);
|
|
|
|
require(config.redundancy_scheme.repair_shares == info.redundancy_scheme.repair_shares);
|
|
|
|
require(config.redundancy_scheme.optimal_shares == info.redundancy_scheme.optimal_shares);
|
|
|
|
require(config.redundancy_scheme.total_shares == info.redundancy_scheme.total_shares);
|
|
|
|
|
|
|
|
free_bucket_info(&info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-05 13:34:35 +01:00
|
|
|
// TODO: test more list options
|
2019-06-15 12:23:12 +01:00
|
|
|
{ // listing buckets
|
2019-09-05 13:34:35 +01:00
|
|
|
BucketListOptions list_options = {
|
|
|
|
.direction = STORJ_FORWARD
|
|
|
|
};
|
|
|
|
BucketList bucket_list = list_buckets(project, &list_options, err);
|
2019-06-15 12:23:12 +01:00
|
|
|
require_noerror(*err);
|
|
|
|
require(bucket_list.more == 0);
|
|
|
|
require(bucket_list.length == num_of_buckets);
|
|
|
|
require(bucket_list.items != NULL);
|
|
|
|
|
|
|
|
for(int i = 0; i < bucket_list.length; i++) {
|
|
|
|
BucketInfo *info = &bucket_list.items[i];
|
|
|
|
require(strcmp(info->name, bucket_names[i]) == 0);
|
|
|
|
require(info->created != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
free_bucket_list(&bucket_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // getting bucket infos
|
|
|
|
for(int i = 0; i < num_of_buckets; i++) {
|
|
|
|
char *bucket_name = bucket_names[i];
|
|
|
|
BucketInfo info = get_bucket_info(project, bucket_name, err);
|
|
|
|
require_noerror(*err);
|
|
|
|
require(strcmp(info.name, bucket_names[i]) == 0);
|
|
|
|
require(info.created != 0);
|
|
|
|
|
|
|
|
free_bucket_info(&info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-27 18:36:51 +01:00
|
|
|
{ // encryption context handling
|
|
|
|
char *enc_ctx = "12VtN2sbbn9PvaEvNbNUBiSKnRcSUNxBADwDWGsPY7UV85e82tT6u";
|
2019-06-15 12:23:12 +01:00
|
|
|
|
2019-06-27 18:36:51 +01:00
|
|
|
BucketRef bucket = open_bucket(project, bucket_names[0], enc_ctx, err);
|
2019-06-15 12:23:12 +01:00
|
|
|
require_noerror(*err);
|
|
|
|
requiref(bucket._handle != 0, "got empty bucket\n");
|
|
|
|
|
|
|
|
// TODO: exercise functions that operate on an open bucket to add assertions
|
|
|
|
close_bucket(bucket, err);
|
|
|
|
require_noerror(*err);
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // deleting buckets
|
|
|
|
for(int i = 0; i < num_of_buckets; i++) {
|
|
|
|
delete_bucket(project, bucket_names[i], err);
|
|
|
|
require_noerror(*err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|