forked from yuth/amplify-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fail
init --forcePush
fast if environment parameters or secret…
…s are missing in the environment (aws-amplify#12279)
- Loading branch information
1 parent
621274c
commit 9665518
Showing
19 changed files
with
393 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 11 additions & 1 deletion
12
packages/amplify-category-function/src/events/postEnvRemoveHandler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
packages/amplify-cli/src/__tests__/utils/verify-expected-env-params.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { getChangedResources } from '../../commands/build'; | ||
import { prompter } from '@aws-amplify/amplify-prompts'; | ||
import { ensureEnvParamManager, IEnvironmentParameterManager } from '@aws-amplify/amplify-environment-parameters'; | ||
import { verifyExpectedEnvParams } from '../../utils/verify-expected-env-params'; | ||
import { $TSContext } from 'amplify-cli-core'; | ||
|
||
jest.mock('../../commands/build'); | ||
jest.mock('@aws-amplify/amplify-prompts'); | ||
jest.mock('@aws-amplify/amplify-environment-parameters'); | ||
|
||
const getResourcesMock = getChangedResources as jest.MockedFunction<typeof getChangedResources>; | ||
const ensureEnvParamManagerMock = ensureEnvParamManager as jest.MockedFunction<typeof ensureEnvParamManager>; | ||
const prompterMock = prompter as jest.Mocked<typeof prompter>; | ||
|
||
const verifyExpectedEnvParametersMock = jest.fn(); | ||
const getMissingParametersMock = jest.fn(); | ||
const saveMock = jest.fn(); | ||
|
||
ensureEnvParamManagerMock.mockResolvedValue({ | ||
instance: { | ||
verifyExpectedEnvParameters: verifyExpectedEnvParametersMock, | ||
getMissingParameters: getMissingParametersMock, | ||
save: saveMock, | ||
getResourceParamManager: jest.fn().mockReturnValue({ | ||
setParam: jest.fn(), | ||
}), | ||
downloadParameters: jest.fn(), | ||
} as unknown as IEnvironmentParameterManager, | ||
}); | ||
|
||
const resourceList = [ | ||
{ | ||
category: 'storage', | ||
resourceName: 'testStorage', | ||
service: 'S3', | ||
}, | ||
{ | ||
category: 'function', | ||
resourceName: 'testFunction', | ||
service: 'Lambda', | ||
}, | ||
]; | ||
|
||
getResourcesMock.mockResolvedValue(resourceList); | ||
|
||
const resetContext = { | ||
exeInfo: { | ||
inputParams: { | ||
yes: true, | ||
}, | ||
}, | ||
amplify: { | ||
invokePluginMethod: jest.fn(), | ||
}, | ||
} as unknown as $TSContext; | ||
|
||
describe('verifyExpectedEnvParams', () => { | ||
let contextStub = resetContext; | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
contextStub = resetContext; | ||
}); | ||
it('filters parameters based on category and resourceName if specified', async () => { | ||
await verifyExpectedEnvParams(contextStub, 'storage'); | ||
expect(verifyExpectedEnvParametersMock).toHaveBeenCalledWith([resourceList[0]]); | ||
}); | ||
|
||
it('calls verify expected parameters if in non-interactive mode', async () => { | ||
await verifyExpectedEnvParams(contextStub, 'storage'); | ||
expect(verifyExpectedEnvParametersMock).toHaveBeenCalled(); | ||
expect(getMissingParametersMock).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('prompts for missing parameters if in interactive mode', async () => { | ||
contextStub.exeInfo.inputParams.yes = false; | ||
getMissingParametersMock.mockResolvedValue([ | ||
{ | ||
categoryName: 'function', | ||
resourceName: 'testFunction', | ||
parameterName: 'something', | ||
}, | ||
]); | ||
await verifyExpectedEnvParams(contextStub, 'storage'); | ||
expect(verifyExpectedEnvParametersMock).not.toHaveBeenCalled(); | ||
expect(prompterMock.input).toHaveBeenCalled(); | ||
expect(saveMock).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.