Skip to content

Commit

Permalink
fix: ContainerId not detected post version 0.2.2 (#2270)
Browse files Browse the repository at this point in the history
* ?? only checks for null and undefined

* added unit test to cover the fix

* added unit test to cover the fix

* lint fixes

* lint fixes - line too long
  • Loading branch information
abhee11 committed Jun 10, 2024
1 parent 3e863cf commit 9761a91
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class ContainerDetector implements Detector {
private async _getContainerId(): Promise<string | undefined> {
try {
return (
(await this._getContainerIdV1()) ?? (await this._getContainerIdV2())
(await this._getContainerIdV1()) || (await this._getContainerIdV2())
);
} catch (e) {
if (e instanceof Error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ describe('ContainerDetector', () => {
assert.ok(resource);
});

it('should return a correctCgroupV2Data resource with v1Detector returns empty string ', async () => {
readStub = sinon.stub(ContainerDetector, 'readFileAsync' as any);
sinon.stub(containerDetector, '_getContainerIdV1' as any).resolves('');
sinon
.stub(containerDetector, '_getContainerIdV2' as any)
.resolves(correctCgroupV2Data);
const containerId = await containerDetector['_getContainerId']();
assert.strictEqual(containerId, correctCgroupV2Data);
});

it('should return a resource without attribute container.id when cgroup file does not contain valid Container ID', async () => {
readStub = sinon
.stub(ContainerDetector, 'readFileAsync' as any)
Expand Down

0 comments on commit 9761a91

Please sign in to comment.