fix: handle workflow input flag parsing (#379)

* fix: handle workflow input flag parsing

Signed-off-by: Asra Ali <asraa@google.com>

* add smoke tests

Signed-off-by: Asra Ali <asraa@google.com>

Signed-off-by: Asra Ali <asraa@google.com>
This commit is contained in:
asraa
2022-12-02 10:01:20 -08:00
committed by GitHub
parent c9993a51d8
commit d50e89b559
2 changed files with 36 additions and 1 deletions
+33 -1
View File
@@ -1,6 +1,7 @@
package main
import (
"bytes"
"context"
"errors"
"fmt"
@@ -487,7 +488,7 @@ func Test_runVerifyGHAArtifactPath(t *testing.T) {
// Avoid rate limiting by not running the tests in parallel.
// t.Parallel()
checkVersions := getBuildersAndVersions(t, tt.minversion, tt.builders, GHA_ARTIFACT_PATH_BUILDERS)
checkVersions := getBuildersAndVersions(t, "v1.2.2", tt.builders, GHA_ARTIFACT_PATH_BUILDERS)
if tt.noversion {
checkVersions = []string{""}
}
@@ -576,6 +577,37 @@ func Test_runVerifyGHAArtifactPath(t *testing.T) {
if err := outBuilderID.Matches(*bid, false); err != nil {
t.Errorf(fmt.Sprintf("matches failed (2): %v", err))
}
// Smoke test against the CLI command
cliCmd := verifyArtifactCmd()
args := []string{
artifactPath,
"--source-uri", tt.source,
"--provenance-path", provenancePath}
if bid != nil {
args = append(args, "--builder-id", *bid)
}
if tt.pbranch != nil {
args = append(args, "--source-branch", *tt.pbranch)
}
if tt.ptag != nil {
args = append(args, "--source-tag", *tt.ptag)
}
if tt.pversiontag != nil {
args = append(args, "--source-versioned-tag", *tt.pversiontag)
}
if tt.inputs != nil {
for k, v := range tt.inputs {
args = append(args, "--build-workflow-input", fmt.Sprintf("%s=%s", k, v))
}
}
b := bytes.NewBufferString("")
cliCmd.SetOut(b)
cliCmd.SetArgs(args)
cliErr := cliCmd.Execute()
if !errCmp(cliErr, tt.err) {
t.Errorf("%v: %v", v, cmp.Diff(cliErr, tt.err, cmpopts.EquateErrors()))
}
}
}
})
+3
View File
@@ -91,6 +91,9 @@ func (i *workflowInputs) Set(value string) error {
if len(l) != 2 {
return fmt.Errorf("%w: expected 'key=value' format, got '%s'", serrors.ErrorInvalidFormat, value)
}
if i.kv == nil {
i.kv = make(map[string]string)
}
i.kv[l[0]] = l[1]
return nil
}