forked from guacsec/trustify-da-javascript-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.test.js
More file actions
88 lines (71 loc) · 2.83 KB
/
tools.test.js
File metadata and controls
88 lines (71 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { getCustom, getCustomPath} from "../src/tools.js"
import esmock from 'esmock'
import { afterEach } from 'mocha'
import { expect } from 'chai'
/**
*
* @param {string}operatingSystem
* @return {Promise<*>}
*/
async function mockToolsPartial(operatingSystem) {
return await esmock('../src/tools.js', {
os: {
platform: () => operatingSystem
}
}
)
}
suite('testing the various tools and utility functions', () => {
suite('test the getCustom utility function', () => {
afterEach(() => delete process.env['DUMMY_KEY'])
test('when exists as environment variable and opts, return environment variables value', () => {
process.env['DUMMY_KEY'] = 'dummy-env-value'
let opts = { 'DUMMY_KEY': 'dummy-opts-value' }
let fetchedValue = getCustom('DUMMY_KEY', 'dummy-default-value', opts)
expect(fetchedValue).to.equal('dummy-env-value')
})
test('when no environment variable but exists as opts, return opts value', () => {
let opts = { 'DUMMY_KEY': 'dummy-opts-value' }
let fetchedValue = getCustom('DUMMY_KEY', 'dummy-default-value', opts)
expect(fetchedValue).to.equal('dummy-opts-value')
})
test('when no environment variable and no opts, return default value', () => {
let fetchedValue = getCustom('DUMMY_KEY', 'dummy-default-value')
expect(fetchedValue).to.equal('dummy-default-value')
})
})
suite('test the getCustomPath utility function', () => {
afterEach(() => delete process.env['EXHORT_DUMMY_PATH'])
test('when exists as environment variable and opts, return environment variables value', () => {
process.env['EXHORT_DUMMY_PATH'] = 'dummy-env-value'
let opts = { 'EXHORT_DUMMY_PATH': 'dummy-opts-value' }
let fetchedValue = getCustomPath('dummy', opts)
expect(fetchedValue).to.equal('dummy-env-value')
})
test('when no environment variable but exists as opts, return opts value', () => {
let opts = { 'EXHORT_DUMMY_PATH': 'dummy-opts-value' }
let fetchedValue = getCustomPath('dummy', opts)
expect(fetchedValue).to.equal('dummy-opts-value')
})
test('when no environment variable and no opts, return default value', () => {
let fetchedValue = getCustomPath('dummy')
expect(fetchedValue).to.equal('dummy')
})
})
suite('test the handleSpacesInPath utility function', () => {
test('Windows Path with spaces', async () => {
const tools = await mockToolsPartial("win32")
let path = "c:\\users\\john doe\\pom.xml"
let expectedPath = "\"c:\\users\\john doe\\pom.xml\""
let actualPath = tools.handleSpacesInPath(path)
expect(actualPath).to.equal(expectedPath)
})
test('Windows Path with no spaces', async () => {
const tools = await mockToolsPartial("win32")
let path = "c:\\users\\john\\pom.xml"
let expectedPath = "c:\\users\\john\\pom.xml"
let actualPath = tools.handleSpacesInPath(path)
expect(actualPath).to.equal(expectedPath)
})
})
})