Skip to content

Commit

Permalink
Add more flexible arguments that allow for both happy and bad flow te…
Browse files Browse the repository at this point in the history
…st cases

Signed-off-by: Brend Smits <brend.smits@philips.com>
  • Loading branch information
Brend-Smits authored and marcofranssen committed Oct 12, 2021
1 parent f7a7cd5 commit ed00d02
Showing 1 changed file with 52 additions and 17 deletions.
69 changes: 52 additions & 17 deletions cmd/slsa-provenance/cli/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,81 @@ import (
"github.com/philips-labs/slsa-provenance-action/cmd/slsa-provenance/cli"
)

type Arguments struct {
argument string
value string
}

func TestErrors(t *testing.T) {
testCases := []struct {
name string
errorMessage string
validArgument []string
name string
errorMessage string
arguments []Arguments
}{
{
name: "test artifact path argument error",
errorMessage: "no value found for required flag: -artifact_path",
// TODO: Refactor from validArguments to "Arguments" - Allows testing for bad/happy flow
validArgument: []string{"-artifact_path", "artifact/path"},
arguments: []Arguments{
{argument: "", value: ""},
},
},
{
name: "test github context argument error",
errorMessage: "no value found for required flag: -github_context",
arguments: []Arguments{
{argument: "-artifact_path", value: "artifact/path"},
},
},
{
name: "test output path argument error",
errorMessage: "no value found for required flag: -output_path",
validArgument: []string{"-output_path", "output/path"},
name: "test output path argument error",
errorMessage: "no value found for required flag: -output_path",
arguments: []Arguments{
{argument: "-artifact_path", value: "artifact/path"},
{argument: "-github_context", value: "gh-context"},
},
},
{
name: "test github context argument error",
errorMessage: "no value found for required flag: -github_context",
validArgument: []string{"-github_context", "gh-context"},
name: "test runner context argument error",
errorMessage: "no value found for required flag: -runner_context",
arguments: []Arguments{
{argument: "-artifact_path", value: "artifact/path"},
{argument: "-github_context", value: "gh-context"},
{argument: "-output_path", value: "output/path"},
},
},
{
name: "test runner context argument error",
errorMessage: "no value found for required flag: -runner_context",
validArgument: []string{"-runner_context", "runner-context"},
name: "test happy flow",
errorMessage: "",
arguments: []Arguments{
{argument: "-artifact_path", value: "artifact/path"},
{argument: "-github_context", value: "gh-context"},
{argument: "-output_path", value: "output/path"},
{argument: "-runner_context", value: "runner-context"},
},
},
{
name: "test without arguments",
errorMessage: "",
arguments: make([]Arguments, 0),
},
// TODO: Add test case that provides no arguments (use make slice function)
}

cli := cli.Generate()
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := cli.Parse(tc.validArgument)
args := []string{}
for _, v := range tc.arguments {
args = append(args, v.argument, v.value)
}
err := cli.Parse(args)
if err != nil {
t.Error("Failed parsing arguments")
}
err = cli.Run(context.Background())

// TODO: Happy flow: If err message is empty string, go test happy flow
if tc.errorMessage == "" {
// TODO: Happy flow: If err message is empty string, go test happy flow
}

if err == nil {
t.Error("Expected an error but did not generate one")
Expand Down

0 comments on commit ed00d02

Please sign in to comment.