Skip to content

Commit 64b4de8

Browse files
author
Saro
committed
Fix tests
Assume that the provided `s3Client` conforms to the v3 API to make tests pass.
1 parent e151745 commit 64b4de8

File tree

4 files changed

+625
-122
lines changed

4 files changed

+625
-122
lines changed

lib/s3.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
'use strict';
22

3-
var AWS = require('aws-sdk'),
4-
{
5-
S3
6-
} = require("@aws-sdk/client-s3");
3+
var { fromIni } = require('@aws-sdk/credential-providers');
4+
var { S3 } = require('@aws-sdk/client-s3');
75
var CoreObject = require('core-object');
86
var RSVP = require('rsvp');
97
var fs = require('fs');
@@ -34,20 +32,31 @@ module.exports = CoreObject.extend({
3432
var config = plugin.pluginConfig;
3533
var profile = plugin.readConfig('profile');
3634
var endpoint = plugin.readConfig('endpoint');
35+
var credentials;
3736

3837
this._plugin = plugin;
3938

40-
if (profile && !this._plugin.readConfig('s3Client')) {
41-
this._plugin.log('Using AWS profile from config', { verbose: true });
42-
AWS.config.credentials = new AWS.SharedIniFileCredentials({ profile: profile });
39+
var providedS3Client = plugin.readConfig("s3Client");
40+
41+
42+
if (profile && !providedS3Client) {
43+
this._plugin.log("Using AWS profile from config", { verbose: true });
44+
credentials = fromIni({ profile: profile });
4345
}
4446

4547
if (endpoint) {
46-
this._plugin.log('Using endpoint from config', { verbose: true });
47-
AWS.config.endpoint = new AWS.Endpoint(endpoint);
48+
this._plugin.log('Using endpoint from config', { verbose: true });
4849
}
4950

50-
this._client = plugin.readConfig('s3Client') || new S3(config);
51+
this._client = providedS3Client || new S3(config);
52+
53+
if (endpoint) {
54+
this._client.config.endpoint = endpoint;
55+
}
56+
if (credentials) {
57+
this._client.config.credentials = credentials;
58+
}
59+
5160
},
5261

5362
upload: function(options) {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
},
2020
"dependencies": {
2121
"@aws-sdk/client-s3": "^3.385.0",
22+
"@aws-sdk/credential-providers": "^3.391.0",
2223
"core-object": "^3.0.0",
2324
"ember-cli-deploy-plugin": "^0.2.9",
2425
"mime-types": "^2.1.27",

tests/unit/lib/s3-test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ describe('s3', function() {
3535
copyObject: function(params, cb) {
3636
copyParams = params;
3737
cb();
38-
}
38+
},
39+
config: {}
3940
};
4041
mockUi = {
4142
messages: [],
@@ -222,7 +223,7 @@ describe('s3', function() {
222223
var promise = subject.upload(options);
223224
return assert.isFulfilled(promise)
224225
.then(function() {
225-
assert.equal(require('aws-sdk').config.endpoint.host, endpoint, 'Endpoint in SDK is correct');
226+
assert.equal(s3Client.config.endpoint, endpoint, 'Endpoint in SDK is correct');
226227
assert.equal(mockUi.messages[0], '- Using endpoint from config', 'Prefix is included in log output');
227228
});
228229
});

0 commit comments

Comments
 (0)