Skip to content

Commit

Permalink
ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Kc committed Jul 26, 2023
1 parent fea3270 commit 630de32
Show file tree
Hide file tree
Showing 15 changed files with 2,202 additions and 2,202 deletions.
60 changes: 30 additions & 30 deletions __tests__/getters/getArpCache.spec.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
import { getArpCache } from '../../src/getters';
import { runOsquery, OsType } from '../../src/runOSQuery';
import { runOsquery, OsType } from '../../src/runOsquery';

// Mock runOsquery function
jest.mock('../../src/runOsquery', () => ({
runOsquery: jest.fn(),
OsType: {
LINUX: 'linux',
DARWIN: 'darwin',
WINDOWS_NT: 'windows_nt',
},
runOsquery: jest.fn(),
OsType: {
LINUX: 'linux',
DARWIN: 'darwin',
WINDOWS_NT: 'windows_nt',
},
}));

describe('getArpCache', () => {
it('resolves with arp_cache table on success', async () => {
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>;
const expectedArpCache = [
{
address: '192.168.1.1',
mac: '00:0a:95:9d:68:16',
interface: 'eth0',
permanent: '0',
},
];
mockRunOsquery.mockResolvedValue(JSON.stringify(expectedArpCache));
it('resolves with arp_cache table on success', async () => {
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>;
const expectedArpCache = [
{
address: '192.168.1.1',
mac: '00:0a:95:9d:68:16',
interface: 'eth0',
permanent: '0',
},
];
mockRunOsquery.mockResolvedValue(JSON.stringify(expectedArpCache));

await expect(getArpCache()).resolves.toEqual(expectedArpCache);
expect(mockRunOsquery).toHaveBeenCalledWith('SELECT * FROM arp_cache', [
OsType.LINUX,
OsType.DARWIN,
OsType.WINDOWS_NT,
]);
});
await expect(getArpCache()).resolves.toEqual(expectedArpCache);
expect(mockRunOsquery).toHaveBeenCalledWith('SELECT * FROM arp_cache', [
OsType.LINUX,
OsType.DARWIN,
OsType.WINDOWS_NT,
]);
});

it('rejects with error on command failure', async () => {
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>;
mockRunOsquery.mockRejectedValue('Command failed');
it('rejects with error on command failure', async () => {
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>;
mockRunOsquery.mockRejectedValue('Command failed');

await expect(getArpCache()).rejects.toEqual('Command failed');
});
await expect(getArpCache()).rejects.toEqual('Command failed');
});
});
2 changes: 1 addition & 1 deletion __tests__/getters/getAtomPackages.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getAtomPackages } from '../../src/getters';
import { runOsquery, OsType } from '../../src/runOSQuery';
import { runOsquery, OsType } from '../../src/runOsquery';

