|
@@ -5,7 +5,6 @@ vi.mock('node:os', () => ({
|
|
|
type: vi.fn(),
|
|
type: vi.fn(),
|
|
|
platform: vi.fn(),
|
|
platform: vi.fn(),
|
|
|
arch: vi.fn(),
|
|
arch: vi.fn(),
|
|
|
- totalmem: vi.fn(),
|
|
|
|
|
}));
|
|
}));
|
|
|
|
|
|
|
|
describe('getOsResourceAttributes', () => {
|
|
describe('getOsResourceAttributes', () => {
|
|
@@ -13,7 +12,6 @@ describe('getOsResourceAttributes', () => {
|
|
|
type: ReturnType<typeof vi.fn>;
|
|
type: ReturnType<typeof vi.fn>;
|
|
|
platform: ReturnType<typeof vi.fn>;
|
|
platform: ReturnType<typeof vi.fn>;
|
|
|
arch: ReturnType<typeof vi.fn>;
|
|
arch: ReturnType<typeof vi.fn>;
|
|
|
- totalmem: ReturnType<typeof vi.fn>;
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
beforeEach(async () => {
|
|
@@ -28,13 +26,11 @@ describe('getOsResourceAttributes', () => {
|
|
|
type: 'Linux',
|
|
type: 'Linux',
|
|
|
platform: 'linux' as const,
|
|
platform: 'linux' as const,
|
|
|
arch: 'x64',
|
|
arch: 'x64',
|
|
|
- totalmem: 16777216000,
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
mockOs.type.mockReturnValue(mockOsData.type);
|
|
mockOs.type.mockReturnValue(mockOsData.type);
|
|
|
mockOs.platform.mockReturnValue(mockOsData.platform);
|
|
mockOs.platform.mockReturnValue(mockOsData.platform);
|
|
|
mockOs.arch.mockReturnValue(mockOsData.arch);
|
|
mockOs.arch.mockReturnValue(mockOsData.arch);
|
|
|
- mockOs.totalmem.mockReturnValue(mockOsData.totalmem);
|
|
|
|
|
|
|
|
|
|
const result = getOsResourceAttributes();
|
|
const result = getOsResourceAttributes();
|
|
|
|
|
|
|
@@ -42,8 +38,8 @@ describe('getOsResourceAttributes', () => {
|
|
|
'os.type': 'Linux',
|
|
'os.type': 'Linux',
|
|
|
'os.platform': 'linux',
|
|
'os.platform': 'linux',
|
|
|
'os.arch': 'x64',
|
|
'os.arch': 'x64',
|
|
|
- 'os.totalmem': 16777216000,
|
|
|
|
|
});
|
|
});
|
|
|
|
|
+ expect(result).not.toHaveProperty('os.totalmem');
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should call all required os module functions', () => {
|
|
it('should call all required os module functions', () => {
|
|
@@ -51,14 +47,12 @@ describe('getOsResourceAttributes', () => {
|
|
|
mockOs.type.mockReturnValue('Linux');
|
|
mockOs.type.mockReturnValue('Linux');
|
|
|
mockOs.platform.mockReturnValue('linux');
|
|
mockOs.platform.mockReturnValue('linux');
|
|
|
mockOs.arch.mockReturnValue('x64');
|
|
mockOs.arch.mockReturnValue('x64');
|
|
|
- mockOs.totalmem.mockReturnValue(16777216000);
|
|
|
|
|
|
|
|
|
|
getOsResourceAttributes();
|
|
getOsResourceAttributes();
|
|
|
|
|
|
|
|
expect(mockOs.type).toHaveBeenCalledOnce();
|
|
expect(mockOs.type).toHaveBeenCalledOnce();
|
|
|
expect(mockOs.platform).toHaveBeenCalledOnce();
|
|
expect(mockOs.platform).toHaveBeenCalledOnce();
|
|
|
expect(mockOs.arch).toHaveBeenCalledOnce();
|
|
expect(mockOs.arch).toHaveBeenCalledOnce();
|
|
|
- expect(mockOs.totalmem).toHaveBeenCalledOnce();
|
|
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should handle different OS types correctly', () => {
|
|
it('should handle different OS types correctly', () => {
|
|
@@ -68,13 +62,11 @@ describe('getOsResourceAttributes', () => {
|
|
|
type: 'Windows_NT',
|
|
type: 'Windows_NT',
|
|
|
platform: 'win32',
|
|
platform: 'win32',
|
|
|
arch: 'x64',
|
|
arch: 'x64',
|
|
|
- totalmem: 8589934592,
|
|
|
|
|
},
|
|
},
|
|
|
expected: {
|
|
expected: {
|
|
|
'os.type': 'Windows_NT',
|
|
'os.type': 'Windows_NT',
|
|
|
'os.platform': 'win32',
|
|
'os.platform': 'win32',
|
|
|
'os.arch': 'x64',
|
|
'os.arch': 'x64',
|
|
|
- 'os.totalmem': 8589934592,
|
|
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
@@ -82,13 +74,11 @@ describe('getOsResourceAttributes', () => {
|
|
|
type: 'Darwin',
|
|
type: 'Darwin',
|
|
|
platform: 'darwin',
|
|
platform: 'darwin',
|
|
|
arch: 'arm64',
|
|
arch: 'arm64',
|
|
|
- totalmem: 17179869184,
|
|
|
|
|
},
|
|
},
|
|
|
expected: {
|
|
expected: {
|
|
|
'os.type': 'Darwin',
|
|
'os.type': 'Darwin',
|
|
|
'os.platform': 'darwin',
|
|
'os.platform': 'darwin',
|
|
|
'os.arch': 'arm64',
|
|
'os.arch': 'arm64',
|
|
|
- 'os.totalmem': 17179869184,
|
|
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
];
|
|
];
|
|
@@ -97,10 +87,10 @@ describe('getOsResourceAttributes', () => {
|
|
|
mockOs.type.mockReturnValue(input.type);
|
|
mockOs.type.mockReturnValue(input.type);
|
|
|
mockOs.platform.mockReturnValue(input.platform as NodeJS.Platform);
|
|
mockOs.platform.mockReturnValue(input.platform as NodeJS.Platform);
|
|
|
mockOs.arch.mockReturnValue(input.arch);
|
|
mockOs.arch.mockReturnValue(input.arch);
|
|
|
- mockOs.totalmem.mockReturnValue(input.totalmem);
|
|
|
|
|
|
|
|
|
|
const result = getOsResourceAttributes();
|
|
const result = getOsResourceAttributes();
|
|
|
expect(result).toEqual(expected);
|
|
expect(result).toEqual(expected);
|
|
|
|
|
+ expect(result).not.toHaveProperty('os.totalmem');
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|