Skip to content

Commit

Permalink
add testing cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-jy committed Nov 28, 2024
1 parent 4e68026 commit 6af0581
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 5 deletions.
6 changes: 2 additions & 4 deletions lib/file_transfer_agent/s3_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@ function S3Util(connectionConfig, s3, filestream) {
this.createClient = function (stageInfo, useAccelerateEndpoint) {
const stageCredentials = stageInfo['creds'];
const securityToken = stageCredentials['AWS_TOKEN'];
// if GS sends us an endpoint, it's likely for FIPS. Use it.
const useS3RegionalUrl = stageInfo.useRegionalUrl || stageInfo.useS3RegionalUrl;

// const useS3RegionalUrl = stageInfo.useRegionalUrl ||stageInfo.useS3RegionalUrl;
const useS3RegionalUrl = true;

// if GS sends us an endpoint, it's likely for FIPS. Use it.
let endPoint = null;
if (stageInfo['endPoint']) {
endPoint = `https://${stageInfo['endPoint']}`;
Expand Down
33 changes: 33 additions & 0 deletions test/unit/file_transfer_agent/gcs_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,39 @@ describe('GCS client', function () {
GCS = new SnowflakeGCSUtil(httpclient, filestream);
});

describe('AWS client endpoint testing', async function () {
const originalStageInfo = meta.stageInfo;
const testCases = [
{
name: 'when useRegionalURL is only enabled',
stageInfo: {
...originalStageInfo,
useRegionalURL: true,
},
endPoint: null,
result: 'storage.mocklocation.rep.googleapis.com'
},
{
name: 'when region is me-central2',
stageInfo: {
...originalStageInfo,
useRegionalURL: false,
endPoint: null,
region: 'me-central2'
},
result: 'storage.me-central2.rep.googleapis.com`'
},
];

testCases.forEach(({ name, stageInfo, result }) => {
it(name, () => {
const client = GCS.createClient(stageInfo);
assert.strictEqual(client.gcsClient.apiEndPoint, result);
} );

});
});

it('extract bucket name and path', async function () {
const GCS = new SnowflakeGCSUtil();

Expand Down
57 changes: 56 additions & 1 deletion test/unit/file_transfer_agent/s3_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('S3 client', function () {

before(function () {
mock('s3', {
S3: function () {
S3: function (config) {
function S3() {
this.getObject = function () {
function getObject() {
Expand All @@ -57,6 +57,8 @@ describe('S3 client', function () {

return new getObject;
};

this.config = config;
this.putObject = function () {
function putObject() {
this.then = function (callback) {
Expand All @@ -82,6 +84,59 @@ describe('S3 client', function () {
AWS = new SnowflakeS3Util(noProxyConnectionConfig, s3, filesystem);
});

describe('AWS client endpoint testing', async function () {
const originalStageInfo = meta.stageInfo;
const testCases = [
{
name: 'when useS3RegionalURL is only enabled',
stageInfo: {
...originalStageInfo,
useS3RegionalUrl: true,
},
endPoint: null,
result: null
},
{
name: 'when useS3RegionalURL and is enabled and domain starts with cn',
stageInfo: {
...originalStageInfo,
useS3RegionalUrl: true,
endPoint: null,
region: 'cn-mockLocation'
},
result: 'https://s3.cn-mockLocation.amazonaws.com.cn'
},
{
name: 'when endPoint is enabled',
stageInfo: {
...originalStageInfo,
endPoint: 's3.endpoint',
useS3RegionalUrl: false
},
result: 'https://s3.endpoint'
},
{
name: 'when both endPoint and useS3PReiongalUrl is valid',
stageInfo: {
...originalStageInfo,
endPoint: 's3.endpoint',
useS3RegionalUrl: true,

},
result: 'https://s3.endpoint'
},
];

testCases.forEach(({ name, stageInfo, result }) => {
it(name, () => {
const client = AWS.createClient(stageInfo);
assert.strictEqual(client.config.endpoint, result);
} );

});
});


it('extract bucket name and path', async function () {
let result = extractBucketNameAndPath('sfc-eng-regression/test_sub_dir/');
assert.strictEqual(result.bucketName, 'sfc-eng-regression');
Expand Down

0 comments on commit 6af0581

Please sign in to comment.