Skip to content

Commit d50e89b

Browse files
authored
fix: handle workflow input flag parsing (#379)
* fix: handle workflow input flag parsing Signed-off-by: Asra Ali <[email protected]> * add smoke tests Signed-off-by: Asra Ali <[email protected]> Signed-off-by: Asra Ali <[email protected]>
1 parent c9993a5 commit d50e89b

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

cli/slsa-verifier/main_test.go

+33-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"bytes"
45
"context"
56
"errors"
67
"fmt"
@@ -487,7 +488,7 @@ func Test_runVerifyGHAArtifactPath(t *testing.T) {
487488
// Avoid rate limiting by not running the tests in parallel.
488489
// t.Parallel()
489490

490-
checkVersions := getBuildersAndVersions(t, tt.minversion, tt.builders, GHA_ARTIFACT_PATH_BUILDERS)
491+
checkVersions := getBuildersAndVersions(t, "v1.2.2", tt.builders, GHA_ARTIFACT_PATH_BUILDERS)
491492
if tt.noversion {
492493
checkVersions = []string{""}
493494
}
@@ -576,6 +577,37 @@ func Test_runVerifyGHAArtifactPath(t *testing.T) {
576577
if err := outBuilderID.Matches(*bid, false); err != nil {
577578
t.Errorf(fmt.Sprintf("matches failed (2): %v", err))
578579
}
580+
581+
// Smoke test against the CLI command
582+
cliCmd := verifyArtifactCmd()
583+
args := []string{
584+
artifactPath,
585+
"--source-uri", tt.source,
586+
"--provenance-path", provenancePath}
587+
if bid != nil {
588+
args = append(args, "--builder-id", *bid)
589+
}
590+
if tt.pbranch != nil {
591+
args = append(args, "--source-branch", *tt.pbranch)
592+
}
593+
if tt.ptag != nil {
594+
args = append(args, "--source-tag", *tt.ptag)
595+
}
596+
if tt.pversiontag != nil {
597+
args = append(args, "--source-versioned-tag", *tt.pversiontag)
598+
}
599+
if tt.inputs != nil {
600+
for k, v := range tt.inputs {
601+
args = append(args, "--build-workflow-input", fmt.Sprintf("%s=%s", k, v))
602+
}
603+
}
604+
b := bytes.NewBufferString("")
605+
cliCmd.SetOut(b)
606+
cliCmd.SetArgs(args)
607+
cliErr := cliCmd.Execute()
608+
if !errCmp(cliErr, tt.err) {
609+
t.Errorf("%v: %v", v, cmp.Diff(cliErr, tt.err, cmpopts.EquateErrors()))
610+
}
579611
}
580612
}
581613
})

cli/slsa-verifier/verify/options.go

+3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ func (i *workflowInputs) Set(value string) error {
9191
if len(l) != 2 {
9292
return fmt.Errorf("%w: expected 'key=value' format, got '%s'", serrors.ErrorInvalidFormat, value)
9393
}
94+
if i.kv == nil {
95+
i.kv = make(map[string]string)
96+
}
9497
i.kv[l[0]] = l[1]
9598
return nil
9699
}

0 commit comments

Comments
 (0)