Skip to content

Commit

Permalink
Create reproducing test
Browse files Browse the repository at this point in the history
  • Loading branch information
angrycub committed Oct 24, 2023
1 parent db9f7f8 commit ac31c02
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion internal/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ func TestCLI_PackStatus_Fails(t *testing.T) {
})
}

func TestCLI_PackRender_MyAlias(t *testing.T) {
func TestCLI_PackRender_RootVar(t *testing.T) {
t.Parallel()
// This test has to do some extra shenanigans because dependent pack template
// output is not guaranteed to be ordered. This requires that the test handle
Expand Down Expand Up @@ -519,6 +519,37 @@ func TestCLI_PackRender_MyAlias(t *testing.T) {
must.SliceContainsAll(t, expected, elems)
}

func TestCLI_PackRender_SetDepVarWithFlag(t *testing.T) {
t.Parallel()
// This test has to do some extra shenanigans because dependent pack template
// output is not guaranteed to be ordered. This requires that the test handle
// either order.
expected := []string{
"deps_test/child1/child1.nomad=override",
"deps_test/child2/child2.nomad=child2",
"deps_test/deps_test.nomad=deps_test",
}

result := runPackCmd(t, []string{
"render",
"--no-format=true",
"--var", "child1.job_name=override",
getTestPackPath(t, "my_alias_test"),
})

must.Eq(t, result.cmdErr.String(), "", must.Sprintf("cmdErr should be empty, but was %q", result.cmdErr.String()))
must.Eq(t, 0, result.exitCode, must.Sprintf("incorrect exit code.\nstdout:\n%v\nstderr:%v\n", result.cmdOut.String(), result.cmdErr.String()))

// Performing a little clever string manipulation on the render output to
// prepare it for splitting into a slice of string enables us to use
// require.ElementsMatch to validate goodness.
outStr := strings.TrimSpace(result.cmdOut.String())
outStr = strings.ReplaceAll(outStr, ":\n\n", "=")
elems := strings.Split(outStr, "\n")

must.SliceContainsAll(t, expected, elems)
}

func TestCLI_CLIFlag_Namespace(t *testing.T) {
testCases := []struct {
desc string
Expand Down

0 comments on commit ac31c02

Please sign in to comment.