Skip to content

Commit

Permalink
add env var flags for passthrough to test suites
Browse files Browse the repository at this point in the history
Co-authored-by: Nick Rohn <nrohn@vmware.com>
Co-authored-by: Gary Liu <garyliu@vmware.com>
  • Loading branch information
notrepo05 and syslxg committed Jun 21, 2023
1 parent 03b5540 commit 3eadd0a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
35 changes: 21 additions & 14 deletions internal/commands/test_tile.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ type TileTest struct {
TilePath string `short:"tp" long:"tile-path" default:"." description:"Path to the Tile directory (e.g., ~/workspace/tas/ist)."`
GingkoFlags string `short:"gmf" long:"ginkgo-flags" default:"-r -p -slowSpecThreshold 15" description:"Flags to pass to the Ginkgo Manifest and Stability test suites."`
Verbose bool `short:"v" long:"verbose" default:"false" description:"Print info lines. This doesn't affect Ginkgo output."`
Manifest bool ` long:"manifest" default:"false" description:"Focus the Manifest tests (ert by default)."`
Manifest bool ` long:"manifest" default:"false" description:"Focus the Manifest tests."`
Migrations bool ` long:"migrations" default:"false" description:"Focus the Migration tests."`
Stability bool ` long:"stability" default:"false" description:"Focus the Stability tests (srt and ert by default)."`
EnvironmentVars []string `short:"e" long:"environment-variable" description:"Pass environment variable to the test suites. For example -e 'PRODUCT=srt'."`
Stability bool ` long:"stability" default:"false" description:"Focus the Stability tests."`
EnvironmentVars []string `short:"e" long:"environment-variable" description:"Pass environment variable to the test suites. For example --stability -e 'PRODUCT=srt'."`
}

logger *log.Logger
Expand Down Expand Up @@ -200,23 +200,26 @@ func (u TileTest) Execute(args []string) error {
runAll := !u.Options.Manifest && !u.Options.Migrations && !u.Options.Stability

var dockerCmds []string
if u.Options.Manifest || runAll {
dockerCmds = append(dockerCmds, fmt.Sprintf("cd /tas/%s/test/manifest", tileDir))
dockerCmds = append(dockerCmds, fmt.Sprintf("ginkgo %s", u.Options.GingkoFlags))
}
if u.Options.Migrations || runAll {
dockerCmds = append(dockerCmds, fmt.Sprintf("cd /tas/%s/migrations", tileDir))
dockerCmds = append(dockerCmds, "npm install")
dockerCmds = append(dockerCmds, "npm test")
dockerCmds = append(dockerCmds, fmt.Sprintf("npm install"))
dockerCmds = append(dockerCmds, fmt.Sprintf("npm test"))
}
ginkgo := []string{}
if u.Options.Stability || runAll {
dockerCmds = append(dockerCmds, fmt.Sprintf("cd /tas/%s/test/stability", tileDir))
dockerCmds = append(dockerCmds, fmt.Sprintf("ginkgo %s", u.Options.GingkoFlags))
ginkgo = append(ginkgo, fmt.Sprintf("/tas/%s/test/stability", tileDir))
}
if u.Options.Manifest || runAll {
ginkgo = append(ginkgo, fmt.Sprintf("/tas/%s/test/manifest", tileDir))
}
if u.Options.Stability || u.Options.Manifest || runAll {
dockerCmds = append(dockerCmds, fmt.Sprintf("cd /tas/%s && ginkgo %s %s", tileDir, u.Options.GingkoFlags, strings.Join(ginkgo, " ")))
}
dockerCmd := strings.Join(dockerCmds, " && ")

envVars := getTileTestEnvVars(absRepoDir, tileDir, envMap)
dockerCmd := strings.Join(dockerCmds, " && ")
loggerWithInfo.Info("Running:", dockerCmd)
envVars := getTileTestEnvVars(absRepoDir, tileDir, envMap)
fmt.Printf("%+v\n", envVarsToSlice(envVars))
createResp, err := u.mobi.ContainerCreate(u.ctx, &container.Config{
Image: "kiln_test_dependencies:vmware",
Cmd: []string{"/bin/bash", "-c", dockerCmd},
Expand Down Expand Up @@ -320,7 +323,11 @@ func getTileTestEnvVars(dir, productDir string, envMap environmentVars) environm
envVarsMap["TAS_CONFIG_FILE"] = fmt.Sprintf(fixturesFormat+"/%s", "/tas/"+productDir, "tas_config.yml")
}

envVarsMap["PRODUCT"] = toProduct(productDir)
// no need to set for tas tile, since it defaults to ert.
// for ist and tasw, we need to set it, as there's no default.
if toProduct(productDir) != "ert" {
envVarsMap["PRODUCT"] = toProduct(productDir)
}
envVarsMap["RENDERER"] = "ops-manifest"

// overwrite with / include optional env vars
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/test_tile_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var _ = Describe("test", func() {

Expect(err).To(HaveOccurred())
Expect(testOutput.String()).NotTo(ContainSubstring("SUCCESS"))
Expect(testOutput.String()).To(ContainSubstring("Failure"))
Expect(testOutput.String()).To(Or(ContainSubstring("ERR!"), ContainSubstring("Failure")))
})
})
})
Expand Down
6 changes: 3 additions & 3 deletions internal/commands/test_tile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ var _ = Describe("kiln test docker", func() {
sort.Strings(actual)
sort.Strings(expected)

dockerCmd := "cd /tas/hello-tile/test/manifest && ginkgo -r -slowSpecThreshold 1"
dockerCmd := "cd /tas/hello-tile && ginkgo -r -slowSpecThreshold 1 /tas/hello-tile/test/manifest"
Expect(config.Cmd).To(Equal(strslice.StrSlice{"/bin/bash", "-c", dockerCmd}))
})
})
Expand Down Expand Up @@ -208,7 +208,7 @@ var _ = Describe("kiln test docker", func() {
sort.Strings(actual)
sort.Strings(expected)

dockerCmd := "cd /tas/hello-tile/test/stability && ginkgo -r -slowSpecThreshold 1"
dockerCmd := "cd /tas/hello-tile && ginkgo -r -slowSpecThreshold 1 /tas/hello-tile/test/stability"
Expect(config.Cmd).To(Equal(strslice.StrSlice{"/bin/bash", "-c", dockerCmd}))
})
})
Expand Down Expand Up @@ -273,7 +273,7 @@ var _ = Describe("kiln test docker", func() {
_, config, _, _, _, _ := fakeMobyClient.ContainerCreateArgsForCall(0)

By("executing the tests", func() {
dockerCmd := "cd /tas/hello-tile/test/manifest && ginkgo -r -p -slowSpecThreshold 15 && cd /tas/hello-tile/migrations && npm install && npm test && cd /tas/hello-tile/test/stability && ginkgo -r -p -slowSpecThreshold 15"
dockerCmd := "cd /tas/hello-tile/migrations && npm install && npm test && cd /tas/hello-tile && ginkgo -r -p -slowSpecThreshold 15 /tas/hello-tile/test/stability /tas/hello-tile/test/manifest"
actual := config.Env
expected := []string{
"TAS_CONFIG_FILE=/tas/hello-tile/test/manifest/fixtures/tas_config.yml",
Expand Down

0 comments on commit 3eadd0a

Please sign in to comment.