Skip to content

Commit 2db4170

Browse files
committed
e2e-tests: simplify bosh curl helper
- Always passing a value to json.Unmarshal so just use "any", a generic doesn't help - bosh curl always returns json from the bosh director api, so specifically adding --json adds no value - bosh curl is independent of the deployment, so can further be simplified [TNZ-66259](https://vmw-jira.broadcom.net/browse/TNZ-66259) Authored-by: Andrew Garner <andrew.garner@broadcom.com>
1 parent 902354c commit 2db4170

1 file changed

Lines changed: 12 additions & 28 deletions

File tree

src/e2e-tests/proxy_healthcheck_test.go

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import (
44
"bytes"
55
"encoding/json"
66
"fmt"
7-
"io"
7+
"os/exec"
88
"slices"
99
"strings"
1010
"time"
1111

12-
"e2e-tests/utilities/bosh"
13-
"e2e-tests/utilities/cmd"
1412
"github.com/google/uuid"
1513
. "github.com/onsi/ginkgo/v2"
1614
. "github.com/onsi/gomega"
15+
16+
"e2e-tests/utilities/bosh"
1717
)
1818

1919
var _ = Describe("Proxy healthcheck", Ordered, Label("proxy", "healthchecks"), func() {
@@ -135,7 +135,7 @@ func boshDNSAddress(deploymentName, jobName string) string {
135135
// Get all links
136136
var deploymentLinks []link
137137

138-
err := curl(deploymentName, "/links?deployment="+deploymentName, &deploymentLinks)
138+
err := curl("/links?deployment="+deploymentName, &deploymentLinks)
139139
Expect(err).NotTo(HaveOccurred())
140140

141141
// Get first proxy link
@@ -152,41 +152,25 @@ func boshDNSAddress(deploymentName, jobName string) string {
152152
// Get links address
153153
var address linkAddress
154154

155-
err = curl(deploymentName, "/link_address?link_id="+targetLinkID, &address)
155+
err = curl("/link_address?link_id="+targetLinkID, &address)
156156
Expect(err).NotTo(HaveOccurred())
157157

158158
return address.Address
159159
}
160160

161-
func curl[T any](deploymentName, endpoint string, target *T) error {
161+
func curl(endpoint string, target any) error {
162162
var output bytes.Buffer
163-
if err := cmd.RunWithoutOutput(io.MultiWriter(&output, GinkgoWriter),
164-
"bosh",
165-
"--deployment="+deploymentName,
166-
"curl",
167-
endpoint,
168-
"--json",
169-
); err != nil {
163+
cmd := exec.Command("bosh", "curl", endpoint)
164+
cmd.Stdout = &output
165+
cmd.Stderr = GinkgoWriter
166+
if err := cmd.Run(); err != nil {
170167
return fmt.Errorf("remote curl failed: %w", err)
171168
}
172169

173-
var result struct {
174-
Blocks []string `json:"Blocks"`
175-
}
176-
177-
if err := json.Unmarshal(output.Bytes(), &result); err != nil {
178-
return fmt.Errorf("failed to unmarshal bosh curl response (%q): %w", output.String(), err)
179-
}
180-
181-
if len(result.Blocks) == 0 {
182-
return fmt.Errorf("no response blocks provided by bosh curl (%q)", output.String())
183-
}
184-
185-
// Does bosh curl ever return >1 Blocks?
186-
err := json.Unmarshal([]byte(result.Blocks[0]), target)
187-
if err != nil {
170+
if err := json.Unmarshal(output.Bytes(), target); err != nil {
188171
return fmt.Errorf("failed to parse JSON: %w", err)
189172
}
173+
190174
return nil
191175
}
192176

0 commit comments

Comments
 (0)