-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Separate how config and plans are updated, add tests (#7491)
- Loading branch information
1 parent
ca7e70b
commit 2ef8788
Showing
14 changed files
with
267 additions
and
36 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
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
213 changes: 213 additions & 0 deletions
213
app/scripts/modules/core/src/pipeline/config/pipelineConfigurer.controller.spec.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,213 @@ | ||
import { IController, IControllerService, IQService, IRootScopeService, IScope, IWindowService } from 'angular'; | ||
|
||
import { ApplicationModelBuilder } from 'core/application/applicationModel.builder'; | ||
import { PipelineConfigService } from 'core/pipeline/config/services/PipelineConfigService'; | ||
import { | ||
IDockerTrigger, | ||
IGitTrigger, | ||
INotification, | ||
IParameter, | ||
IPipelineTemplateConfigV2, | ||
IPipelineTemplatePlanV2, | ||
} from 'core/domain'; | ||
|
||
const githubTrigger: IGitTrigger = { | ||
branch: 'master', | ||
enabled: true, | ||
project: 'spinnaker', | ||
slug: 'test-project', | ||
source: 'github', | ||
type: 'git', | ||
}; | ||
|
||
const inheritedDockerTrigger: IDockerTrigger = { | ||
account: 'test-docker-registry', | ||
enabled: true, | ||
inherited: true, | ||
organization: 'test-org', | ||
registry: 'index.docker.io', | ||
repository: 'test-image', | ||
type: 'docker', | ||
}; | ||
|
||
const inheritedParameter: IParameter = { | ||
default: '', | ||
description: 'an inherited test parameter', | ||
hasOptions: false, | ||
inherited: true, | ||
label: 'foo', | ||
name: 'foo', | ||
options: [{ value: '' }], | ||
pinned: false, | ||
required: true, | ||
}; | ||
|
||
const pipelineParameter: IParameter = { | ||
default: '', | ||
description: 'a test parameter', | ||
hasOptions: false, | ||
label: 'bar', | ||
name: 'bar', | ||
options: [{ value: '' }], | ||
pinned: false, | ||
required: true, | ||
}; | ||
|
||
const inheritedNotification: INotification = { | ||
address: 'inherited@example.com', | ||
level: 'pipeline', | ||
type: 'email', | ||
when: ['pipeline.starting'], | ||
inherited: true, | ||
}; | ||
|
||
const pipelineNotification: INotification = { | ||
address: 'example@example.com', | ||
level: 'pipeline', | ||
type: 'email', | ||
when: ['pipeline.complete'], | ||
}; | ||
|
||
const pipeline: IPipelineTemplateConfigV2 = { | ||
schema: 'v2', | ||
application: 'app', | ||
name: 'Test pipeline', | ||
template: { | ||
artifactAccount: 'front50ArtifactCredentials', | ||
reference: 'spinnaker://test-template', | ||
type: 'front50/pipelineTemplate', | ||
}, | ||
variables: {}, | ||
exclude: [], | ||
triggers: [], | ||
parameterConfig: [], | ||
notifications: [], | ||
description: '', | ||
stages: [], | ||
expectedArtifacts: [], | ||
keepWaitingPipelines: false, | ||
limitConcurrent: true, | ||
type: 'templatedPipeline', | ||
updateTs: 1568324929257, | ||
id: '1234', | ||
}; | ||
|
||
const plan: IPipelineTemplatePlanV2 = { | ||
appConfig: {}, | ||
application: 'app', | ||
expectedArtifacts: [], | ||
id: '1234', | ||
keepWaitingPipelines: false, | ||
lastModifiedBy: 'anonymous', | ||
limitConcurrent: true, | ||
name: 'Test pipeline', | ||
notifications: [inheritedNotification], | ||
parameterConfig: [inheritedParameter], | ||
stages: [], | ||
templateVariables: {}, | ||
triggers: [inheritedDockerTrigger], | ||
updateTs: 1562959880351, | ||
}; | ||
|
||
declare const window: IWindowService; | ||
|
||
describe('Controller: pipelineConfigurer', function() { | ||
let $scope: IScope; | ||
let vm: IController; | ||
let $q: IQService; | ||
|
||
beforeEach(window.module(require('./pipelineConfigurer').name)); | ||
|
||
beforeEach( | ||
window.inject(function($controller: IControllerService, $rootScope: IRootScopeService, _$q_: IQService) { | ||
$q = _$q_; | ||
|
||
$scope = $rootScope.$new(); | ||
$scope.pipeline = pipeline; | ||
$scope.application = ApplicationModelBuilder.createApplicationForTests('app', { | ||
key: 'pipelineConfigs', | ||
lazy: true, | ||
}); | ||
$scope.plan = plan; | ||
$scope.isTemplatedPipeline = true; | ||
$scope.isV2TemplatedPipeline = true; | ||
|
||
this.initialize = () => { | ||
vm = $controller('PipelineConfigurerCtrl', { | ||
$scope: $scope, | ||
$uibModal: {}, | ||
$state: {}, | ||
executionService: {}, | ||
}); | ||
}; | ||
}), | ||
); | ||
|
||
describe('initialization', function() { | ||
it('sets $scope.renderablePipeline to the plan for templated pipelines', function() { | ||
this.initialize(); | ||
expect($scope.renderablePipeline).toEqual(plan); | ||
}); | ||
}); | ||
|
||
describe('adding configuration options', function() { | ||
beforeEach(function() { | ||
spyOn(PipelineConfigService, 'getHistory').and.returnValue($q.when([])); | ||
this.initialize(); | ||
}); | ||
|
||
it('can add and remove a trigger to the pipeline config and plan', function() { | ||
expect($scope.pipeline.triggers.length).toBe(0); | ||
vm.updatePipelineConfig({ triggers: [inheritedDockerTrigger, githubTrigger] }); | ||
|
||
$scope.$apply(); | ||
|
||
expect($scope.pipeline.triggers.length).toBe(1); | ||
expect($scope.pipeline.triggers).toEqual([githubTrigger]); | ||
expect($scope.renderablePipeline.triggers).toEqual([inheritedDockerTrigger, githubTrigger]); | ||
|
||
vm.updatePipelineConfig({ triggers: [inheritedDockerTrigger] }); | ||
|
||
$scope.$apply(); | ||
|
||
expect($scope.pipeline.triggers.length).toBe(0); | ||
expect($scope.renderablePipeline.triggers).toEqual([inheritedDockerTrigger]); | ||
}); | ||
|
||
it('can add and remove a parameter to the pipeline config and plan', function() { | ||
expect($scope.pipeline.parameterConfig.length).toBe(0); | ||
vm.updatePipelineConfig({ parameterConfig: [inheritedParameter, pipelineParameter] }); | ||
|
||
$scope.$apply(); | ||
|
||
expect($scope.pipeline.parameterConfig.length).toBe(1); | ||
expect($scope.pipeline.parameterConfig).toEqual([pipelineParameter]); | ||
expect($scope.renderablePipeline.parameterConfig).toEqual([inheritedParameter, pipelineParameter]); | ||
|
||
vm.updatePipelineConfig({ parameterConfig: [inheritedParameter] }); | ||
|
||
$scope.$apply(); | ||
|
||
expect($scope.pipeline.parameterConfig.length).toBe(0); | ||
expect($scope.renderablePipeline.parameterConfig).toEqual([inheritedParameter]); | ||
}); | ||
|
||
it('can add and remove a notification to the pipeline config and plan', function() { | ||
expect($scope.pipeline.notifications.length).toBe(0); | ||
vm.updatePipelineConfig({ notifications: [inheritedNotification, pipelineNotification] }); | ||
|
||
$scope.$apply(); | ||
|
||
expect($scope.pipeline.notifications.length).toBe(1); | ||
expect($scope.pipeline.notifications).toEqual([pipelineNotification]); | ||
expect($scope.renderablePipeline.notifications).toEqual([inheritedNotification, pipelineNotification]); | ||
|
||
vm.updatePipelineConfig({ notifications: [inheritedNotification] }); | ||
|
||
$scope.$apply(); | ||
|
||
expect($scope.pipeline.notifications.length).toBe(0); | ||
expect($scope.renderablePipeline.notifications).toEqual([inheritedNotification]); | ||
}); | ||
}); | ||
}); |
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.