Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(moniker) - adds filter to only retrieve target cluster for clone aws cluster stage #4196

Merged
merged 2 commits into from
Oct 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ module.exports = angular.module('spinnaker.amazon.pipeline.stage.cloneServerGrou

this.targetClusterUpdated = () => {
if (stage.targetCluster) {
let moniker = _.first(appListExtractorService.getMonikers([$scope.application]));
const filterByCluster = (serverGroup) => serverGroup.moniker.cluster === stage.targetCluster;
let moniker = _.first(appListExtractorService.getMonikers([$scope.application], filterByCluster));
stage.stack = moniker.stack;
stage.freeFormDetails = moniker.detail;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ describe('appListExtractorService', function () {
);

describe('Get Monikers from a list of applications', function () {

it('should return a filtered list of monikers', function () {
let moniker: IMoniker = {
cluster: 'test-cluster',
application: 'test-application'
};
const filterByCluster = (serverGroup:IServerGroup) => serverGroup.moniker.cluster === 'test-cluster'
const applicationA: Application = buildApplication([ {moniker: moniker} ]);
const applicationB: Application = buildApplication();

const result = service.getMonikers([applicationA, applicationB], filterByCluster);
expect(result.length).toEqual(1);
expect(result).toEqual([moniker]);
});

it('should get a empty list for one application w/ no monikers', function () {
const application: Application = buildApplication([ {stack: 'prod'}, {stack: 'test'} ]);
const result = service.getMonikers([application]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ const defaultFilter = () => true;

export class AppListExtractor {

public getMonikers(applications: Application[]): IMoniker[] {
public getMonikers(applications: Application[], filter: IServerGroupFilter = defaultFilter): IMoniker[] {
const allMonikers: IMoniker[][] = applications.map(a => a.getDataSource('serverGroups').data
.filter(filter)
.map((serverGroup: IServerGroup) => serverGroup.moniker));
return compact(flatten(allMonikers));
}
Expand Down