Skip to content

Commit

Permalink
AWS network form has radio inputs.
Browse files Browse the repository at this point in the history
[#138005815]
Signed-off-by: Dave Walter <[email protected]>
  • Loading branch information
Zachary Gershman authored and davewalter committed Feb 24, 2017
1 parent 4ff13bb commit 2bcd924
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 11 deletions.
11 changes: 11 additions & 0 deletions api/bosh_form_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,16 @@ func (bs BoshFormService) Networks() (map[string]string, error) {
},
)

if len(networks) == 0 {
document.Find(`input[id*=network][type=radio]`).Each(
func(i int, s *goquery.Selection) {
guid, _ := s.Attr("value")
name := strings.TrimSpace(document.Find(fmt.Sprintf("label[for*=%s]", guid)).First().Text())

networks[name] = guid
},
)
}

return networks, nil
}
64 changes: 53 additions & 11 deletions api/bosh_form_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ const VsphereAZDocument = `
</body>
</html>`

const AWSNetworkDocument = `
<html>
<body>
<form action="/some/action" method="some-method">
<input name="_method" value="some-rails" />
<input name="authenticity_token" value="some-authenticity" />
<div class="controls">
<label for="network_collection_networks_attributes_0_subnets_0_availability_zone_references_some-guid">
<input id="network_collection_networks_attributes_0_subnets_0_availability_zone_references_some-guid" type="radio" value="some-guid">
us-west-1b
</label>
<label for="network_collection_networks_attributes_0_subnets_0_availability_zone_references_some-other-guid">
<input id="network_collection_networks_attributes_0_subnets_0_availability_zone_references_some-other-guid" type="radio" value="some-other-guid">
us-west-1c
</label>
</div>
</form>
</body>
</html>`

const NetDocument = `
<html>
<body>
Expand Down Expand Up @@ -298,21 +318,43 @@ var _ = Describe("BoshFormService", func() {
})

Describe("Networks", func() {
It("returns a map of networks", func() {
client.DoReturns(&http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(strings.NewReader(NetDocument)),
}, nil)
Context("when the networks are selectors", func() {
It("returns a map of networks", func() {
client.DoReturns(&http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(strings.NewReader(NetDocument)),
}, nil)

netMap, err := service.Networks()
Expect(err).NotTo(HaveOccurred())
netMap, err := service.Networks()
Expect(err).NotTo(HaveOccurred())

req := client.DoArgsForCall(0)
req := client.DoArgsForCall(0)

Expect(req.Method).To(Equal("GET"))
Expect(req.URL.Path).To(Equal("/infrastructure/director/az_and_network_assignment/edit"))
Expect(req.Method).To(Equal("GET"))
Expect(req.URL.Path).To(Equal("/infrastructure/director/az_and_network_assignment/edit"))

Expect(netMap).To(HaveKeyWithValue("some-net", "ed9b4dcf24dad744b1cf"))
})
})

Expect(netMap).To(HaveKeyWithValue("some-net", "ed9b4dcf24dad744b1cf"))
Context("when the networks are radio buttons", func() {
It("returns a map of networks", func() {
client.DoReturns(&http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(strings.NewReader(AWSNetworkDocument)),
}, nil)

netMap, err := service.Networks()
Expect(err).NotTo(HaveOccurred())

req := client.DoArgsForCall(0)

Expect(req.Method).To(Equal("GET"))
Expect(req.URL.Path).To(Equal("/infrastructure/director/az_and_network_assignment/edit"))

Expect(netMap).To(HaveKeyWithValue("us-west-1b", "some-guid"))
Expect(netMap).To(HaveKeyWithValue("us-west-1c", "some-other-guid"))
})
})

Context("failure cases", func() {
Expand Down

0 comments on commit 2bcd924

Please sign in to comment.