Skip to content

Commit b850a3f

Browse files
feat(pipeline): add support for pipeline cache invalidation. fixes #434 (#435)
1 parent 425cdc3 commit b850a3f

File tree

4 files changed

+101
-1
lines changed

4 files changed

+101
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"author": "Adobe Inc.",
66
"bugs": "https://github.com/adobe/aio-cli-plugin-cloudmanager/issues",
77
"dependencies": {
8-
"@adobe/aio-lib-cloudmanager": "^1.3.0",
8+
"@adobe/aio-lib-cloudmanager": "^1.4.0",
99
"@adobe/aio-lib-core-config": "^2.0.0",
1010
"@adobe/aio-lib-core-errors": "^3.0.1",
1111
"@adobe/aio-lib-core-logging": "^1.2.0",
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Copyright 2021 Adobe. All rights reserved.
3+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License. You may obtain a copy
5+
of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
Unless required by applicable law or agreed to in writing, software distributed under
8+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
OF ANY KIND, either express or implied. See the License for the specific language
10+
governing permissions and limitations under the License.
11+
*/
12+
13+
const { initSdk, getProgramId } = require('../../../cloudmanager-helpers')
14+
const { cli } = require('cli-ux')
15+
const commonFlags = require('../../../common-flags')
16+
const BaseCommand = require('../../../base-command')
17+
18+
class InvalidatePipelineCacheCommand extends BaseCommand {
19+
async run () {
20+
const { args, flags } = this.parse(InvalidatePipelineCacheCommand)
21+
22+
const programId = getProgramId(flags)
23+
24+
cli.action.start('invalidating cache for pipeline')
25+
26+
const result = await this.invalidateCache(programId, args.pipelineId, flags.imsContextName)
27+
28+
cli.action.stop('done')
29+
30+
return result
31+
}
32+
33+
async invalidateCache (programId, pipelineId, imsContextName = null) {
34+
const sdk = await initSdk(imsContextName)
35+
return sdk.invalidatePipelineCache(programId, pipelineId)
36+
}
37+
}
38+
39+
InvalidatePipelineCacheCommand.description = 'invalidate pipeline cache'
40+
41+
InvalidatePipelineCacheCommand.flags = {
42+
...commonFlags.global,
43+
...commonFlags.programId,
44+
}
45+
46+
InvalidatePipelineCacheCommand.args = [
47+
{ name: 'pipelineId', required: true, description: 'the pipeline id' },
48+
]
49+
50+
module.exports = InvalidatePipelineCacheCommand

test/__mocks__/@adobe/aio-lib-cloudmanager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ function createDefaultMock () {
111111
deleteEnvironment: jest.fn(() => Promise.resolve()),
112112
tailLog: jest.fn(() => Promise.resolve()),
113113
tailExecutionStepLog: jest.fn(() => Promise.resolve()),
114+
invalidatePipelineCache: jest.fn(() => Promise.resolve()),
114115
}
115116
}
116117

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Copyright 2021 Adobe. All rights reserved.
3+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License. You may obtain a copy
5+
of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
Unless required by applicable law or agreed to in writing, software distributed under
8+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
OF ANY KIND, either express or implied. See the License for the specific language
10+
governing permissions and limitations under the License.
11+
*/
12+
13+
const { init, mockSdk } = require('@adobe/aio-lib-cloudmanager')
14+
const { resetCurrentOrgId, setCurrentOrgId } = require('@adobe/aio-lib-ims')
15+
const InvalidatePipelineCacheCommand = require('../../../src/commands/cloudmanager/pipeline/invalidate-cache')
16+
17+
beforeEach(() => {
18+
resetCurrentOrgId()
19+
})
20+
21+
test('invalidate-cache - missing arg', async () => {
22+
expect.assertions(2)
23+
24+
const runResult = InvalidatePipelineCacheCommand.run([])
25+
await expect(runResult instanceof Promise).toBeTruthy()
26+
await expect(runResult).rejects.toThrow(/^Missing 1 required arg/)
27+
})
28+
29+
test('invalidate-cache - missing config', async () => {
30+
expect.assertions(2)
31+
32+
const runResult = InvalidatePipelineCacheCommand.run(['--programId', '5', '10'])
33+
await expect(runResult instanceof Promise).toBeTruthy()
34+
await expect(runResult).rejects.toThrow('[CloudManagerCLI:NO_IMS_CONTEXT] Unable to find IMS context aio-cli-plugin-cloudmanager.')
35+
})
36+
37+
test('invalidate-cache - configured', async () => {
38+
setCurrentOrgId('good')
39+
40+
expect.assertions(5)
41+
42+
const runResult = InvalidatePipelineCacheCommand.run(['--programId', '5', '7'])
43+
await expect(runResult instanceof Promise).toBeTruthy()
44+
await runResult
45+
await expect(init.mock.calls.length).toEqual(1)
46+
await expect(init).toHaveBeenCalledWith('good', 'test-client-id', 'fake-token', 'https://cloudmanager.adobe.io')
47+
await expect(mockSdk.invalidatePipelineCache.mock.calls.length).toEqual(1)
48+
await expect(mockSdk.invalidatePipelineCache).toHaveBeenCalledWith('5', '7')
49+
})

0 commit comments

Comments
 (0)