@abgov/nx-oc 12.1.0 → 12.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "http://json-schema.org/schema",
|
|
3
3
|
"id": "NxOcDeployment",
|
|
4
|
-
"title": "",
|
|
4
|
+
"title": "ADSP Application Deployment",
|
|
5
5
|
"type": "object",
|
|
6
6
|
"properties": {
|
|
7
7
|
"project": {
|
|
@@ -59,5 +59,6 @@
|
|
|
59
59
|
"project",
|
|
60
60
|
"appType",
|
|
61
61
|
"env"
|
|
62
|
-
]
|
|
62
|
+
],
|
|
63
|
+
"additionalProperties": false
|
|
63
64
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "http://json-schema.org/schema",
|
|
3
3
|
"id": "NxOcPipeline",
|
|
4
|
-
"title": "",
|
|
4
|
+
"title": "OpenShift CI/CD Pipeline",
|
|
5
5
|
"type": "object",
|
|
6
6
|
"properties": {
|
|
7
7
|
"pipeline": {
|
|
@@ -47,5 +47,6 @@
|
|
|
47
47
|
"infra",
|
|
48
48
|
"type",
|
|
49
49
|
"envs"
|
|
50
|
-
]
|
|
50
|
+
],
|
|
51
|
+
"additionalProperties": false
|
|
51
52
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
import { mocked } from 'jest-mock';
|
|
3
|
+
import { getGitRemoteUrl } from './git-utils';
|
|
4
|
+
|
|
5
|
+
jest.mock('child_process');
|
|
6
|
+
const mockedExecSync = mocked(execSync);
|
|
7
|
+
|
|
8
|
+
describe('getGitRemoteUrl', () => {
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
mockedExecSync.mockReset();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('returns the remote origin url', () => {
|
|
14
|
+
mockedExecSync.mockReturnValue(
|
|
15
|
+
Buffer.from('https://github.com/GovAlta/nx-tools.git\n')
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const url = getGitRemoteUrl();
|
|
19
|
+
expect(url).toBe('https://github.com/GovAlta/nx-tools.git\n');
|
|
20
|
+
expect(mockedExecSync).toHaveBeenCalledWith(
|
|
21
|
+
'git config --get remote.origin.url',
|
|
22
|
+
{ stdio: 'pipe' }
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('returns undefined when git command fails', () => {
|
|
27
|
+
mockedExecSync.mockImplementation(() => {
|
|
28
|
+
throw new Error('not a git repo');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const url = getGitRemoteUrl();
|
|
32
|
+
expect(url).toBeUndefined();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
import { mocked } from 'jest-mock';
|
|
3
|
+
import { runOcCommand } from './oc-utils';
|
|
4
|
+
|
|
5
|
+
jest.mock('child_process');
|
|
6
|
+
const mockedExecSync = mocked(execSync);
|
|
7
|
+
|
|
8
|
+
describe('runOcCommand', () => {
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
mockedExecSync.mockReset();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('returns success with stdout on successful command', () => {
|
|
14
|
+
const output = Buffer.from('project set to test-dev');
|
|
15
|
+
mockedExecSync.mockReturnValue(output);
|
|
16
|
+
|
|
17
|
+
const result = runOcCommand('project', ['test-dev']);
|
|
18
|
+
expect(result.success).toBe(true);
|
|
19
|
+
expect(result.stdout).toBe(output);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('builds the correct command string without input', () => {
|
|
23
|
+
mockedExecSync.mockReturnValue(Buffer.from(''));
|
|
24
|
+
|
|
25
|
+
runOcCommand('process', ['-f .openshift/app.yml', '-p ENV=dev']);
|
|
26
|
+
expect(mockedExecSync).toHaveBeenCalledWith(
|
|
27
|
+
'oc process -f .openshift/app.yml -p ENV=dev',
|
|
28
|
+
expect.objectContaining({ stdio: 'pipe' })
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('uses cat pipe form when input buffer is provided', () => {
|
|
33
|
+
mockedExecSync.mockReturnValue(Buffer.from(''));
|
|
34
|
+
const input = Buffer.from('{"kind":"List"}');
|
|
35
|
+
|
|
36
|
+
runOcCommand('apply', [], input);
|
|
37
|
+
const [cmd] = mockedExecSync.mock.calls[0];
|
|
38
|
+
expect(cmd).toContain('cat |');
|
|
39
|
+
expect(cmd).toContain('oc apply -f -');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('passes input buffer to execSync', () => {
|
|
43
|
+
mockedExecSync.mockReturnValue(Buffer.from(''));
|
|
44
|
+
const input = Buffer.from('yaml-content');
|
|
45
|
+
|
|
46
|
+
runOcCommand('apply', [], input);
|
|
47
|
+
const [, options] = mockedExecSync.mock.calls[0];
|
|
48
|
+
expect((options as { input: Buffer }).input).toBe(input);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('returns failure when command throws', () => {
|
|
52
|
+
mockedExecSync.mockImplementation(() => {
|
|
53
|
+
throw new Error('oc: command not found');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const result = runOcCommand('start-build', ['my-pipeline']);
|
|
57
|
+
expect(result.success).toBe(false);
|
|
58
|
+
expect(result.stdout).toBeUndefined();
|
|
59
|
+
});
|
|
60
|
+
});
|