Skip to content

Commit f58ef6b

Browse files
committed
Acceptance Tests: use long-form bosh flags
1 parent 4cf39f3 commit f58ef6b

File tree

1 file changed

+39
-31
lines changed

1 file changed

+39
-31
lines changed

acceptance_test/main_test.go

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package windows_stemcell_acceptance_test
22

33
import (
44
"archive/zip"
5-
"bytes"
65
"encoding/json"
76
"fmt"
87
"io"
@@ -308,11 +307,20 @@ func newBoshCommand(config *TestConfig) *BoshCommand {
308307
}
309308

310309
func (c *BoshCommand) args(command string) []string {
311-
args := strings.Split(command, " ")
312-
args = append([]string{"-n", "-e", c.DirectorIP, "--client", c.Client, "--client-secret", c.ClientSecret}, args...)
310+
commonArgs := []string{
311+
"--non-interactive",
312+
fmt.Sprintf("--environment=%s", c.DirectorIP),
313+
fmt.Sprintf("--client=%s", c.Client),
314+
fmt.Sprintf("--client-secret=%s", c.ClientSecret),
315+
}
313316
if c.CertPath != "" {
314-
args = append([]string{"--ca-cert", c.CertPath}, args...)
317+
commonArgs = append(commonArgs, fmt.Sprintf("--ca-cert=%s", c.CertPath))
315318
}
319+
320+
commandArgs := strings.Split(command, " ")
321+
322+
args := append(commonArgs, commandArgs...)
323+
316324
return args
317325
}
318326

@@ -321,18 +329,16 @@ func (c *BoshCommand) Run(command string) error {
321329
}
322330

323331
func (c *BoshCommand) RunErrand(errandName string, deploymentName string) error {
324-
return c.Run(fmt.Sprintf("-d %s run-errand --download-logs %s --tty", deploymentName, errandName))
332+
return c.Run(fmt.Sprintf("--deployment=%s run-errand --download-logs %s --tty", deploymentName, errandName))
325333
}
326334

327335
func (c *BoshCommand) RunInStdOut(command, dir string) ([]byte, error) {
328336
cmd := exec.Command("bosh", c.args(command)...)
329337

330338
if dir != "" {
331339
cmd.Dir = dir
332-
GinkgoWriter.Printf("\nRUNNING %q IN %q\n", strings.Join(cmd.Args, " "), dir)
333-
} else {
334-
GinkgoWriter.Printf("\nRUNNING %q\n", strings.Join(cmd.Args, " "))
335340
}
341+
GinkgoWriter.Printf("\nRUNNING: %q\nWorking Dir: %q\n", strings.Join(cmd.Args, " "), cmd.Dir)
336342

337343
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
338344
if err != nil {
@@ -349,7 +355,7 @@ func (c *BoshCommand) RunInStdOut(command, dir string) ([]byte, error) {
349355
}
350356
return stdout,
351357
fmt.Errorf(
352-
"Non-zero exit code for cmd %q: %d\nSTDERR:\n%s\nSTDOUT:%s\n",
358+
"Non-zero exit code for cmd %q: %d\nSTDERR:\n%s\nSTDOUT:%s\n---------------------------------\n",
353359
strings.Join(cmd.Args, " "), exitCode, stderr, stdout,
354360
)
355361
}
@@ -457,30 +463,25 @@ type ManifestProperties struct {
457463
SecurityComplianceApplied bool
458464
}
459465

460-
func (m ManifestProperties) toVarsString() string {
461-
manifest := m.toMap()
462-
463-
fmtString := "-v %s=%s "
466+
func (m ManifestProperties) toVarsFlags() []string {
467+
const stringVarFmt = `--var=%s="%s"`
468+
const boolVarFmt = "--var=%s=%t"
464469

465-
var b bytes.Buffer
470+
var varFlags []string
466471

467-
for k, v := range manifest {
472+
for k, v := range m.toMap() {
468473
if v != "" {
469-
_, err := fmt.Fprintf(&b, fmtString, k, v)
470-
Expect(err).NotTo(HaveOccurred())
474+
varFlags = append(varFlags, fmt.Sprintf(stringVarFmt, k, v))
471475
}
472476
}
473477

474-
boolOperators := []string{
475-
fmt.Sprintf("-v MountEphemeralDisk=%t", m.MountEphemeralDisk),
476-
fmt.Sprintf("-v SSHDisabledByDefault=%t", m.SSHDisabledByDefault),
477-
fmt.Sprintf("-v SecurityComplianceApplied=%t", m.SecurityComplianceApplied),
478-
}
478+
varFlags = append(varFlags,
479+
fmt.Sprintf(boolVarFmt, "MountEphemeralDisk", m.MountEphemeralDisk),
480+
fmt.Sprintf(boolVarFmt, "SSHDisabledByDefault", m.SSHDisabledByDefault),
481+
fmt.Sprintf(boolVarFmt, "SecurityComplianceApplied", m.SecurityComplianceApplied),
482+
)
479483

480-
_, err := fmt.Fprint(&b, strings.Join(boolOperators, " "))
481-
Expect(err).NotTo(HaveOccurred())
482-
483-
return b.String()
484+
return varFlags
484485
}
485486

486487
func (m ManifestProperties) toMap() map[string]string {
@@ -568,9 +569,19 @@ func (c *TestConfig) deployWithManifest(bosh *BoshCommand, deploymentName string
568569

569570
var opsFileArgs strings.Builder
570571
for _, path := range opsFiles {
571-
opsFileArgs.WriteString(fmt.Sprintf("-o %s ", path))
572+
opsFileArgs.WriteString(fmt.Sprintf("--ops-file=%s ", path))
572573
}
573-
return bosh.Run(fmt.Sprintf("-d %s deploy %s %s %s", deploymentName, manifestPath, manifestProperties.toVarsString(), opsFileArgs.String()))
574+
cmdArgs := []string{
575+
fmt.Sprintf("--deployment=%s", deploymentName),
576+
"deploy",
577+
manifestPath,
578+
}
579+
for _, path := range opsFiles {
580+
cmdArgs = append(cmdArgs, fmt.Sprintf("--ops-file=%s", path))
581+
}
582+
cmdArgs = append(cmdArgs, manifestProperties.toVarsFlags()...)
583+
584+
return bosh.Run(strings.Join(cmdArgs, " "))
574585
}
575586

576587
func (c *TestConfig) deploy(bosh *BoshCommand, deploymentName string, stemcellVersion string, bwatsVersion string) error {
@@ -580,9 +591,6 @@ func (c *TestConfig) deploy(bosh *BoshCommand, deploymentName string, stemcellVe
580591

581592
var opsFilePaths []string
582593
if c.RootEphemeralVmType != "" {
583-
var pwd string
584-
pwd, err = os.Getwd()
585-
Expect(err).NotTo(HaveOccurred())
586594
opsFilePaths = append(opsFilePaths, filepath.Join(pwd, "assets", "root-disk-as-ephemeral.yml"))
587595
}
588596

0 commit comments

Comments
 (0)