-
Notifications
You must be signed in to change notification settings - Fork 738
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ecs): add API support for ECS Describe Clusters (#1394)
* feat(ecs): add API support for ECS Describe Clusters * add review comments:1 * add review comments:2 * address feedback:3 * add unit tests Co-authored-by: Parag Bhingre <pbhingre@gmail.com> Co-authored-by: Piradeep Kandasamy <44981951+piradeepk@users.noreply.github.com>
- Loading branch information
1 parent
d2b00d8
commit 48ba922
Showing
4 changed files
with
108 additions
and
0 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
94 changes: 94 additions & 0 deletions
94
...eb/src/test/groovy/com/netflix/spinnaker/gate/controllers/EcsClusterControllerSpec.groovy
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,94 @@ | ||
/* | ||
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
* CONDITIONS OF ANY KIND, either express or implied. See the License | ||
* for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.gate.controllers | ||
|
||
import com.netflix.spinnaker.gate.services.EcsClusterService | ||
import com.netflix.spinnaker.gate.controllers.ecs.EcsClusterController | ||
import com.netflix.spinnaker.gate.services.internal.ClouddriverService | ||
import com.squareup.okhttp.mockwebserver.MockWebServer | ||
import groovy.json.JsonSlurper | ||
import org.springframework.http.MediaType | ||
import org.springframework.mock.web.MockHttpServletResponse | ||
import org.springframework.test.web.servlet.MockMvc | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders | ||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get | ||
|
||
class EcsClusterControllerSpec extends Specification { | ||
|
||
def server = new MockWebServer() | ||
MockMvc mockMvc | ||
def cloudDriverService | ||
def ecsClusterService | ||
|
||
void cleanup() { | ||
server.shutdown() | ||
} | ||
|
||
void setup(){ | ||
given: | ||
cloudDriverService = Mock(ClouddriverService) | ||
ecsClusterService = new EcsClusterService(cloudDriverService) | ||
server.start() | ||
mockMvc = MockMvcBuilders.standaloneSetup(new EcsClusterController(ecsClusterService: ecsClusterService)).build() | ||
} | ||
|
||
@Unroll | ||
void 'Describe Cluster API should return 200 with cluster descriptions'() { | ||
|
||
def apiResponse = [ | ||
[ activeServicesCount : '2', | ||
attachments :[], | ||
capacityProviders : [], | ||
clusterArn :'arn:aws:ecs:us-west-2:123123123:cluster/spinnaker', | ||
clusterName : 'spinnaker', | ||
defaultCapacityProviderStrategy : [], | ||
pendingTasksCount : '3', | ||
registeredContainerInstancesCount : '0', | ||
runningTasksCount : '0', | ||
settings :[[ name :'containerInsights', | ||
value : 'disabled']], | ||
], | ||
] | ||
|
||
1 * cloudDriverService.getEcsClusterDescriptions('ecs-my-aws-devel-acct', 'us-west-2') >> apiResponse | ||
when: | ||
MockHttpServletResponse response = mockMvc.perform( | ||
get("/ecs/ecsClusterDescriptions/ecs-my-aws-devel-acct/us-west-2").contentType(MediaType.APPLICATION_JSON) | ||
).andReturn().response | ||
|
||
then: | ||
response.status == 200 | ||
new JsonSlurper().parseText(response.contentAsString) == apiResponse | ||
} | ||
|
||
@Unroll | ||
void 'Describe Cluster API should return 200 with empty response'() { | ||
def apiResponse = [] | ||
|
||
1 * cloudDriverService.getEcsClusterDescriptions('ecs-my-aws-devel-acct', 'us-west-2') >> apiResponse | ||
when: | ||
MockHttpServletResponse response = mockMvc.perform( | ||
get("/ecs/ecsClusterDescriptions/ecs-my-aws-devel-acct/us-west-2").contentType(MediaType.APPLICATION_JSON) | ||
).andReturn().response | ||
|
||
then: | ||
response.status == 200 | ||
new JsonSlurper().parseText(response.contentAsString) == apiResponse | ||
} | ||
} |