Skip to content

Commit

Permalink
fix: await http response in AWS EKS detector (#2076)
Browse files Browse the repository at this point in the history
* previously missing await on a promise response
* update tests to reflect current behavior

Co-authored-by: Daniel Dyla <dyladan@users.noreply.github.com>
  • Loading branch information
vreynolds and dyladan authored Apr 8, 2021
1 parent 64c8ef5 commit a51bbbd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class AwsEksDetector implements Detector {
await AwsEksDetector.fileAccessAsync(this.K8S_TOKEN_PATH);
const k8scert = await AwsEksDetector.readFileAsync(this.K8S_CERT_PATH);

if (!this._isEks(k8scert)) {
if (!(await this._isEks(k8scert))) {
return Resource.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@ describe('awsEksDetector', () => {
});

describe('on unsuccesful request', () => {
it('should throw when receiving error response code', async () => {
const expectedError = new Error('EKS metadata api request timed out.');
it('should return an empty resource when timed out', async () => {
fileStub = sinon
.stub(AwsEksDetector, 'fileAccessAsync' as any)
.resolves();
Expand All @@ -265,17 +264,14 @@ describe('awsEksDetector', () => {
.delayConnection(2500)
.reply(200, () => mockedAwsAuth);

try {
await awsEksDetector.detect();
} catch (err) {
assert.deepStrictEqual(err, expectedError);
}

const resource: Resource = await awsEksDetector.detect();
scope.done();
});

it('should return an empty resource when timed out', async () => {
const expectedError = new Error('Failed to load page, status code: 404');
assert.ok(resource);
assertEmptyResource(resource);
}).timeout(awsEksDetector.TIMEOUT_MS + 100);

it('should return an empty resource when receiving error response code', async () => {
fileStub = sinon
.stub(AwsEksDetector, 'fileAccessAsync' as any)
.resolves();
Expand All @@ -291,13 +287,11 @@ describe('awsEksDetector', () => {
.matchHeader('Authorization', k8s_token)
.reply(404, () => new Error());

try {
await awsEksDetector.detect();
} catch (err) {
assert.deepStrictEqual(err, expectedError);
}

const resource: Resource = await awsEksDetector.detect();
scope.done();

assert.ok(resource);
assertEmptyResource(resource);
});
});
});

0 comments on commit a51bbbd

Please sign in to comment.