Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
claymccoy committed May 23, 2014
1 parent 0d983e6 commit 55803bb
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 47 deletions.
6 changes: 2 additions & 4 deletions app/scripts/controllers/deployment/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,8 @@ angular.module("asgardApp")
$scope.environment = data.environment;
$scope.asgOptions = data.asgOptions;
$scope.lcOptions = data.lcOptions;
if ($scope.asgOptions) {
$scope.suspendAZRebalance = $scope.asgOptions.suspendedProcesses.indexOf("AZRebalance") > -1;
$scope.suspendAddToLoadBalancer = $scope.asgOptions.suspendedProcesses.indexOf("AddToLoadBalancer") > -1;
}
$scope.suspendAZRebalance = $scope.asgOptions.suspendedProcesses.indexOf("AZRebalance") > -1;
$scope.suspendAddToLoadBalancer = $scope.asgOptions.suspendedProcesses.indexOf("AddToLoadBalancer") > -1;
initStepsDisplay();
angular.forEach($scope.environment.subnetPurposes.concat(""), function(value) {
$scope.selectionsForSubnet[value] = {
Expand Down
189 changes: 147 additions & 42 deletions test/spec/controllers/deployment/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,26 @@ describe('Controller: DeploymentNewCtrl', function () {
});
}));

it('should set initial scope', function () {
$httpBackend.expectGET(
'deployment/prepare/helloworld?deploymentTemplateName=CreateAndCleanUpPreviousAsg&includeEnvironment=true').respond({
deploymentOptions: { steps: [] },
environment: 'environment1',
lcOptions: 'lcOptions1',
asgOptions: {
name: "asgOptions1",
suspendedProcesses: ["AddToLoadBalancer"]
}
});
$httpBackend.flush();
expect(scope.clusterName).toEqual('helloworld');
expect(scope.hideAdvancedItems).toEqual(true);
expect(scope.deploymentOptions).toEqual({ steps: [] });
expect(scope.environment).toEqual('environment1');
expect(scope.asgOptions.name).toEqual('asgOptions1');
expect(scope.lcOptions).toEqual('lcOptions1');
expect(scope.vpcId).toEqual(undefined);
expect(scope.suspendAZRebalance).toEqual(false);
expect(scope.suspendAddToLoadBalancer).toEqual(true);
});