jest.mock('../../src/runOSQuery', () => ({
runOsquery: jest.fn(),
Expand Down
82 changes: 41 additions & 41 deletions __tests__/getters/getAzureInstanceMetadata.test.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
import { getAzureInstanceMetadata } from '../../src/getters';
import { runOsquery, OsType } from '../../src/runOSQuery';
import { runOsquery, OsType } from '../../src/runOsquery';

jest.mock('../../src/runOsquery', () => ({
runOsquery: jest.fn(),
OsType: {
LINUX: 'linux',
DARWIN: 'darwin',
WINDOWS_NT: 'windows_nt',
},
runOsquery: jest.fn(),
OsType: {
LINUX: 'linux',
DARWIN: 'darwin',
WINDOWS_NT: 'windows_nt',
},
}));

describe('getAzureInstanceMetadata', () => {
it('resolves with azure_instance_metadata table on success', async () => {
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>;
const expectedMetadata = [
{
location: 'location',
name: 'name',
offer: 'offer',
publisher: 'publisher',
sku: 'sku',
version: 'version',
os_type: 'os_type',
platform_update_domain: 'platform_update_domain',
platform_fault_domain: 'platform_fault_domain',
vm_id: 'vm_id',
vm_size: 'vm_size',
subscription_id: 'subscription_id',
resource_group_name: 'resource_group_name',
placement_group_id: 'placement_group_id',
vm_scale_set_name: 'vm_scale_set_name',
zone: 'zone',
},
];
mockRunOsquery.mockResolvedValue(JSON.stringify(expectedMetadata));
it('resolves with azure_instance_metadata table on success', async () => {
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>;
const expectedMetadata = [
{
location: 'location',
name: 'name',
offer: 'offer',
publisher: 'publisher',
sku: 'sku',
version: 'version',
os_type: 'os_type',
platform_update_domain: 'platform_update_domain',
platform_fault_domain: 'platform_fault_domain',
vm_id: 'vm_id',
vm_size: 'vm_size',
subscription_id: 'subscription_id',
resource_group_name: 'resource_group_name',
placement_group_id: 'placement_group_id',
vm_scale_set_name: 'vm_scale_set_name',
zone: 'zone',
},
];
mockRunOsquery.mockResolvedValue(JSON.stringify(expectedMetadata));

await expect(getAzureInstanceMetadata()).resolves.toEqual(expectedMetadata);
expect(mockRunOsquery).toHaveBeenCalledWith(
'SELECT * FROM azure_instance_metadata',
[OsType.LINUX, OsType.DARWIN, OsType.WINDOWS_NT],
);
});
await expect(getAzureInstanceMetadata()).resolves.toEqual(expectedMetadata);
expect(mockRunOsquery).toHaveBeenCalledWith(
'SELECT * FROM azure_instance_metadata',
[OsType.LINUX, OsType.DARWIN, OsType.WINDOWS_NT],
);
});

it('rejects with error on command failure', async () => {
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>;
mockRunOsquery.mockRejectedValue('Command failed');
it('rejects with error on command failure', async () => {
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>;
mockRunOsquery.mockRejectedValue('Command failed');

await expect(getAzureInstanceMetadata()).rejects.toEqual('Command failed');
});
await expect(getAzureInstanceMetadata()).rejects.toEqual('Command failed');
});
});
56 changes: 28 additions & 28 deletions __tests__/getters/getAzureInstanceTags.test.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
import { getAzureInstanceTags } from '../../src/getters';
import { runOsquery, OsType } from '../../src/runOSQuery';
import { runOsquery, OsType } from '../../src/runOsquery';

jest.mock('../../src/runOsquery', () => ({
runOsquery: jest.fn(),
OsType: {
LINUX: 'linux',
DARWIN: 'darwin',
WINDOWS_NT: 'windows_nt',
},
runOsquery: jest.fn(),
OsType: {
LINUX: 'linux',
DARWIN: 'darwin',
WINDOWS_NT: 'windows_nt',
},
}));

describe('getAzureInstanceTags', () => {
it('resolves with azure_instance_tags table on success', async () => {
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>;
const expectedTags = [
{
vm_id: 'vm_id',
key: 'key',
value: 'value',
},
];
mockRunOsquery.mockResolvedValue(JSON.stringify(expectedTags));
it('resolves with azure_instance_tags table on success', async () => {
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>;
const expectedTags = [
{
vm_id: 'vm_id',
key: 'key',
value: 'value',
},
];
mockRunOsquery.mockResolvedValue(JSON.stringify(expectedTags));

await expect(getAzureInstanceTags()).resolves.toEqual(expectedTags);
expect(mockRunOsquery).toHaveBeenCalledWith(
'SELECT * FROM azure_instance_tags',
[OsType.LINUX, OsType.DARWIN, OsType.WINDOWS_NT],
);
});
await expect(getAzureInstanceTags()).resolves.toEqual(expectedTags);
expect(mockRunOsquery).toHaveBeenCalledWith(
'SELECT * FROM azure_instance_tags',
[OsType.LINUX, OsType.DARWIN, OsType.WINDOWS_NT],
);
});

it('rejects with error on command failure', async () => {
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>;
mockRunOsquery.mockRejectedValue('Command failed');
it('rejects with error on command failure', async () => {
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>;
mockRunOsquery.mockRejectedValue('Command failed');

await expect(getAzureInstanceTags()).rejects.toEqual('Command failed');
});
await expect(getAzureInstanceTags()).rejects.toEqual('Command failed');
});
});
96 changes: 48 additions & 48 deletions __tests__/getters/getCarbonBlackInfo.test.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
import { getCarbonBlackInfo } from '../../src/getters';
import { runOsquery, OsType } from '../../src/runOSQuery';
import { runOsquery, OsType } from '../../src/runOsquery';

jest.mock('../../src/runOsquery', () => ({
runOsquery: jest.fn(),
OsType: {
LINUX: 'linux',
DARWIN: 'darwin',
WINDOWS_NT: 'windows_nt',
},
runOsquery: jest.fn(),
OsType: {
LINUX: 'linux',
DARWIN: 'darwin',
WINDOWS_NT: 'windows_nt',
},
}));

describe('getCarbonBlackInfo', () => {
it('resolves with carbon_black_info table on success', async () => {
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>;
const expectedCarbonBlackInfo = [
{
sensor_id: 1,
config_name: 'config_name',
collect_store_files: 1,
collect_module_loads: 1,
collect_module_info: 1,
collect_file_mods: 1,
collect_reg_mods: 1,
collect_net_conns: 1,
collect_processes: 1,
collect_cross_processes: 1,
collect_emet_events: 1,
collect_data_file_writes: 1,
collect_process_user_context: 1,
collect_sensor_operations: 1,
log_file_disk_quota_mb: 1,
log_file_disk_quota_percentage: 1,
protection_disabled: 1,
sensor_ip_addr: 'sensor_ip_addr',
sensor_backend_server: 'sensor_backend_server',
event_queue: 1,
binary_queue: 1,
},
];
mockRunOsquery.mockResolvedValue(JSON.stringify(expectedCarbonBlackInfo));
it('resolves with carbon_black_info table on success', async () => {
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>;
const expectedCarbonBlackInfo = [
{
sensor_id: 1,
config_name: 'config_name',
collect_store_files: 1,
collect_module_loads: 1,
collect_module_info: 1,
collect_file_mods: 1,
collect_reg_mods: 1,
collect_net_conns: 1,
collect_processes: 1,
collect_cross_processes: 1,
collect_emet_events: 1,
collect_data_file_writes: 1,
collect_process_user_context: 1,
collect_sensor_operations: 1,
log_file_disk_quota_mb: 1,
log_file_disk_quota_percentage: 1,
protection_disabled: 1,
sensor_ip_addr: 'sensor_ip_addr',
sensor_backend_server: 'sensor_backend_server',
event_queue: 1,
binary_queue: 1,
},
];
mockRunOsquery.mockResolvedValue(JSON.stringify(expectedCarbonBlackInfo));

await expect(getCarbonBlackInfo()).resolves.toEqual(
expectedCarbonBlackInfo,
);
expect(mockRunOsquery).toHaveBeenCalledWith(
'SELECT * FROM carbon_black_info',
[OsType.LINUX, OsType.DARWIN, OsType.WINDOWS_NT],
);
});
await expect(getCarbonBlackInfo()).resolves.toEqual(
expectedCarbonBlackInfo,
);
expect(mockRunOsquery).toHaveBeenCalledWith(
'SELECT * FROM carbon_black_info',
[OsType.LINUX, OsType.DARWIN, OsType.WINDOWS_NT],
);
});

it('rejects with error on command failure', async () => {
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>;
mockRunOsquery.mockRejectedValue('Command failed');
it('rejects with error on command failure', async () => {
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>;
mockRunOsquery.mockRejectedValue('Command failed');

await expect(getCarbonBlackInfo()).rejects.toEqual('Command failed');
});
await expect(getCarbonBlackInfo()).rejects.toEqual('Command failed');
});
});
Loading

0 comments on commit 630de32

Please sign in to comment.