Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bucket Logging: Add unit tests for bucket logging #8155

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions src/test/unit_tests/test_np_bucket_logging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/* Copyright (C) 2020 NooBaa */
'use strict';

const mocha = require('mocha');
const assert = require('assert');
const _ = require('lodash');
const P = require('../../util/promise');
const coretest = require('./coretest');
const { rpc_client } = coretest; //, PASSWORD, SYSTEM

coretest.setup({ pools_to_create: [coretest.POOL_LIST[0]] });

mocha.describe('noobaa bucket logging configuration validity tests', function() {
const source1 = 'source-bucket-1';
const source2 = 'source-bucket-2';
const log1 = 'log-bucket';

const no_log_bucket = 'no-log-bucket';
const no_source_bucket = 'no-source-bucket';

const log_prefix_1 = 'xxxxx/';
const log_prefix_2 = 'yyyyy/';
const no_log_prefix = '';

const buckets = [source1, source2, log1];

mocha.before('create buckets', async function() {
await P.all(_.map(buckets, async bucket_name => {
await rpc_client.bucket.create_bucket({ name: bucket_name });
}));
});

mocha.after('delete buckets', async function() {
await P.all(_.map(buckets, async bucket_name => {
await rpc_client.bucket.delete_bucket({ name: bucket_name });
}));
});

mocha.it('_put_bucket_logging - all parameter provided - should not fail', async function() {
await _put_bucket_logging(source1, log1, log_prefix_1, false, "");
});

mocha.it('_put_bucket_logging - log prefix not provided - should not fail', async function() {
await _put_bucket_logging(source1, log1, no_log_prefix, false, "");
});

mocha.it('_put_bucket_logging - log bucket does not exist - should fail', async function() {
await _put_bucket_logging(source2, no_log_bucket, log_prefix_1, true, "INVALID_TARGET_BUCKET");
});

mocha.it('_put_bucket_logging - source bucket does not exist - should fail', async function() {
await _put_bucket_logging(no_source_bucket, log1, log_prefix_1, true, "NO_SUCH_BUCKET");
});

mocha.it('_put_bucket_logging - second source bucket configured with same log bucket - should not fail', async function() {
await _put_bucket_logging(source2, log1, log_prefix_2, false, "");
});

mocha.it('_get bucket logging ', async function() {
await _get_bucket_logging(source1, false, "");
});

mocha.it('_get bucket logging ', async function() {
await _get_bucket_logging(no_source_bucket, true, "NO_SUCH_BUCKET");
});
});

async function _put_bucket_logging(source_bucket_name, log_bucket_name, log_prefix, should_fail, error_message) {
try {
await rpc_client.bucket.put_bucket_logging({ name: source_bucket_name, log_bucket: log_bucket_name, log_prefix: log_prefix });
if (should_fail) {
assert.fail(`put_bucket_logging should fail but it passed`);
}
} catch (err) {
if (should_fail) {
assert.deepStrictEqual(err.rpc_code, error_message);
return;
}
assert.fail(`put_bucket_logging failed ${err}, ${err.stack}`);
}
}

async function _get_bucket_logging(source_bucket_name, should_fail, error_message) {
try {
await rpc_client.bucket.get_bucket_logging({ name: source_bucket_name});
if (should_fail) {
assert.fail(`get_bucket_logging should fail but it passed`);
}
} catch (err) {
if (should_fail) {
assert.deepStrictEqual(err.rpc_code, error_message);
return;
}
assert.fail(`get_bucket_logging failed ${err}, ${err.stack}`);
}
}