it('should set VPC id based on subnet purpose', function () {
$httpBackend.expectGET(
'deployment/prepare/helloworld?deploymentTemplateName=CreateAndCleanUpPreviousAsg&includeEnvironment=true').respond({
deploymentOptions: { steps: [] },
asgOptions: {
subnetPurpose: "",
suspendedProcesses: [],
availabilityZones: [],
loadBalancerNames: []
},
lcOptions: {
securityGroups: []
},
environment: {
subnetPurposes: [],
purposeToVpcId: {
'internal': 'vpc1',
'external': 'vpc2'
}
},
securityGroups: []
}
});
$httpBackend.flush();
Expand All @@ -69,10 +57,21 @@ describe('Controller: DeploymentNewCtrl', function () {
it('should toggle suspended processes', function () {
$httpBackend.expectGET(
'deployment/prepare/helloworld?deploymentTemplateName=CreateAndCleanUpPreviousAsg&includeEnvironment=true').respond({
deploymentOptions: { steps: [] },
asgOptions: {
suspendedProcesses: []
}
deploymentOptions: { steps: [] },
asgOptions: {
subnetPurpose: "",
suspendedProcesses: [],
availabilityZones: [],
loadBalancerNames: []
},
lcOptions: {
securityGroups: []
},
environment: {
purposeToVpcId: {},
subnetPurposes: [],
securityGroups: []
}
});
$httpBackend.flush();
expect(scope.suspendAZRebalance).toEqual(false);
Expand Down Expand Up @@ -110,13 +109,38 @@ describe('Controller: DeploymentNewCtrl', function () {
it('should start deployment', function () {
$httpBackend.expectGET(
'deployment/prepare/helloworld?deploymentTemplateName=CreateAndCleanUpPreviousAsg&includeEnvironment=true').respond({
deploymentOptions: { steps: [] }
deploymentOptions: { steps: [] },
asgOptions: {
subnetPurpose: "",
suspendedProcesses: [],
availabilityZones: [],
loadBalancerNames: []
},
lcOptions: {
securityGroups: []
},
environment: {
purposeToVpcId: {},
subnetPurposes: [],
securityGroups: []
}
});
$httpBackend.flush();
expect(scope.startingDeployment).toEqual(undefined);
scope.startDeployment();
expect(scope.startingDeployment).toEqual(true);
$httpBackend.expectPOST('deployment/start', {"deploymentOptions":{ steps: [] }}).respond(200, {
$httpBackend.expectPOST('deployment/start', {
deploymentOptions: { steps: [] },
asgOptions: {
subnetPurpose: "",
suspendedProcesses: [],
availabilityZones: [],
loadBalancerNames: []
},
lcOptions: {
securityGroups: []
}
}).respond(200, {
deploymentId: "123"
});
$httpBackend.flush();
Expand All @@ -126,13 +150,38 @@ describe('Controller: DeploymentNewCtrl', function () {
it('should show errors on failure to start deployment', function () {
$httpBackend.expectGET(
'deployment/prepare/helloworld?deploymentTemplateName=CreateAndCleanUpPreviousAsg&includeEnvironment=true').respond({
deploymentOptions: { steps: [] }
deploymentOptions: { steps: [] },
asgOptions: {
subnetPurpose: "",
suspendedProcesses: [],
availabilityZones: [],
loadBalancerNames: []
},
lcOptions: {
securityGroups: []
},
environment: {
purposeToVpcId: {},
subnetPurposes: [],
securityGroups: []
}
});
$httpBackend.flush();
expect(scope.startingDeployment).toEqual(undefined);
scope.startDeployment();
expect(scope.startingDeployment).toEqual(true);
$httpBackend.expectPOST('deployment/start', {"deploymentOptions":{ steps: [] }}).respond(422, {
$httpBackend.expectPOST('deployment/start', {
deploymentOptions: { steps: [] },
asgOptions: {
subnetPurpose: "",
suspendedProcesses: [],
availabilityZones: [],
loadBalancerNames: []
},
lcOptions: {
securityGroups: []
}
}).respond(422, {
validationErrors: 'errors'
});
$httpBackend.flush();
Expand All @@ -143,16 +192,30 @@ describe('Controller: DeploymentNewCtrl', function () {

it('should conditionally allow steps', function() {
$httpBackend.expectGET(
'deployment/prepare/helloworld?deploymentTemplateName=CreateAndCleanUpPreviousAsg&includeEnvironment=true').respond({
deploymentOptions: {
steps: [
{"type":"Wait","durationMinutes":60},
{"type":"CreateAsg"},
{"type":"Resize","targetAsg":"Next","capacity":0,"startUpTimeoutMinutes":40},
{"type":"Judgment","durationMinutes":120},
{"type":"DisableAsg","targetAsg":"Previous"}
]
}
'deployment/prepare/helloworld?deploymentTemplateName=CreateAndCleanUpPreviousAsg&includeEnvironment=true').respond({
deploymentOptions: {
steps: [
{"type":"Wait","durationMinutes":60},
{"type":"CreateAsg"},
{"type":"Resize","targetAsg":"Next","capacity":0,"startUpTimeoutMinutes":40},
{"type":"Judgment","durationMinutes":120},
{"type":"DisableAsg","targetAsg":"Previous"}
]
},
asgOptions: {
subnetPurpose: "",
suspendedProcesses: [],
availabilityZones: [],
loadBalancerNames: []
},
lcOptions: {
securityGroups: []
},
environment: {
purposeToVpcId: {},
subnetPurposes: [],
securityGroups: []
}
});
$httpBackend.flush();
expect(scope.isStepAllowed("Wait", 4)).toEqual(true);
Expand Down Expand Up @@ -183,6 +246,20 @@ describe('Controller: DeploymentNewCtrl', function () {
{"type":"DisableAsg","targetAsg":"Previous"},
{"type":"DeleteAsg","targetAsg":"Previous"}
]
},
asgOptions: {
subnetPurpose: "",
suspendedProcesses: [],
availabilityZones: [],
loadBalancerNames: []
},
lcOptions: {
securityGroups: []
},
environment: {
purposeToVpcId: {},
subnetPurposes: [],
securityGroups: []
}
});
$httpBackend.flush();
Expand All @@ -204,6 +281,20 @@ describe('Controller: DeploymentNewCtrl', function () {
{"type":"CreateAsg"},
{"type":"DeleteAsg","targetAsg":"Previous"}
]
},
asgOptions: {
subnetPurpose: "",
suspendedProcesses: [],
availabilityZones: [],
loadBalancerNames: []
},
lcOptions: {
securityGroups: []
},
environment: {
purposeToVpcId: {},
subnetPurposes: [],
securityGroups: []
}
});
$httpBackend.flush();
Expand Down Expand Up @@ -253,6 +344,20 @@ describe('Controller: DeploymentNewCtrl', function () {
{ type : 'DisableAsg', targetAsg : 'Previous' },
{"type":"DeleteAsg","targetAsg":"Previous"}
]
},
asgOptions: {
subnetPurpose: "",
suspendedProcesses: [],
availabilityZones: [],
loadBalancerNames: []
},
lcOptions: {
securityGroups: []
},
environment: {
purposeToVpcId: {},
subnetPurposes: [],
securityGroups: []
}
});
$httpBackend.flush();
Expand Down
4 changes: 3 additions & 1 deletion test/unit/com/netflix/asgard/DeploymentControllerSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ class DeploymentControllerSpec extends Specification {
}
with(controller.awsEc2Service) {
1 * getSubnets(_) >> subnets
1 * getSecurityGroup(_, 'sg-12345678') >> new SecurityGroup(groupId: 'sg-12345678')
}
0 * _
}
Expand Down Expand Up @@ -483,7 +484,7 @@ class DeploymentControllerSpec extends Specification {
[id: "ELB", description: "Replace instances that fail ELB health check"]
],
instanceTypes: [[id: null, price:""]],
securityGroups: [[id: "sg-1", name: "hcsg", selection: "sg-1", vpcId: "vpc1"]],
securityGroups: [[id: "sg-1", name: "hcsg", vpcId: "vpc1"]],
images: [[id: "img123", imageLocation: "imgloc"]],
keys: ["key1"],
spotUrl: "spotUrl"
Expand All @@ -504,6 +505,7 @@ class DeploymentControllerSpec extends Specification {
1 * getEffectiveSecurityGroups(_) >> [new SecurityGroup(groupId: "sg-1", groupName: "hcsg", vpcId: "vpc1")]
1 * getAvailabilityZones(_) >> [new AvailabilityZone(zoneName: "us-east-1")]
1 * getKeys(_) >> [new KeyPairInfo(keyName: "key1")]
1 * getSecurityGroup(_, 'sg-12345678') >> new SecurityGroup(groupId: 'sg-12345678')
}
with(controller.awsLoadBalancerService) {
1 * getLoadBalancers(_) >> [new LoadBalancerDescription(loadBalancerName: "lb1", vPCId: "vpc1")]
Expand Down

0 comments on commit 55803bb

Please sign in to comment.