diff --git a/bin/never_alone_report_commit_and_pr_to_kosli.sh b/bin/never_alone_report_commit_and_pr_to_kosli.sh index 5d293181..a88129c0 100755 --- a/bin/never_alone_report_commit_and_pr_to_kosli.sh +++ b/bin/never_alone_report_commit_and_pr_to_kosli.sh @@ -79,8 +79,10 @@ function get_commit_and_pull_request local commit_sha=$1; shift local result_file=$1; shift - pr_data=$(gh pr list --search "${commit_sha}" --state merged --json author,reviews,mergeCommit,mergedAt,reviewDecision,url) - commit_data=$(gh search commits --hash "${commit_sha}" --json author) + pr_data=$(gh pr list --search "${commit_sha}" --state merged --json author,reviews,mergeCommit,mergedAt,reviewDecision,url) \ + || die "Failed to get pull request with: gh pr list --search" + commit_data=$(gh search commits --hash "${commit_sha}" --json author) \ + || die "Failed to get commit with: gh search commits" combined_data=$(jq -n --arg commitsha "$commit_sha" --argjson commit "$commit_data" --argjson pr "$pr_data" \ '{commit_sha: $commitsha, commit: $commit[0], pull_request: $pr[0]}') @@ -118,11 +120,7 @@ function get_commit_and_pull_request combined_data=$(echo "${combined_data}" | jq ". += {\"compliant\": $compliant}") echo "${combined_data}" > ${result_file} - if [ "${compliant}" == "true" ]; then - return 0 - else - return 1 - fi + echo ${compliant} } function get_commit_and_pr_data_and_report_to_kosli @@ -131,13 +129,14 @@ function get_commit_and_pr_data_and_report_to_kosli local proposed_commit=$1; shift local commit_pull_request_flow=$1; shift local trail_name=$1; shift + local commits compliant - commits=($(gh api repos/:owner/:repo/compare/${base_commit}...${proposed_commit} -q '.commits[].sha')) + commits=($(gh api repos/:owner/:repo/compare/${base_commit}...${proposed_commit} -q '.commits[].sha')) \ + || die "Failed to get list of commits between '${base_commit}' and '${proposed_commit}' with: gh api" for commit_sha in "${commits[@]}"; do - short_commit_sha=${commit_sha:0:7} + local short_commit_sha=${commit_sha:0:7} local file_name="commit_pr_${short_commit_sha}.json" - local compliant="true" - get_commit_and_pull_request ${commit_sha} ${file_name} || compliant="false" + compliant=$(get_commit_and_pull_request ${commit_sha} ${file_name}) kosli attest generic \ --name=commit_${short_commit_sha} \ --compliant=${compliant} \ diff --git a/charts/k8s-reporter/Chart.yaml b/charts/k8s-reporter/Chart.yaml index 5470f344..6505a97f 100644 --- a/charts/k8s-reporter/Chart.yaml +++ b/charts/k8s-reporter/Chart.yaml @@ -15,10 +15,10 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 1.5.0 +version: 1.5.1 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. -appVersion: "2.10.11" +appVersion: "2.10.13" diff --git a/charts/k8s-reporter/templates/cronjob.yaml b/charts/k8s-reporter/templates/cronjob.yaml index 7a0e7a98..20019bdd 100644 --- a/charts/k8s-reporter/templates/cronjob.yaml +++ b/charts/k8s-reporter/templates/cronjob.yaml @@ -43,7 +43,8 @@ spec: - --dry-run {{ end }} {{ if .Values.reporterConfig.httpProxy }} - - --http-proxy {{ .Values.reporterConfig.httpProxy }} + - --http-proxy + - {{ .Values.reporterConfig.httpProxy }} {{ end }} resources: diff --git a/charts/k8s-reporter/values.yaml b/charts/k8s-reporter/values.yaml index fb4025d3..7bab12f2 100644 --- a/charts/k8s-reporter/values.yaml +++ b/charts/k8s-reporter/values.yaml @@ -8,7 +8,7 @@ image: # -- the kosli reporter image pull policy pullPolicy: IfNotPresent # -- the kosli reporter image tag, overrides the image tag whose default is the chart appVersion. - tag: "v2.10.11" + tag: "v2.10.13" # -- overrides the name used for the created k8s resources. If `fullnameOverride` is provided, it has higher precedence than this one nameOverride: "" diff --git a/cmd/kosli/attestArtifact_test.go b/cmd/kosli/attestArtifact_test.go index d537457b..b9ed1a0e 100644 --- a/cmd/kosli/attestArtifact_test.go +++ b/cmd/kosli/attestArtifact_test.go @@ -41,72 +41,72 @@ func (suite *AttestArtifactCommandTestSuite) TestAttestArtifactCmd() { { wantError: true, name: "fails when missing a required flag", - cmd: fmt.Sprintf("attest artifact foo --artifact-type file --name bar --commit HEAD --build-url example.com %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest artifact foo --artifact-type file --name bar --commit HEAD --build-url http://www.example.com %s", suite.defaultKosliArguments), golden: "Error: required flag(s) \"commit-url\" not set\n", }, { wantError: true, name: "fails when --fingerprint is invalid sha256 digest", - cmd: fmt.Sprintf("attest artifact foo --fingerprint xxxx --name bar --commit HEAD --build-url example.com --commit-url example.com %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest artifact foo --fingerprint xxxx --name bar --commit HEAD --build-url http://www.example.com --commit-url http://www.example.com %s", suite.defaultKosliArguments), golden: "Error: xxxx is not a valid SHA256 fingerprint. It should match the pattern ^([a-f0-9]{64})$\nUsage: kosli attest artifact {IMAGE-NAME | FILE-PATH | DIR-PATH} [flags]\n", }, { name: "works when --name does not match artifact name in the template (extra artifact)", - cmd: fmt.Sprintf("attest artifact testdata/file1 --artifact-type file --name bar --commit HEAD --build-url example.com --commit-url example.com %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest artifact testdata/file1 --artifact-type file --name bar --commit HEAD --build-url http://www.example.com --commit-url http://www.example.com %s", suite.defaultKosliArguments), golden: "artifact file1 was attested with fingerprint: 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9\n", }, { name: "can attest a file artifact", - cmd: fmt.Sprintf("attest artifact testdata/file1 --artifact-type file --name cli --commit HEAD --build-url example.com --commit-url example.com %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest artifact testdata/file1 --artifact-type file --name cli --commit HEAD --build-url http://www.example.com --commit-url http://www.example.com %s", suite.defaultKosliArguments), golden: "artifact file1 was attested with fingerprint: 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9\n", }, { name: "can attest an artifact with --fingerprint", - cmd: fmt.Sprintf("attest artifact testdata/file1 --fingerprint 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name cli --commit HEAD --build-url example.com --commit-url example.com %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest artifact testdata/file1 --fingerprint 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name cli --commit HEAD --build-url http://www.example.com --commit-url http://www.example.com %s", suite.defaultKosliArguments), golden: "artifact testdata/file1 was attested with fingerprint: 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9\n", }, { name: "can attest an artifact with external urls", - cmd: fmt.Sprintf("attest artifact testdata/file1 --fingerprint 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name cli --commit HEAD --build-url example.com --commit-url example.com --external-url jira=https://jira.kosli.com %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest artifact testdata/file1 --fingerprint 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name cli --commit HEAD --build-url http://www.example.com --commit-url http://www.example.com --external-url jira=https://jira.kosli.com %s", suite.defaultKosliArguments), golden: "artifact testdata/file1 was attested with fingerprint: 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9\n", }, { name: "can attest an artifact with external urls and fingerprints", - cmd: fmt.Sprintf("attest artifact testdata/file1 --fingerprint 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name cli --commit HEAD --build-url example.com --commit-url example.com --external-url file=https://kosli.com/file --external-fingerprint file=7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest artifact testdata/file1 --fingerprint 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name cli --commit HEAD --build-url http://www.example.com --commit-url http://www.example.com --external-url file=https://kosli.com/file --external-fingerprint file=7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 %s", suite.defaultKosliArguments), golden: "artifact testdata/file1 was attested with fingerprint: 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9\n", }, { wantError: true, name: "fails when --external-fingerprint has more items than external urls", - cmd: fmt.Sprintf("attest artifact testdata/file1 --fingerprint 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name cli --commit HEAD --build-url example.com --commit-url example.com --external-fingerprint file=7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest artifact testdata/file1 --fingerprint 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name cli --commit HEAD --build-url http://www.example.com --commit-url http://www.example.com --external-fingerprint file=7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 %s", suite.defaultKosliArguments), golden: "Error: --external-fingerprints have labels that don't have a URL in --external-url\n", }, { wantError: true, name: "fails (from server) when --external-fingerprint has invalid fingerprint", - cmd: fmt.Sprintf("attest artifact testdata/file1 --fingerprint 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name cli --commit HEAD --build-url example.com --commit-url example.com --external-url file=https://example.com --external-fingerprint file=7509e5bda0 %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest artifact testdata/file1 --fingerprint 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name cli --commit HEAD --build-url http://www.example.com --commit-url http://www.example.com --external-url file=https://http://www.example.com --external-fingerprint file=7509e5bda0 %s", suite.defaultKosliArguments), golden: "Error: Input payload validation failed: map[external_urls.file.fingerprint:'7509e5bda0' does not match '^[a-f0-9]{64}$']\n", }, { name: "can attest with annotations against a trail", - cmd: fmt.Sprintf("attest artifact testdata/file1 --fingerprint 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name cli --commit HEAD --build-url example.com --commit-url example.com --annotate foo=bar --annotate baz=\"data with spaces\" %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest artifact testdata/file1 --fingerprint 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name cli --commit HEAD --build-url http://www.example.com --commit-url http://www.example.com --annotate foo=bar --annotate baz=\"data with spaces\" %s", suite.defaultKosliArguments), golden: "artifact testdata/file1 was attested with fingerprint: 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9\n", }, { wantError: true, name: "fails when annotation is not valid", - cmd: fmt.Sprintf("attest artifact testdata/file1 --fingerprint 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name cli --commit HEAD --build-url example.com --commit-url example.com --annotate foo.baz=bar %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest artifact testdata/file1 --fingerprint 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name cli --commit HEAD --build-url http://www.example.com --commit-url http://www.example.com --annotate foo.baz=bar %s", suite.defaultKosliArguments), golden: "Error: --annotate flag should be in the format key=value. Invalid key: 'foo.baz'. Key can only contain [A-Za-z0-9_].\n", }, { name: "can attest a file artifact with redacted commit info", - cmd: fmt.Sprintf("attest artifact testdata/file1 --artifact-type file --redact-commit-info author,branch --name cli --commit HEAD --build-url example.com --commit-url example.com %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest artifact testdata/file1 --artifact-type file --redact-commit-info author,branch --name cli --commit HEAD --build-url http://www.example.com --commit-url http://www.example.com %s", suite.defaultKosliArguments), golden: "artifact file1 was attested with fingerprint: 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9\n", }, { wantError: true, name: "fails when attesting an artifact with invalid redacted commit info", - cmd: fmt.Sprintf("attest artifact testdata/file1 --artifact-type file --redact-commit-info author,bar --name cli --commit HEAD --build-url example.com --commit-url example.com %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest artifact testdata/file1 --artifact-type file --redact-commit-info author,bar --name cli --commit HEAD --build-url http://www.example.com --commit-url http://www.example.com %s", suite.defaultKosliArguments), golden: "Error: bar is not an allowed value for --redact-commit-info\n", }, } diff --git a/cmd/kosli/attestGeneric_test.go b/cmd/kosli/attestGeneric_test.go index 67d9f089..f326d339 100644 --- a/cmd/kosli/attestGeneric_test.go +++ b/cmd/kosli/attestGeneric_test.go @@ -80,25 +80,25 @@ func (suite *AttestGenericCommandTestSuite) TestAttestGenericCmd() { { wantError: true, name: "fails when both --fingerprint and --artifact-type", - cmd: fmt.Sprintf("attest generic testdata/file1 --fingerprint xxxx --artifact-type file --name bar --commit HEAD --origin-url example.com %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest generic testdata/file1 --fingerprint xxxx --artifact-type file --name bar --commit HEAD --origin-url http://www.example.com %s", suite.defaultKosliArguments), golden: "Error: only one of --fingerprint, --artifact-type is allowed\n", }, { wantError: true, name: "fails when --fingerprint is not valid", - cmd: fmt.Sprintf("attest generic --name foo --fingerprint xxxx --commit HEAD --origin-url example.com %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest generic --name foo --fingerprint xxxx --commit HEAD --origin-url http://www.example.com %s", suite.defaultKosliArguments), golden: "Error: xxxx is not a valid SHA256 fingerprint. It should match the pattern ^([a-f0-9]{64})$\nUsage: kosli attest generic [IMAGE-NAME | FILE-PATH | DIR-PATH] [flags]\n", }, { wantError: true, name: "attesting against an artifact that does not exist fails", - cmd: fmt.Sprintf("attest generic --fingerprint 1234e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name foo --commit HEAD --origin-url example.com %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest generic --fingerprint 1234e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name foo --commit HEAD --origin-url http://www.example.com %s", suite.defaultKosliArguments), golden: "Error: Artifact with fingerprint 1234e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 does not exist in trail \"test-123\" of flow \"attest-generic\" belonging to organization \"docs-cmd-test-user\"\n", }, { wantError: true, name: "fails when --name is passed as empty string", - cmd: fmt.Sprintf("attest generic --name \"\" --commit HEAD --origin-url example.com %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest generic --name \"\" --commit HEAD --origin-url http://www.example.com %s", suite.defaultKosliArguments), golden: "Error: flag '--name' is required, but empty string was provided\n", }, { @@ -108,32 +108,32 @@ func (suite *AttestGenericCommandTestSuite) TestAttestGenericCmd() { }, { name: "can attest generic against an artifact using artifact name and --artifact-type", - cmd: fmt.Sprintf("attest generic testdata/file1 --artifact-type file --name foo --commit HEAD --origin-url example.com %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest generic testdata/file1 --artifact-type file --name foo --commit HEAD --origin-url http://www.example.com %s", suite.defaultKosliArguments), golden: "generic attestation 'foo' is reported to trail: test-123\n", }, { name: "can attest generic against an artifact using artifact name and --artifact-type when --name does not exist in the trail template", - cmd: fmt.Sprintf("attest generic testdata/file1 --artifact-type file --name bar --commit HEAD --origin-url example.com %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest generic testdata/file1 --artifact-type file --name bar --commit HEAD --origin-url http://www.example.com %s", suite.defaultKosliArguments), golden: "generic attestation 'bar' is reported to trail: test-123\n", }, { name: "can attest generic against an artifact using --fingerprint and no artifact-name", - cmd: fmt.Sprintf("attest generic --fingerprint 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name foo --commit HEAD --origin-url example.com %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest generic --fingerprint 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name foo --commit HEAD --origin-url http://www.example.com %s", suite.defaultKosliArguments), golden: "generic attestation 'foo' is reported to trail: test-123\n", }, { name: "can attest generic against a trail", - cmd: fmt.Sprintf("attest generic --name bar --commit HEAD --origin-url example.com %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest generic --name bar --commit HEAD --origin-url http://www.example.com %s", suite.defaultKosliArguments), golden: "generic attestation 'bar' is reported to trail: test-123\n", }, { name: "can attest generic against a trail when name is not found in the trail template", - cmd: fmt.Sprintf("attest generic --name additional --commit HEAD --origin-url example.com %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest generic --name additional --commit HEAD --origin-url http://www.example.com %s", suite.defaultKosliArguments), golden: "generic attestation 'additional' is reported to trail: test-123\n", }, { name: "can attest generic against an artifact it is created using dot syntax in --name", - cmd: fmt.Sprintf("attest generic --name cli.foo --commit HEAD --origin-url example.com %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest generic --name cli.foo --commit HEAD --origin-url http://www.example.com %s", suite.defaultKosliArguments), golden: "generic attestation 'foo' is reported to trail: test-123\n", }, { diff --git a/cmd/kosli/attestJira_test.go b/cmd/kosli/attestJira_test.go index 1c789a35..9ba15f50 100644 --- a/cmd/kosli/attestJira_test.go +++ b/cmd/kosli/attestJira_test.go @@ -87,13 +87,13 @@ func (suite *AttestJiraCommandTestSuite) TestAttestJiraCmd() { { wantError: true, name: "fails when both --fingerprint and --artifact-type", - cmd: fmt.Sprintf("attest jira testdata/file1 --fingerprint xxxx --artifact-type file --name bar --commit HEAD --origin-url example.com %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest jira testdata/file1 --fingerprint xxxx --artifact-type file --name bar --commit HEAD --origin-url http://www.example.com %s", suite.defaultKosliArguments), golden: "Error: only one of --fingerprint, --artifact-type is allowed\n", }, { wantError: true, name: "fails when --fingerprint is not valid", - cmd: fmt.Sprintf("attest jira --name foo --fingerprint xxxx --commit HEAD --origin-url example.com --jira-username tore@kosli.com %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest jira --name foo --fingerprint xxxx --commit HEAD --origin-url http://www..com --jira-username tore@kosli.com %s", suite.defaultKosliArguments), golden: "Error: xxxx is not a valid SHA256 fingerprint. It should match the pattern ^([a-f0-9]{64})$\nUsage: kosli attest jira [IMAGE-NAME | FILE-PATH | DIR-PATH] [flags]\n", }, { diff --git a/cmd/kosli/attestJunit_test.go b/cmd/kosli/attestJunit_test.go index f20c3cec..1996d58a 100644 --- a/cmd/kosli/attestJunit_test.go +++ b/cmd/kosli/attestJunit_test.go @@ -50,54 +50,54 @@ func (suite *AttestJunitCommandTestSuite) TestAttestJunitCmd() { { wantError: true, name: "fails when both --fingerprint and --artifact-type", - cmd: fmt.Sprintf("attest junit testdata/file1 --fingerprint xxxx --artifact-type file --name bar --commit HEAD --origin-url example.com %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest junit testdata/file1 --fingerprint xxxx --artifact-type file --name bar --commit HEAD --origin-url %s", suite.defaultKosliArguments), golden: "Error: only one of --fingerprint, --artifact-type is allowed\n", }, { wantError: true, name: "fails when --fingerprint is not valid", - cmd: fmt.Sprintf("attest junit --name foo --fingerprint xxxx --commit HEAD --origin-url example.com %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest junit --name foo --fingerprint xxxx --commit HEAD --origin-url http://www.example.com %s", suite.defaultKosliArguments), golden: "Error: xxxx is not a valid SHA256 fingerprint. It should match the pattern ^([a-f0-9]{64})$\nUsage: kosli attest junit [IMAGE-NAME | FILE-PATH | DIR-PATH] [flags]\n", }, { wantError: true, name: "attesting against an artifact that does not exist fails", - cmd: fmt.Sprintf("attest junit --fingerprint 1234e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name foo --commit HEAD --origin-url example.com --results-dir testdata %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest junit --fingerprint 1234e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name foo --commit HEAD --origin-url http://www.example.com --results-dir testdata %s", suite.defaultKosliArguments), golden: "Error: Artifact with fingerprint 1234e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 does not exist in trail \"test-123\" of flow \"attest-junit\" belonging to organization \"docs-cmd-test-user\"\n", }, { name: "can attest junit against an artifact using artifact name and --artifact-type", - cmd: fmt.Sprintf("attest junit testdata/file1 --artifact-type file --name foo --commit HEAD --origin-url example.com --results-dir testdata %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest junit testdata/file1 --artifact-type file --name foo --commit HEAD --origin-url http://www.example.com --results-dir testdata %s", suite.defaultKosliArguments), golden: "junit attestation 'foo' is reported to trail: test-123\n", }, { name: "can attest junit against an artifact using artifact name and --artifact-type when --name does not exist in the trail template", - cmd: fmt.Sprintf("attest junit testdata/file1 --artifact-type file --name bar --commit HEAD --origin-url example.com --results-dir testdata %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest junit testdata/file1 --artifact-type file --name bar --commit HEAD --origin-url http://www.example.com --results-dir testdata %s", suite.defaultKosliArguments), golden: "junit attestation 'bar' is reported to trail: test-123\n", }, { name: "can attest junit against an artifact using --fingerprint", - cmd: fmt.Sprintf("attest junit --fingerprint 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name foo --commit HEAD --origin-url example.com --results-dir testdata %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest junit --fingerprint 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name foo --commit HEAD --origin-url http://www.example.com --results-dir testdata %s", suite.defaultKosliArguments), golden: "junit attestation 'foo' is reported to trail: test-123\n", }, { name: "can attest junit against a trail", - cmd: fmt.Sprintf("attest junit --name bar --commit HEAD --origin-url example.com --results-dir testdata %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest junit --name bar --commit HEAD --origin-url http://www.example.com --results-dir testdata %s", suite.defaultKosliArguments), golden: "junit attestation 'bar' is reported to trail: test-123\n", }, { name: "can attest junit against a trail when name is not found in the trail template", - cmd: fmt.Sprintf("attest junit --name additional --commit HEAD --origin-url example.com --results-dir testdata %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest junit --name additional --commit HEAD --origin-url http://www.example.com --results-dir testdata %s", suite.defaultKosliArguments), golden: "junit attestation 'additional' is reported to trail: test-123\n", }, { name: "can attest junit against an artifact it is created using dot syntax in --name", - cmd: fmt.Sprintf("attest junit --name cli.foo --commit HEAD --origin-url example.com --results-dir testdata %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest junit --name cli.foo --commit HEAD --origin-url http://www.example.com --results-dir testdata %s", suite.defaultKosliArguments), golden: "junit attestation 'foo' is reported to trail: test-123\n", }, { name: "can attest junit with external-url and external-fingerprint against a trail", - cmd: fmt.Sprintf(`attest junit --name bar --commit HEAD --origin-url example.com --results-dir testdata + cmd: fmt.Sprintf(`attest junit --name bar --commit HEAD --origin-url http://www.example.com --results-dir testdata --external-url file=https://foo.com/file --external-fingerprint file=7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 %s`, suite.defaultKosliArguments), golden: "junit attestation 'bar' is reported to trail: test-123\n", @@ -105,20 +105,20 @@ func (suite *AttestJunitCommandTestSuite) TestAttestJunitCmd() { { wantError: true, name: "fails when external-fingerprint has more items than external-url", - cmd: fmt.Sprintf(`attest junit --name bar --commit HEAD --origin-url example.com --results-dir testdata + cmd: fmt.Sprintf(`attest junit --name bar --commit HEAD --origin-url http://www.example.com --results-dir testdata --external-fingerprint file=7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 %s`, suite.defaultKosliArguments), golden: "Error: --external-fingerprints have labels that don't have a URL in --external-url\n", }, { name: "can attest with annotations against a trail", - cmd: fmt.Sprintf(`attest junit --name bar --commit HEAD --origin-url example.com --results-dir testdata + cmd: fmt.Sprintf(`attest junit --name bar --commit HEAD --origin-url http://www.example.com --results-dir testdata --annotate foo=bar --annotate baz=qux %s`, suite.defaultKosliArguments), golden: "junit attestation 'bar' is reported to trail: test-123\n", }, { wantError: true, name: "fails when annotation is not valid", - cmd: fmt.Sprintf(`attest junit --name bar --commit HEAD --origin-url example.com --results-dir testdata + cmd: fmt.Sprintf(`attest junit --name bar --commit HEAD --origin-url http://www.example.com --results-dir testdata --annotate foo.bar=bar %s`, suite.defaultKosliArguments), golden: "Error: --annotate flag should be in the format key=value. Invalid key: 'foo.bar'. Key can only contain [A-Za-z0-9_].\n", }, diff --git a/cmd/kosli/attestSnyk_test.go b/cmd/kosli/attestSnyk_test.go index c0b1ea50..ca79e1cf 100644 --- a/cmd/kosli/attestSnyk_test.go +++ b/cmd/kosli/attestSnyk_test.go @@ -50,68 +50,68 @@ func (suite *AttestSnykCommandTestSuite) TestAttestSnykCmd() { { wantError: true, name: "fails when both --fingerprint and --artifact-type", - cmd: fmt.Sprintf("attest snyk testdata/file1 --fingerprint xxxx --artifact-type file --name bar --commit HEAD --origin-url example.com %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest snyk testdata/file1 --fingerprint xxxx --artifact-type file --name bar --commit HEAD --origin-url http://www.example.com %s", suite.defaultKosliArguments), golden: "Error: only one of --fingerprint, --artifact-type is allowed\n", }, { wantError: true, name: "fails when --fingerprint is not valid", - cmd: fmt.Sprintf("attest snyk --name foo --fingerprint xxxx --commit HEAD --origin-url example.com %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest snyk --name foo --fingerprint xxxx --commit HEAD --origin-url http://www.example.com %s", suite.defaultKosliArguments), golden: "Error: xxxx is not a valid SHA256 fingerprint. It should match the pattern ^([a-f0-9]{64})$\nUsage: kosli attest snyk [IMAGE-NAME | FILE-PATH | DIR-PATH] [flags]\n", }, { wantError: true, name: "attesting against an artifact that does not exist fails", - cmd: fmt.Sprintf("attest snyk --fingerprint 1234e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name foo --commit HEAD --origin-url example.com --scan-results testdata/snyk_sarif.json %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest snyk --fingerprint 1234e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name foo --commit HEAD --origin-url http://www.example.com --scan-results testdata/snyk_sarif.json %s", suite.defaultKosliArguments), golden: "Error: Artifact with fingerprint 1234e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 does not exist in trail \"test-123\" of flow \"attest-snyk\" belonging to organization \"docs-cmd-test-user\"\n", }, { wantError: true, name: "fails when --snyk-results is missing", - cmd: fmt.Sprintf("attest snyk testdata/file1 --artifact-type file --name foo --commit HEAD --origin-url example.com %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest snyk testdata/file1 --artifact-type file --name foo --commit HEAD --origin-url http://www.example.com %s", suite.defaultKosliArguments), golden: "Error: required flag(s) \"scan-results\" not set\n", }, { name: "can attest snyk against an artifact using artifact name and --artifact-type", - cmd: fmt.Sprintf("attest snyk testdata/file1 --artifact-type file --name foo --commit HEAD --origin-url example.com --scan-results testdata/snyk_sarif.json %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest snyk testdata/file1 --artifact-type file --name foo --commit HEAD --origin-url http://www.example.com --scan-results testdata/snyk_sarif.json %s", suite.defaultKosliArguments), golden: "snyk attestation 'foo' is reported to trail: test-123\n", }, { name: "can attest snyk against an artifact using artifact name and --artifact-type when --name does not exist in the trail template", - cmd: fmt.Sprintf("attest snyk testdata/file1 --artifact-type file --name bar --commit HEAD --origin-url example.com --scan-results testdata/snyk_sarif.json %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest snyk testdata/file1 --artifact-type file --name bar --commit HEAD --origin-url http://www.example.com --scan-results testdata/snyk_sarif.json %s", suite.defaultKosliArguments), golden: "snyk attestation 'bar' is reported to trail: test-123\n", }, { name: "can attest snyk against an artifact using --fingerprint", - cmd: fmt.Sprintf("attest snyk --fingerprint 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name foo --commit HEAD --origin-url example.com --scan-results testdata/snyk_sarif.json %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest snyk --fingerprint 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name foo --commit HEAD --origin-url http://www.example.com --scan-results testdata/snyk_sarif.json %s", suite.defaultKosliArguments), golden: "snyk attestation 'foo' is reported to trail: test-123\n", }, { name: "can attest snyk against a trail", - cmd: fmt.Sprintf("attest snyk --name bar --commit HEAD --origin-url example.com --scan-results testdata/snyk_sarif.json %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest snyk --name bar --commit HEAD --origin-url http://www.example.com --scan-results testdata/snyk_sarif.json %s", suite.defaultKosliArguments), golden: "snyk attestation 'bar' is reported to trail: test-123\n", }, { name: "can attest snyk against a trail when name is not found in the trail template", - cmd: fmt.Sprintf("attest snyk --name additional --commit HEAD --origin-url example.com --scan-results testdata/snyk_sarif.json %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest snyk --name additional --commit HEAD --origin-url http://www.example.com --scan-results testdata/snyk_sarif.json %s", suite.defaultKosliArguments), golden: "snyk attestation 'additional' is reported to trail: test-123\n", }, { name: "can attest snyk against an artifact it is created using dot syntax in --name", - cmd: fmt.Sprintf("attest snyk --name cli.foo --commit HEAD --origin-url example.com --scan-results testdata/snyk_sarif.json %s", suite.defaultKosliArguments), + cmd: fmt.Sprintf("attest snyk --name cli.foo --commit HEAD --origin-url http://www.example.com --scan-results testdata/snyk_sarif.json %s", suite.defaultKosliArguments), golden: "snyk attestation 'foo' is reported to trail: test-123\n", }, { name: "can attest snyk against with external-url and external-fingerprint a trail", - cmd: fmt.Sprintf(`attest snyk --name bar --commit HEAD --origin-url example.com - --external-url file=https://example.com/file --external-url other=https://other.com + cmd: fmt.Sprintf(`attest snyk --name bar --commit HEAD --origin-url http://www.example.com + --external-url file=https://http://www.example.com/file --external-url other=https://other.com --external-fingerprint file=7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --scan-results testdata/snyk_sarif.json %s`, suite.defaultKosliArguments), golden: "snyk attestation 'bar' is reported to trail: test-123\n", }, { name: "can attest with annotations against a trail", - cmd: fmt.Sprintf(`attest snyk --name bar --commit HEAD --origin-url example.com + cmd: fmt.Sprintf(`attest snyk --name bar --commit HEAD --origin-url http://www.example.com --annotate foo=bar --annotate baz=qux --scan-results testdata/snyk_sarif.json %s`, suite.defaultKosliArguments), golden: "snyk attestation 'bar' is reported to trail: test-123\n", @@ -119,7 +119,7 @@ func (suite *AttestSnykCommandTestSuite) TestAttestSnykCmd() { { wantError: true, name: "fails when annotation is not valid", - cmd: fmt.Sprintf(`attest snyk --name bar --commit HEAD --origin-url example.com + cmd: fmt.Sprintf(`attest snyk --name bar --commit HEAD --origin-url http://www.example.com --annotate foo.baz=bar --scan-results testdata/snyk_sarif.json %s`, suite.defaultKosliArguments), golden: "Error: --annotate flag should be in the format key=value. Invalid key: 'foo.baz'. Key can only contain [A-Za-z0-9_].\n", diff --git a/cmd/kosli/cli_utils.go b/cmd/kosli/cli_utils.go index 1fdd58ef..dd35ce76 100644 --- a/cmd/kosli/cli_utils.go +++ b/cmd/kosli/cli_utils.go @@ -493,7 +493,7 @@ func ValidateArtifactArg(args []string, artifactType, inputSha256 string, always if argsWithLeadingSpace { errMsg = append(errMsg, "Arguments with a leading space are probably caused by a lone backslash that has a space after it.") } - return fmt.Errorf(strings.Join(errMsg, "\n")) + return fmt.Errorf("%s", strings.Join(errMsg, "\n")) } if len(args) == 0 || args[0] == "" { diff --git a/cmd/kosli/expectDeployment_test.go b/cmd/kosli/expectDeployment_test.go index cd6e7b13..ab6d93b4 100644 --- a/cmd/kosli/expectDeployment_test.go +++ b/cmd/kosli/expectDeployment_test.go @@ -48,19 +48,19 @@ func (suite *ExpectDeploymentCommandTestSuite) TestExpectDeploymentCmd() { tests := []cmdTestCase{ { name: "expect deployment works (with --fingerprint)", - cmd: fmt.Sprintf(`expect deployment --flow %s --fingerprint %s --environment %s --build-url example.com %s`, + cmd: fmt.Sprintf(`expect deployment --flow %s --fingerprint %s --environment %s --build-url http://www.example.com %s`, suite.flowName, suite.fingerprint, suite.envName, suite.defaultKosliArguments), golden: fmt.Sprintf("Command \"deployment\" is deprecated, deployment expectation is no longer required for compliance.\nexpect deployment of artifact %s was reported to: expect-deploy-env\n", suite.fingerprint), }, { name: "expect deployment works (with --artifact-type)", - cmd: fmt.Sprintf(`expect deployment %s --artifact-type file --flow %s --fingerprint %s --environment %s --build-url example.com %s`, + cmd: fmt.Sprintf(`expect deployment %s --artifact-type file --flow %s --fingerprint %s --environment %s --build-url http://www.example.com %s`, suite.artifactPath, suite.flowName, suite.fingerprint, suite.envName, suite.defaultKosliArguments), golden: fmt.Sprintf("Command \"deployment\" is deprecated, deployment expectation is no longer required for compliance.\nexpect deployment of artifact %s was reported to: expect-deploy-env\n", suite.fingerprint), }, { name: "expect deployment works with --user-data", - cmd: fmt.Sprintf(`expect deployment --flow %s --fingerprint %s --environment %s --build-url example.com + cmd: fmt.Sprintf(`expect deployment --flow %s --fingerprint %s --environment %s --build-url http://www.example.com --user-data testdata/snyk_scan_example.json %s`, suite.flowName, suite.fingerprint, suite.envName, suite.defaultKosliArguments), golden: fmt.Sprintf("Command \"deployment\" is deprecated, deployment expectation is no longer required for compliance.\nexpect deployment of artifact %s was reported to: expect-deploy-env\n", suite.fingerprint), @@ -68,7 +68,7 @@ func (suite *ExpectDeploymentCommandTestSuite) TestExpectDeploymentCmd() { { wantError: true, name: "missing --org flag causes an error", - cmd: fmt.Sprintf(`expect deployment --flow %s --fingerprint %s --environment %s --build-url example.com + cmd: fmt.Sprintf(`expect deployment --flow %s --fingerprint %s --environment %s --build-url http://www.example.com --api-token secret`, suite.flowName, suite.fingerprint, suite.envName), golden: "Command \"deployment\" is deprecated, deployment expectation is no longer required for compliance.\nError: --org is not set\nUsage: kosli expect deployment [IMAGE-NAME | FILE-PATH | DIR-PATH] [flags]\n", @@ -76,7 +76,7 @@ func (suite *ExpectDeploymentCommandTestSuite) TestExpectDeploymentCmd() { { wantError: true, name: "missing --api-token flag causes an error", - cmd: fmt.Sprintf(`expect deployment --flow %s --fingerprint %s --environment %s --build-url example.com + cmd: fmt.Sprintf(`expect deployment --flow %s --fingerprint %s --environment %s --build-url http://www.example.com --org orgX`, suite.flowName, suite.fingerprint, suite.envName), golden: "Command \"deployment\" is deprecated, deployment expectation is no longer required for compliance.\nError: --api-token is not set\nUsage: kosli expect deployment [IMAGE-NAME | FILE-PATH | DIR-PATH] [flags]\n", @@ -84,7 +84,7 @@ func (suite *ExpectDeploymentCommandTestSuite) TestExpectDeploymentCmd() { { wantError: true, name: "expect deployment fails when --user-data is a non-existing file", - cmd: fmt.Sprintf(`expect deployment --flow %s --fingerprint %s --environment %s --build-url example.com + cmd: fmt.Sprintf(`expect deployment --flow %s --fingerprint %s --environment %s --build-url http://www.example.com --user-data non-existing.json %s`, suite.flowName, suite.fingerprint, suite.envName, suite.defaultKosliArguments), golden: "Command \"deployment\" is deprecated, deployment expectation is no longer required for compliance.\nError: open non-existing.json: no such file or directory\n", @@ -92,14 +92,14 @@ func (suite *ExpectDeploymentCommandTestSuite) TestExpectDeploymentCmd() { { wantError: true, name: "expect deployment fails if --flow is missing", - cmd: fmt.Sprintf(`expect deployment --fingerprint %s --environment %s --build-url example.com %s`, + cmd: fmt.Sprintf(`expect deployment --fingerprint %s --environment %s --build-url http://www.example.com %s`, suite.fingerprint, suite.envName, suite.defaultKosliArguments), golden: "Command \"deployment\" is deprecated, deployment expectation is no longer required for compliance.\nError: required flag(s) \"flow\" not set\n", }, { wantError: true, name: "expect deployment fails if --environment is missing", - cmd: fmt.Sprintf(`expect deployment --flow %s --fingerprint %s --build-url example.com %s`, + cmd: fmt.Sprintf(`expect deployment --flow %s --fingerprint %s --build-url http://www.example.com %s`, suite.flowName, suite.fingerprint, suite.defaultKosliArguments), golden: "Command \"deployment\" is deprecated, deployment expectation is no longer required for compliance.\nError: required flag(s) \"environment\" not set\n", }, diff --git a/cmd/kosli/reportEvidenceArtifactGeneric_test.go b/cmd/kosli/reportEvidenceArtifactGeneric_test.go index d255cfab..084c2cd3 100644 --- a/cmd/kosli/reportEvidenceArtifactGeneric_test.go +++ b/cmd/kosli/reportEvidenceArtifactGeneric_test.go @@ -56,22 +56,22 @@ func (suite *ArtifactEvidenceGenericCommandTestSuite) TestArtifactEvidenceGeneri { name: "report Generic test evidence works without --evidence-paths", cmd: fmt.Sprintf(`report evidence artifact generic --fingerprint %s --name %s --flow %s - --build-url example.com --compliant --description "some description" %s`, + --build-url http://www.example.com --compliant --description "some description" %s`, suite.artifactFingerprint, evidenceName, suite.flowName, suite.defaultKosliArguments), goldenRegex: fmt.Sprintf("generic evidence '%s' is reported to artifact: %s\n", evidenceName, suite.artifactFingerprint), }, { name: "report Generic test evidence works when --evidence-url and --evidence-fingerprint are provided", cmd: fmt.Sprintf(`report evidence artifact generic --fingerprint %s --name %s --flow %s - --build-url example.com --compliant --description "some description" - --evidence-url https://example.com --evidence-fingerprint %s %s`, + --build-url http://www.example.com --compliant --description "some description" + --evidence-url https://http://www.example.com --evidence-fingerprint %s %s`, suite.artifactFingerprint, evidenceName, suite.flowName, suite.artifactFingerprint, suite.defaultKosliArguments), goldenRegex: fmt.Sprintf("generic evidence '%s' is reported to artifact: %s\n", evidenceName, suite.artifactFingerprint), }, { name: "report Generic test evidence works with --evidence-paths that contains a single file", cmd: fmt.Sprintf(`report evidence artifact generic --fingerprint %s --name %s --flow %s - --build-url example.com --compliant --description "some description" + --build-url http://www.example.com --compliant --description "some description" --evidence-paths testdata/file1 %s`, suite.artifactFingerprint, evidenceName, suite.flowName, suite.defaultKosliArguments), goldenRegex: fmt.Sprintf("generic evidence '%s' is reported to artifact: %s\n", evidenceName, suite.artifactFingerprint), @@ -79,7 +79,7 @@ func (suite *ArtifactEvidenceGenericCommandTestSuite) TestArtifactEvidenceGeneri { name: "report Generic test evidence works with --evidence-paths that contains a single dir", cmd: fmt.Sprintf(`report evidence artifact generic --fingerprint %s --name %s --flow %s - --build-url example.com --compliant --description "some description" + --build-url http://www.example.com --compliant --description "some description" --evidence-paths testdata/folder1 %s`, suite.artifactFingerprint, evidenceName, suite.flowName, suite.defaultKosliArguments), goldenRegex: fmt.Sprintf("generic evidence '%s' is reported to artifact: %s\n", evidenceName, suite.artifactFingerprint), @@ -87,7 +87,7 @@ func (suite *ArtifactEvidenceGenericCommandTestSuite) TestArtifactEvidenceGeneri { name: "report Generic test evidence works with --evidence-paths that contains multiple paths", cmd: fmt.Sprintf(`report evidence artifact generic --fingerprint %s --name %s --flow %s - --build-url example.com --compliant --description "some description" + --build-url http://www.example.com --compliant --description "some description" --evidence-paths testdata/file1,testdata/folder1 %s`, suite.artifactFingerprint, evidenceName, suite.flowName, suite.defaultKosliArguments), goldenRegex: fmt.Sprintf("generic evidence '%s' is reported to artifact: %s\n", evidenceName, suite.artifactFingerprint), @@ -95,7 +95,7 @@ func (suite *ArtifactEvidenceGenericCommandTestSuite) TestArtifactEvidenceGeneri { name: "report Generic test evidence works when multiple --evidence-paths include duplicates", cmd: fmt.Sprintf(`report evidence artifact generic --fingerprint %s --name %s --flow %s - --build-url example.com --compliant --description "some description" + --build-url http://www.example.com --compliant --description "some description" --evidence-paths testdata/file1,testdata/folder1,testdata/file1 %s`, suite.artifactFingerprint, evidenceName, suite.flowName, suite.defaultKosliArguments), goldenRegex: fmt.Sprintf("generic evidence '%s' is reported to artifact: %s\n", evidenceName, suite.artifactFingerprint), @@ -103,14 +103,14 @@ func (suite *ArtifactEvidenceGenericCommandTestSuite) TestArtifactEvidenceGeneri { name: "report Generic test evidence works when neither of --description nor --user-data provided", cmd: fmt.Sprintf(`report evidence artifact generic --fingerprint %s --name %s --flow %s - --build-url example.com --compliant %s`, + --build-url http://www.example.com --compliant %s`, suite.artifactFingerprint, evidenceName, suite.flowName, suite.defaultKosliArguments), goldenRegex: fmt.Sprintf("generic evidence '%s' is reported to artifact: %s\n", evidenceName, suite.artifactFingerprint), }, { name: "report Generic test evidence works when neither of --description, --user-data or --compliant is provided", cmd: fmt.Sprintf(`report evidence artifact generic --fingerprint %s --name %s --flow %s - --build-url example.com %s`, + --build-url http://www.example.com %s`, suite.artifactFingerprint, evidenceName, suite.flowName, suite.defaultKosliArguments), goldenRegex: fmt.Sprintf("generic evidence '%s' is reported to artifact: %s\n", evidenceName, suite.artifactFingerprint), }, @@ -118,7 +118,7 @@ func (suite *ArtifactEvidenceGenericCommandTestSuite) TestArtifactEvidenceGeneri wantError: true, name: "report Generic test evidence fails when providing --evidence-paths that does not exist", cmd: fmt.Sprintf(`report evidence artifact generic --fingerprint %s --name %s --flow %s - --build-url example.com --compliant --description "some description" + --build-url http://www.example.com --compliant --description "some description" --evidence-paths non-existing %s`, suite.artifactFingerprint, evidenceName, suite.flowName, suite.defaultKosliArguments), goldenRegex: "Error: stat non-existing: no such file or directory\n", @@ -126,7 +126,7 @@ func (suite *ArtifactEvidenceGenericCommandTestSuite) TestArtifactEvidenceGeneri { name: "report Generic test evidence fails if --name is missing", cmd: fmt.Sprintf(`report evidence artifact generic --fingerprint %s --flow %s - --build-url example.com %s`, + --build-url http://www.example.com %s`, suite.artifactFingerprint, suite.flowName, suite.defaultKosliArguments), wantError: true, goldenRegex: "Error: required flag\\(s\\) \"name\" not set\n", @@ -134,14 +134,14 @@ func (suite *ArtifactEvidenceGenericCommandTestSuite) TestArtifactEvidenceGeneri { name: "report Generic test evidence fails if --fingerprint and --artifact-type are missing ", cmd: fmt.Sprintf(`report evidence artifact generic --name %s --flow %s - --build-url example.com %s`, + --build-url http://www.example.com %s`, evidenceName, suite.flowName, suite.defaultKosliArguments), wantError: true, }, { name: "report Generic test evidence works when --artifact-type is provided", cmd: fmt.Sprintf(`report evidence artifact generic testdata --artifact-type dir --name %s --flow %s - --build-url example.com %s`, + --build-url http://www.example.com %s`, evidenceName, suite.flowName, suite.defaultKosliArguments), }, } diff --git a/cmd/kosli/reportEvidenceArtifactJUnit_test.go b/cmd/kosli/reportEvidenceArtifactJUnit_test.go index ecf5f0be..e80c0707 100644 --- a/cmd/kosli/reportEvidenceArtifactJUnit_test.go +++ b/cmd/kosli/reportEvidenceArtifactJUnit_test.go @@ -36,13 +36,13 @@ func (suite *ArtifactEvidenceJUnitCommandTestSuite) TestArtifactEvidenceJUnitCom { name: "report JUnit test evidence works (using --fingerprint)", cmd: `report evidence artifact junit --fingerprint ` + suite.artifactFingerprint + ` --name junit-result --flow ` + suite.flowName + ` - --build-url example.com --results-dir testdata` + suite.defaultKosliArguments, + --build-url http://www.example.com --results-dir testdata` + suite.defaultKosliArguments, goldenRegex: "junit test evidence is reported to artifact: " + suite.artifactFingerprint + "\n", }, { name: "report JUnit test evidence works when --evidence-url and --evidence-fingerprint are provided", cmd: `report evidence artifact junit --fingerprint ` + suite.artifactFingerprint + ` --name junit-result --flow ` + suite.flowName + ` - --build-url example.com --results-dir testdata + --build-url http://www.example.com --results-dir testdata --evidence-url https://example.com --evidence-fingerprint ` + suite.artifactFingerprint + suite.defaultKosliArguments, goldenRegex: "junit test evidence is reported to artifact: " + suite.artifactFingerprint + "\n", }, @@ -50,39 +50,39 @@ func (suite *ArtifactEvidenceJUnitCommandTestSuite) TestArtifactEvidenceJUnitCom name: "report JUnit test evidence with maven-surefire XML that lacks a timestamp on the ", cmd: `report evidence artifact junit --fingerprint ` + suite.artifactFingerprint + ` --name junit-result --flow ` + suite.flowName + - ` --build-url example.com --results-dir testdata/junit` + suite.defaultKosliArguments, + ` --build-url http://www.example.com --results-dir testdata/junit` + suite.defaultKosliArguments, goldenRegex: "junit test evidence is reported to artifact: " + suite.artifactFingerprint + "\n", }, { name: "report JUnit test evidence works (using --artifact-type)", cmd: `report evidence artifact junit testdata/file1 --artifact-type file --name junit-result --flow ` + suite.flowName + ` - --build-url example.com --results-dir testdata` + suite.defaultKosliArguments, + --build-url http://www.example.com --results-dir testdata` + suite.defaultKosliArguments, goldenRegex: "junit test evidence is reported to artifact: " + suite.artifactFingerprint + "\n", }, { name: "report JUnit test evidence with non-existing results dir", cmd: `report evidence artifact junit --fingerprint ` + suite.artifactFingerprint + ` --name junit-result --flow ` + suite.flowName + ` - --build-url example.com --results-dir foo` + suite.defaultKosliArguments, + --build-url http://www.example.com --results-dir foo` + suite.defaultKosliArguments, wantError: true, }, { name: "report JUnit test evidence with a results dir that does not contain any results", cmd: `report evidence artifact junit --fingerprint ` + suite.artifactFingerprint + ` --name junit-result --flow ` + suite.flowName + ` - --build-url example.com --results-dir testdata/folder1` + suite.defaultKosliArguments, + --build-url http://www.example.com --results-dir testdata/folder1` + suite.defaultKosliArguments, wantError: true, goldenRegex: "Error: no tests found in testdata/folder1 directory\n", }, { name: "report JUnit test evidence with missing name flag", cmd: `report evidence artifact junit --fingerprint ` + suite.artifactFingerprint + ` --flow ` + suite.flowName + ` - --build-url example.com --results-dir testdata` + suite.defaultKosliArguments, + --build-url http://www.example.com --results-dir testdata` + suite.defaultKosliArguments, wantError: true, goldenRegex: "Error: required flag\\(s\\) \"name\" not set\n", }, { name: "report JUnit test evidence with a missing flow", cmd: `report evidence artifact junit --fingerprint ` + suite.artifactFingerprint + ` --name junit-result - --build-url example.com --results-dir testdata` + suite.defaultKosliArguments, + --build-url http://www.example.com --results-dir testdata` + suite.defaultKosliArguments, wantError: true, goldenRegex: "Error: required flag\\(s\\) \"flow\" not set\n", }, diff --git a/cmd/kosli/reportEvidenceArtifactPRAzure_test.go b/cmd/kosli/reportEvidenceArtifactPRAzure_test.go index 60ff768d..c1f3aac9 100644 --- a/cmd/kosli/reportEvidenceArtifactPRAzure_test.go +++ b/cmd/kosli/reportEvidenceArtifactPRAzure_test.go @@ -39,14 +39,14 @@ func (suite *ArtifactEvidencePRAzureCommandTestSuite) TestArtifactEvidencePRAzur { name: "report Azure PR evidence works with new flags (fingerprint, name ...)", cmd: `report evidence artifact pullrequest azure --fingerprint ` + suite.artifactFingerprint + ` --name az-pr --flow ` + suite.flowName + ` - --build-url example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, + --build-url http://www.example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, goldenRegex: "found 1 pull request\\(s\\) for commit: .*\nazure pull request evidence is reported to artifact: .*\n", }, { wantError: true, name: "report Azure PR evidence fails when --org is missing", cmd: `report evidence artifact pullrequest azure --fingerprint ` + suite.artifactFingerprint + ` --name az-pr --flow ` + suite.flowName + ` - --build-url example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a --api-token foo --host bar`, + --build-url http://www.example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a --api-token foo --host bar`, goldenRegex: "Error: --org is not set\n" + "Usage: kosli report evidence artifact pullrequest azure \\[IMAGE-NAME | FILE-PATH | DIR-PATH\\] \\[flags\\]\n", }, @@ -54,56 +54,56 @@ func (suite *ArtifactEvidencePRAzureCommandTestSuite) TestArtifactEvidencePRAzur wantError: true, name: "report Azure PR evidence fails when --name is missing", cmd: `report evidence artifact pullrequest azure --fingerprint ` + suite.artifactFingerprint + ` --flow ` + suite.flowName + ` - --build-url example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, + --build-url http://www.example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"name\" not set\n", }, { wantError: true, name: "report Azure PR evidence fails when --azure-org-url is missing", cmd: `report evidence artifact pullrequest azure --fingerprint ` + suite.artifactFingerprint + ` --name az-pr --flow ` + suite.flowName + ` - --build-url example.com --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, + --build-url http://www.example.com --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"azure-org-url\" not set\n", }, { wantError: true, name: "report Azure PR evidence fails when --project is missing", cmd: `report evidence artifact pullrequest azure --fingerprint ` + suite.artifactFingerprint + ` --name az-pr --flow ` + suite.flowName + ` - --build-url example.com --azure-org-url https://dev.azure.com/kosli --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, + --build-url http://www.example.com --azure-org-url https://dev.azure.com/kosli --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"project\" not set\n", }, { wantError: true, name: "report Azure PR evidence fails when --repository is missing", cmd: `report evidence artifact pullrequest azure --fingerprint ` + suite.artifactFingerprint + ` --name az-pr --flow ` + suite.flowName + ` - --build-url example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, + --build-url http://www.example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"repository\" not set\n", }, { wantError: true, name: "report Azure PR evidence fails when --commit is missing", cmd: `report evidence artifact pullrequest azure --fingerprint ` + suite.artifactFingerprint + ` --name az-pr --flow ` + suite.flowName + ` - --build-url example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli` + suite.defaultKosliArguments, + --build-url http://www.example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"commit\" not set\n", }, { wantError: true, name: "report Azure PR evidence fails when neither --fingerprint nor --artifact-type are set", cmd: `report evidence artifact pullrequest azure artifactNameArg --name az-pr --flow ` + suite.flowName + ` - --build-url example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, + --build-url http://www.example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, goldenRegex: "Error: either --artifact-type or --fingerprint must be specified\n" + "Usage: kosli report evidence artifact pullrequest azure \\[IMAGE-NAME | FILE-PATH | DIR-PATH\\] \\[flags\\]\n", }, { name: "report Azure PR evidence does not fail when commit does not exist, empty evidence is reported instead.", cmd: `report evidence artifact pullrequest azure --fingerprint ` + suite.artifactFingerprint + ` --name az-pr --flow ` + suite.flowName + ` - --build-url example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, + --build-url http://www.example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, goldenRegex: "found 1 pull request\\(s\\) for commit: .*\nazure pull request evidence is reported to artifact: .*\n", }, { name: "report Azure PR evidence works when --assert is used and commit has a PR", cmd: `report evidence artifact pullrequest azure --fingerprint ` + suite.artifactFingerprint + ` --name az-pr --flow ` + suite.flowName + ` --assert - --build-url example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, + --build-url http://www.example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, goldenRegex: "found 1 pull request\\(s\\) for commit: .*\nazure pull request evidence is reported to artifact: .*\n", }, { @@ -111,27 +111,27 @@ func (suite *ArtifactEvidencePRAzureCommandTestSuite) TestArtifactEvidencePRAzur name: "report Azure PR evidence fails when --assert is used and commit has no PRs", cmd: `report evidence artifact pullrequest azure --fingerprint ` + suite.artifactFingerprint + ` --name az-pr --flow ` + suite.flowName + ` --assert - --build-url example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 9bca2c44eaf221a79fb18a1a11bdf2997adaf870` + suite.defaultKosliArguments, + --build-url http://www.example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 9bca2c44eaf221a79fb18a1a11bdf2997adaf870` + suite.defaultKosliArguments, goldenRegex: "found 0 pull request\\(s\\) for commit: .*\nazure pull request evidence is reported to artifact: .*\nError: assert failed: no pull request found for the given commit: .*\n", }, { name: "report Azure PR evidence does not fail when commit has no PRs", cmd: `report evidence artifact pullrequest azure --fingerprint ` + suite.artifactFingerprint + ` --name az-pr --flow ` + suite.flowName + ` - --build-url example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 9bca2c44eaf221a79fb18a1a11bdf2997adaf870` + suite.defaultKosliArguments, + --build-url http://www.example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 9bca2c44eaf221a79fb18a1a11bdf2997adaf870` + suite.defaultKosliArguments, goldenRegex: "found 0 pull request\\(s\\) for commit: .*\nazure pull request evidence is reported to artifact: .*\n", }, { wantError: true, name: "report Azure PR evidence fails when the artifact does not exist in the server", cmd: `report evidence artifact pullrequest azure testdata/file1 --artifact-type file --name az-pr --flow ` + suite.flowName + ` - --build-url example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, + --build-url http://www.example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, goldenRegex: "found 1 pull request\\(s\\) for commit: .*\nError: Artifact with fingerprint '7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9' does not exist in flow 'azure-pr' belonging to organization 'docs-cmd-test-user'. \n", }, { wantError: true, name: "report Azure PR evidence fails when --artifact-type is unsupported", cmd: `report evidence artifact pullrequest azure testdata/file1 --artifact-type unsupported --name az-pr --flow ` + suite.flowName + ` - --build-url example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, + --build-url http://www.example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, goldenRegex: "Error: unsupported is not a supported artifact type\n", }, { @@ -139,7 +139,7 @@ func (suite *ArtifactEvidencePRAzureCommandTestSuite) TestArtifactEvidencePRAzur name: "report Azure PR evidence fails when --user-data is not found", cmd: `report evidence artifact pullrequest azure --fingerprint ` + suite.artifactFingerprint + ` --name az-pr --flow ` + suite.flowName + ` --user-data non-existing.json - --build-url example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, + --build-url http://www.example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, goldenRegex: "Error: open non-existing.json: no such file or directory\n", }, } diff --git a/cmd/kosli/reportEvidenceArtifactPRBitbucket_test.go b/cmd/kosli/reportEvidenceArtifactPRBitbucket_test.go index 02d3022b..c51dc8ee 100644 --- a/cmd/kosli/reportEvidenceArtifactPRBitbucket_test.go +++ b/cmd/kosli/reportEvidenceArtifactPRBitbucket_test.go @@ -39,14 +39,14 @@ func (suite *ArtifactEvidencePRBitbucketCommandTestSuite) TestArtifactEvidencePR { name: "report Bitbucket PR evidence works with new flags (fingerprint, name ...)", cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + ` - --build-url example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, goldenRegex: "found 1 pull request\\(s\\) for commit: .*\nbitbucket pull request evidence is reported to artifact: .*", }, { wantError: true, name: "report Bitbucket PR evidence fails when --org is missing", cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + ` - --build-url example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69 --api-token foo --host bar`, + --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69 --api-token foo --host bar`, goldenRegex: "Error: --org is not set\n" + "Usage: kosli report evidence artifact pullrequest bitbucket \\[IMAGE-NAME | FILE-PATH | DIR-PATH\\] \\[flags\\]\n", }, @@ -54,35 +54,35 @@ func (suite *ArtifactEvidencePRBitbucketCommandTestSuite) TestArtifactEvidencePR wantError: true, name: "report Bitbucket PR evidence fails when --name is missing", cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --flow ` + suite.flowName + ` - --build-url example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"name\" not set\n", }, { wantError: true, name: "report Bitbucket PR evidence fails when --bitbucket-username is missing", cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + ` - --build-url example.com --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"bitbucket-username\" not set\n", }, { wantError: true, name: "report Bitbucket PR evidence fails when --repository is missing", cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + ` - --build-url example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"repository\" not set\n", }, { wantError: true, name: "report Bitbucket PR evidence fails when --commit is missing", cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + ` - --build-url example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"commit\" not set\n", }, { wantError: true, name: "report Bitbucket PR evidence fails when neither --fingerprint nor --artifact-type are set", cmd: `report evidence artifact pullrequest bitbucket artifactNameArg --name bb-pr --flow ` + suite.flowName + ` - --build-url example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, goldenRegex: "Error: either --artifact-type or --fingerprint must be specified\n" + "Usage: kosli report evidence artifact pullrequest bitbucket \\[IMAGE-NAME | FILE-PATH | DIR-PATH\\] \\[flags\\]\n", }, @@ -90,14 +90,14 @@ func (suite *ArtifactEvidencePRBitbucketCommandTestSuite) TestArtifactEvidencePR wantError: true, name: "report Bitbucket PR evidence fails when commit does not exist", cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + ` - --build-url example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 73d7fee2f31ade8e1a9c456c324255212c3123ab` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 73d7fee2f31ade8e1a9c456c324255212c3123ab` + suite.defaultKosliArguments, goldenRegex: "Error: map\\[error:map\\[message:Resource not found\\] type:error\\]\n", }, { name: "report Bitbucket PR evidence works when --assert is used and commit has a PR", cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + ` --assert - --build-url example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, goldenRegex: "found 1 pull request\\(s\\) for commit: .*\nbitbucket pull request evidence is reported to artifact: .*\n", }, { @@ -105,27 +105,27 @@ func (suite *ArtifactEvidencePRBitbucketCommandTestSuite) TestArtifactEvidencePR name: "report Bitbucket PR evidence fails when --assert is used and commit has no PRs", cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + ` --assert - --build-url example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit cb6ec5fcbb25b1ebe4859d35ab7995ab973f894c` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit cb6ec5fcbb25b1ebe4859d35ab7995ab973f894c` + suite.defaultKosliArguments, goldenRegex: "found 0 pull request\\(s\\) for commit: .*\nbitbucket pull request evidence is reported to artifact: .*\nError: assert failed: no pull request found for the given commit: .*\n", }, { name: "report Bitbucket PR evidence does not fail when commit has no PRs", cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + ` - --build-url example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit cb6ec5fcbb25b1ebe4859d35ab7995ab973f894c` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit cb6ec5fcbb25b1ebe4859d35ab7995ab973f894c` + suite.defaultKosliArguments, goldenRegex: "found 0 pull request\\(s\\) for commit: .*\nbitbucket pull request evidence is reported to artifact: .*\n", }, { wantError: true, name: "report Bitbucket PR evidence fails when the artifact does not exist in the server", cmd: `report evidence artifact pullrequest bitbucket testdata/file1 --artifact-type file --name bb-pr --flow ` + suite.flowName + ` - --build-url example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, goldenRegex: "found 1 pull request\\(s\\) for commit: .*\nError: Artifact with fingerprint '7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9' does not exist in flow 'bitbucket-pr' belonging to organization 'docs-cmd-test-user'. \n", }, { wantError: true, name: "report Bitbucket PR evidence fails when --artifact-type is unsupported", cmd: `report evidence artifact pullrequest bitbucket testdata/file1 --artifact-type unsupported --name bb-pr --flow ` + suite.flowName + ` - --build-url example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, goldenRegex: "Error: unsupported is not a supported artifact type\n", }, { @@ -133,7 +133,7 @@ func (suite *ArtifactEvidencePRBitbucketCommandTestSuite) TestArtifactEvidencePR name: "report Bitbucket PR evidence fails when --user-data is not found", cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + ` --user-data non-existing.json - --build-url example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, goldenRegex: "Error: open non-existing.json: no such file or directory\n", }, } diff --git a/cmd/kosli/reportEvidenceArtifactPRGithub_test.go b/cmd/kosli/reportEvidenceArtifactPRGithub_test.go index ae4824d6..e21dcac0 100644 --- a/cmd/kosli/reportEvidenceArtifactPRGithub_test.go +++ b/cmd/kosli/reportEvidenceArtifactPRGithub_test.go @@ -41,14 +41,14 @@ func (suite *ArtifactEvidencePRGithubCommandTestSuite) TestArtifactEvidencePRGit { name: "report Github PR evidence works with new flags (fingerprint, name ...)", cmd: `report evidence artifact pullrequest github --fingerprint ` + suite.artifactFingerprint + ` --name gh-pr --flow ` + suite.flowName + ` - --build-url example.com --github-org kosli-dev --repository cli --commit ` + suite.commitWithPR + suite.defaultKosliArguments, + --build-url http://www.example.com --github-org kosli-dev --repository cli --commit ` + suite.commitWithPR + suite.defaultKosliArguments, goldenRegex: "found 1 pull request\\(s\\) for commit: .*\ngithub pull request evidence is reported to artifact: .*\n", }, { wantError: true, name: "report Github PR evidence fails when --org is missing", cmd: `report evidence artifact pullrequest github --fingerprint ` + suite.artifactFingerprint + ` --name gh-pr --flow ` + suite.flowName + ` - --build-url example.com --github-org kosli-dev --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6 --api-token foo --host bar`, + --build-url http://www.example.com --github-org kosli-dev --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6 --api-token foo --host bar`, goldenRegex: "Error: --org is not set\n" + "Usage: kosli report evidence artifact pullrequest github \\[IMAGE-NAME | FILE-PATH | DIR-PATH\\] \\[flags\\]\n", }, @@ -56,35 +56,35 @@ func (suite *ArtifactEvidencePRGithubCommandTestSuite) TestArtifactEvidencePRGit wantError: true, name: "report Github PR evidence fails when --name is missing", cmd: `report evidence artifact pullrequest github --fingerprint ` + suite.artifactFingerprint + ` --flow ` + suite.flowName + ` - --build-url example.com --github-org kosli-dev --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, + --build-url http://www.example.com --github-org kosli-dev --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"name\" not set\n", }, { wantError: true, name: "report Github PR evidence fails when --github-org is missing", cmd: `report evidence artifact pullrequest github --fingerprint ` + suite.artifactFingerprint + ` --name gh-pr --flow ` + suite.flowName + ` - --build-url example.com --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, + --build-url http://www.example.com --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"github-org\" not set\n", }, { wantError: true, name: "report Github PR evidence fails when --repository is missing", cmd: `report evidence artifact pullrequest github --fingerprint ` + suite.artifactFingerprint + ` --name gh-pr --flow ` + suite.flowName + ` - --build-url example.com --github-org kosli-dev --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, + --build-url http://www.example.com --github-org kosli-dev --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"repository\" not set\n", }, { wantError: true, name: "report Github PR evidence fails when --commit is missing", cmd: `report evidence artifact pullrequest github --fingerprint ` + suite.artifactFingerprint + ` --name gh-pr --flow ` + suite.flowName + ` - --build-url example.com --github-org kosli-dev --repository cli` + suite.defaultKosliArguments, + --build-url http://www.example.com --github-org kosli-dev --repository cli` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"commit\" not set\n", }, { wantError: true, name: "report Github PR evidence fails when neither --fingerprint nor --artifact-type are set", cmd: `report evidence artifact pullrequest github artifactNameArg --name gh-pr --flow ` + suite.flowName + ` - --build-url example.com --github-org kosli-dev --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, + --build-url http://www.example.com --github-org kosli-dev --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, goldenRegex: "Error: either --artifact-type or --fingerprint must be specified\n" + "Usage: kosli report evidence artifact pullrequest github \\[IMAGE-NAME | FILE-PATH | DIR-PATH\\] \\[flags\\]\n", }, @@ -92,14 +92,14 @@ func (suite *ArtifactEvidencePRGithubCommandTestSuite) TestArtifactEvidencePRGit wantError: true, name: "report Github PR evidence fails when commit does not exist", cmd: `report evidence artifact pullrequest github --fingerprint ` + suite.artifactFingerprint + ` --name gh-pr --flow ` + suite.flowName + ` - --build-url example.com --github-org kosli-dev --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c3123ab` + suite.defaultKosliArguments, + --build-url http://www.example.com --github-org kosli-dev --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c3123ab` + suite.defaultKosliArguments, goldenRegex: "Error: GET https://api.github.com/repos/kosli-dev/cli/commits/73d7fee2f31ade8e1a9c456c324255212c3123ab/pulls: 422 No commit found for SHA: 73d7fee2f31ade8e1a9c456c324255212c3123ab \\[\\]\n", }, { name: "report Github PR evidence works when --assert is used and commit has a PR", cmd: `report evidence artifact pullrequest github --fingerprint ` + suite.artifactFingerprint + ` --name gh-pr --flow ` + suite.flowName + ` --assert - --build-url example.com --github-org kosli-dev --repository cli --commit ` + suite.commitWithPR + suite.defaultKosliArguments, + --build-url http://www.example.com --github-org kosli-dev --repository cli --commit ` + suite.commitWithPR + suite.defaultKosliArguments, goldenRegex: "found 1 pull request\\(s\\) for commit: .*\ngithub pull request evidence is reported to artifact: .*\n", }, { @@ -107,13 +107,13 @@ func (suite *ArtifactEvidencePRGithubCommandTestSuite) TestArtifactEvidencePRGit name: "report Github PR evidence fails when --assert is used and commit has no PRs", cmd: `report evidence artifact pullrequest github --fingerprint ` + suite.artifactFingerprint + ` --name gh-pr --flow ` + suite.flowName + ` --assert - --build-url example.com --github-org kosli-dev --repository cli --commit 9bca2c44eaf221a79fb18a1a11bdf2997adaf870` + suite.defaultKosliArguments, + --build-url http://www.example.com --github-org kosli-dev --repository cli --commit 9bca2c44eaf221a79fb18a1a11bdf2997adaf870` + suite.defaultKosliArguments, goldenRegex: "found 0 pull request\\(s\\) for commit: .*\ngithub pull request evidence is reported to artifact: .*\nError: assert failed: no pull request found for the given commit: .*\n", }, { name: "report Github PR evidence does not fail when commit has no PRs", cmd: `report evidence artifact pullrequest github --fingerprint ` + suite.artifactFingerprint + ` --name gh-pr --flow ` + suite.flowName + ` - --build-url example.com --github-org kosli-dev --repository cli --commit 9bca2c44eaf221a79fb18a1a11bdf2997adaf870` + suite.defaultKosliArguments, + --build-url http://www.example.com --github-org kosli-dev --repository cli --commit 9bca2c44eaf221a79fb18a1a11bdf2997adaf870` + suite.defaultKosliArguments, goldenRegex: "found 0 pull request\\(s\\) for commit: 9bca2c44eaf221a79fb18a1a11bdf2997adaf870\n" + "github pull request evidence is reported to artifact: " + suite.artifactFingerprint + "\n", }, @@ -121,14 +121,14 @@ func (suite *ArtifactEvidencePRGithubCommandTestSuite) TestArtifactEvidencePRGit wantError: true, name: "report Github PR evidence fails when the artifact does not exist in the server", cmd: `report evidence artifact pullrequest github testdata/file1 --artifact-type file --name gh-pr --flow ` + suite.flowName + ` - --build-url example.com --github-org kosli-dev --repository cli --commit ` + suite.commitWithPR + suite.defaultKosliArguments, + --build-url http://www.example.com --github-org kosli-dev --repository cli --commit ` + suite.commitWithPR + suite.defaultKosliArguments, goldenRegex: "found 1 pull request\\(s\\) for commit: e21a8afff429e0c87ee523d683f2438113f0a105\nError: Artifact with fingerprint '7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9' does not exist in flow 'github-pr' belonging to organization 'docs-cmd-test-user'. \n", }, { wantError: true, name: "report Github PR evidence fails when --artifact-type is unsupported", cmd: `report evidence artifact pullrequest github testdata/file1 --artifact-type unsupported --name gh-pr --flow ` + suite.flowName + ` - --build-url example.com --github-org kosli-dev --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, + --build-url http://www.example.com --github-org kosli-dev --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, goldenRegex: "Error: unsupported is not a supported artifact type\n", }, { @@ -136,7 +136,7 @@ func (suite *ArtifactEvidencePRGithubCommandTestSuite) TestArtifactEvidencePRGit name: "report Github PR evidence fails when --user-data is not found", cmd: `report evidence artifact pullrequest github --fingerprint ` + suite.artifactFingerprint + ` --name gh-pr --flow ` + suite.flowName + ` --user-data non-existing.json - --build-url example.com --github-org kosli-dev --repository cli --commit ` + suite.commitWithPR + suite.defaultKosliArguments, + --build-url http://www.example.com --github-org kosli-dev --repository cli --commit ` + suite.commitWithPR + suite.defaultKosliArguments, goldenRegex: "Error: open non-existing.json: no such file or directory\n", }, } diff --git a/cmd/kosli/reportEvidenceArtifactPRGitlab_test.go b/cmd/kosli/reportEvidenceArtifactPRGitlab_test.go index 8f034537..68d2ac4a 100644 --- a/cmd/kosli/reportEvidenceArtifactPRGitlab_test.go +++ b/cmd/kosli/reportEvidenceArtifactPRGitlab_test.go @@ -39,21 +39,21 @@ func (suite *ArtifactEvidencePRGitlabCommandTestSuite) TestArtifactEvidencePRGit { name: "report Gitlab PR evidence works when no merge requests are found", cmd: `report evidence artifact pullrequest gitlab --fingerprint ` + suite.artifactFingerprint + ` --name gl-pr --flow ` + suite.flowName + ` - --build-url example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit 2ec23dda01fc85e3f94a2b5ea8cb8cf7e79c4ed6` + suite.defaultKosliArguments, + --build-url http://www.example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit 2ec23dda01fc85e3f94a2b5ea8cb8cf7e79c4ed6` + suite.defaultKosliArguments, goldenRegex: "found 0 merge request\\(s\\) for commit: 2ec23dda01fc85e3f94a2b5ea8cb8cf7e79c4ed6\n" + "gitlab merge request evidence is reported to artifact: " + suite.artifactFingerprint + "\n", }, { name: "report Gitlab PR evidence works when there are merge requests", cmd: `report evidence artifact pullrequest gitlab --fingerprint ` + suite.artifactFingerprint + ` --name gl-pr --flow ` + suite.flowName + ` - --build-url example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit e6510880aecdc05d79104d937e1adb572bd91911` + suite.defaultKosliArguments, + --build-url http://www.example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit e6510880aecdc05d79104d937e1adb572bd91911` + suite.defaultKosliArguments, goldenRegex: "found 1 merge request\\(s\\) for commit: e6510880aecdc05d79104d937e1adb572bd91911\ngitlab merge request evidence is reported to artifact: " + suite.artifactFingerprint + "\n", }, { wantError: true, name: "report Gitlab PR evidence fails when --org is missing", cmd: `report evidence artifact pullrequest gitlab --fingerprint ` + suite.artifactFingerprint + ` --name gl-pr --flow ` + suite.flowName + ` - --build-url example.com --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6 --api-token foo --host bar`, + --build-url http://www.example.com --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6 --api-token foo --host bar`, goldenRegex: "Error: --org is not set\n" + "Usage: kosli report evidence artifact pullrequest gitlab \\[IMAGE-NAME | FILE-PATH | DIR-PATH\\] \\[flags\\]\n", }, @@ -61,35 +61,35 @@ func (suite *ArtifactEvidencePRGitlabCommandTestSuite) TestArtifactEvidencePRGit wantError: true, name: "report Gitlab PR evidence fails when both --name and --gitlab-org are missing", cmd: `report evidence artifact pullrequest gitlab --fingerprint ` + suite.artifactFingerprint + ` --flow ` + suite.flowName + ` - --build-url example.com --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, + --build-url http://www.example.com --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"gitlab-org\", \"name\" not set\n", }, { wantError: true, name: "report Gitlab PR evidence fails when --gitlab-org is missing", cmd: `report evidence artifact pullrequest gitlab --fingerprint ` + suite.artifactFingerprint + ` --name gl-pr --flow ` + suite.flowName + ` - --build-url example.com --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, + --build-url http://www.example.com --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"gitlab-org\" not set\n", }, { wantError: true, name: "report Gitlab PR evidence fails when --repository is missing", cmd: `report evidence artifact pullrequest gitlab --fingerprint ` + suite.artifactFingerprint + ` --name gl-pr --flow ` + suite.flowName + ` - --build-url example.com --gitlab-org kosli-dev --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, + --build-url http://www.example.com --gitlab-org kosli-dev --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"repository\" not set\n", }, { wantError: true, name: "report Gitlab PR evidence fails when --commit is missing", cmd: `report evidence artifact pullrequest gitlab --fingerprint ` + suite.artifactFingerprint + ` --name gl-pr --flow ` + suite.flowName + ` - --build-url example.com --gitlab-org kosli-dev --repository cli` + suite.defaultKosliArguments, + --build-url http://www.example.com --gitlab-org kosli-dev --repository cli` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"commit\" not set\n", }, { wantError: true, name: "report Gitlab PR evidence fails when neither --fingerprint nor --artifact-type are set", cmd: `report evidence artifact pullrequest gitlab artifactNameArg --name gl-pr --flow ` + suite.flowName + ` - --build-url example.com --gitlab-org kosli-dev --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, + --build-url http://www.example.com --gitlab-org kosli-dev --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, goldenRegex: "Error: either --artifact-type or --fingerprint must be specified\n" + "Usage: kosli report evidence artifact pullrequest gitlab \\[IMAGE-NAME | FILE-PATH | DIR-PATH\\] \\[flags\\]\n", }, @@ -97,14 +97,14 @@ func (suite *ArtifactEvidencePRGitlabCommandTestSuite) TestArtifactEvidencePRGit wantError: true, name: "report Gitlab PR evidence fails when commit does not exist", cmd: `report evidence artifact pullrequest gitlab --fingerprint ` + suite.artifactFingerprint + ` --name gl-pr --flow ` + suite.flowName + ` - --build-url example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit 73d7fee2f31ade8e1a9c456c324255212c3123ab` + suite.defaultKosliArguments, + --build-url http://www.example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit 73d7fee2f31ade8e1a9c456c324255212c3123ab` + suite.defaultKosliArguments, goldenRegex: "Error: GET https://gitlab.com/api/v4/projects/ewelinawilkosz/merkely-gitlab-demo/repository/commits/73d7fee2f31ade8e1a9c456c324255212c3123ab/merge_requests: 404 {message: 404 Commit Not Found}\n", }, { name: "report Gitlab PR evidence works when --assert is used and commit has a PR", cmd: `report evidence artifact pullrequest gitlab --fingerprint ` + suite.artifactFingerprint + ` --name gl-pr --flow ` + suite.flowName + ` --assert - --build-url example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit e6510880aecdc05d79104d937e1adb572bd91911` + suite.defaultKosliArguments, + --build-url http://www.example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit e6510880aecdc05d79104d937e1adb572bd91911` + suite.defaultKosliArguments, goldenRegex: "found 1 merge request\\(s\\) for commit: .*\ngitlab merge request evidence is reported to artifact: .*\n", }, { @@ -112,21 +112,21 @@ func (suite *ArtifactEvidencePRGitlabCommandTestSuite) TestArtifactEvidencePRGit name: "report Gitlab PR evidence fails when --assert is used and commit has no PRs", cmd: `report evidence artifact pullrequest gitlab --fingerprint ` + suite.artifactFingerprint + ` --name gl-pr --flow ` + suite.flowName + ` --assert - --build-url example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit 2ec23dda01fc85e3f94a2b5ea8cb8cf7e79c4ed6` + suite.defaultKosliArguments, + --build-url http://www.example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit 2ec23dda01fc85e3f94a2b5ea8cb8cf7e79c4ed6` + suite.defaultKosliArguments, goldenRegex: "found 0 merge request\\(s\\) for commit: .*\ngitlab merge request evidence is reported to artifact: .*\nError: assert failed: no merge request found for the given commit: .*\n", }, { wantError: true, name: "report Gitlab PR evidence fails when the artifact does not exist in the server", cmd: `report evidence artifact pullrequest gitlab testdata/file1 --artifact-type file --name gl-pr --flow ` + suite.flowName + ` - --build-url example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit e6510880aecdc05d79104d937e1adb572bd91911` + suite.defaultKosliArguments, + --build-url http://www.example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit e6510880aecdc05d79104d937e1adb572bd91911` + suite.defaultKosliArguments, goldenRegex: "found 1 merge request\\(s\\) for commit: e6510880aecdc05d79104d937e1adb572bd91911\nError: Artifact with fingerprint '7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9' does not exist in flow 'gitlab-pr' belonging to organization 'docs-cmd-test-user'. \n", }, { wantError: true, name: "report Gitlab PR evidence fails when --artifact-type is unsupported", cmd: `report evidence artifact pullrequest gitlab testdata/file1 --artifact-type unsupported --name gl-pr --flow ` + suite.flowName + ` - --build-url example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit e6510880aecdc05d79104d937e1adb572bd91911` + suite.defaultKosliArguments, + --build-url http://www.example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit e6510880aecdc05d79104d937e1adb572bd91911` + suite.defaultKosliArguments, goldenRegex: "Error: unsupported is not a supported artifact type\n", }, { @@ -134,7 +134,7 @@ func (suite *ArtifactEvidencePRGitlabCommandTestSuite) TestArtifactEvidencePRGit name: "report Gitlab PR evidence fails when --user-data is not found", cmd: `report evidence artifact pullrequest gitlab --fingerprint ` + suite.artifactFingerprint + ` --name gl-pr --flow ` + suite.flowName + ` --user-data non-existing.json - --build-url example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit e6510880aecdc05d79104d937e1adb572bd91911` + suite.defaultKosliArguments, + --build-url http://www.example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit e6510880aecdc05d79104d937e1adb572bd91911` + suite.defaultKosliArguments, goldenRegex: "Error: open non-existing.json: no such file or directory\n", }, } diff --git a/cmd/kosli/reportEvidenceArtifactSnyk_test.go b/cmd/kosli/reportEvidenceArtifactSnyk_test.go index e97c4689..8045c675 100644 --- a/cmd/kosli/reportEvidenceArtifactSnyk_test.go +++ b/cmd/kosli/reportEvidenceArtifactSnyk_test.go @@ -37,47 +37,47 @@ func (suite *ArtifactEvidenceSnykCommandTestSuite) TestArtifactEvidenceSnykCmd() { name: "report Snyk test evidence works (using --fingerprint)", cmd: `report evidence artifact snyk --fingerprint ` + suite.artifactFingerprint + ` --name snyk-result --flow ` + suite.flowName + ` - --build-url example.com --scan-results testdata/snyk_scan_example.json` + suite.defaultKosliArguments, + --build-url http://www.example.com --scan-results testdata/snyk_scan_example.json` + suite.defaultKosliArguments, goldenRegex: "snyk scan evidence is reported to artifact: " + suite.artifactFingerprint + "\n", }, { name: "report Snyk test evidence works when --evidence-url and --evidence-fingerprint are provided", cmd: `report evidence artifact snyk --fingerprint ` + suite.artifactFingerprint + ` --name snyk-result --flow ` + suite.flowName + ` - --build-url example.com --scan-results testdata/snyk_scan_example.json + --build-url http://www.example.com --scan-results testdata/snyk_scan_example.json --evidence-url https://example.com --evidence-fingerprint ` + suite.artifactFingerprint + suite.defaultKosliArguments, goldenRegex: "snyk scan evidence is reported to artifact: " + suite.artifactFingerprint + "\n", }, { name: "report Snyk test evidence works (using --artifact-type)", cmd: `report evidence artifact snyk testdata/file1 --artifact-type file --name snyk-result --flow ` + suite.flowName + ` - --build-url example.com --scan-results testdata/snyk_scan_example.json` + suite.defaultKosliArguments, + --build-url http://www.example.com --scan-results testdata/snyk_scan_example.json` + suite.defaultKosliArguments, goldenRegex: "snyk scan evidence is reported to artifact: " + suite.artifactFingerprint + "\n", }, { name: "report Snyk scan evidence with non-existing scan-results fails", cmd: `report evidence artifact snyk --fingerprint ` + suite.artifactFingerprint + ` --name snyk-result --flow ` + suite.flowName + ` - --build-url example.com --scan-results testdata/foo.json` + suite.defaultKosliArguments, + --build-url http://www.example.com --scan-results testdata/foo.json` + suite.defaultKosliArguments, wantError: true, goldenRegex: "Error: failed to parse Snyk results file \\[testdata/foo.json\\]. Failed to parse as Sarif: open testdata/foo.json: no such file or directory. Fallen back to parse Snyk Json, but also failed: the provided file path doesn't have a file\n", }, { name: "report Snyk scan evidence with missing scan-results flag fails", cmd: `report evidence artifact snyk --fingerprint ` + suite.artifactFingerprint + ` --name snyk-result --flow ` + suite.flowName + ` - --build-url example.com` + suite.defaultKosliArguments, + --build-url http://www.example.com` + suite.defaultKosliArguments, wantError: true, goldenRegex: "Error: required flag\\(s\\) \"scan-results\" not set\n", }, { name: "report Snyk scan evidence with missing name flag fails", cmd: `report evidence artifact snyk --fingerprint ` + suite.artifactFingerprint + ` --flow ` + suite.flowName + ` - --build-url example.com --scan-results testdata/snyk_scan_example.json` + suite.defaultKosliArguments, + --build-url http://www.example.com --scan-results testdata/snyk_scan_example.json` + suite.defaultKosliArguments, wantError: true, goldenRegex: "Error: required flag\\(s\\) \"name\" not set\n", }, { name: "report Snyk scan evidence with a missing flow fails", cmd: `report evidence artifact snyk --fingerprint ` + suite.artifactFingerprint + ` --name snyk-result - --build-url example.com --scan-results testdata/snyk_scan_example.json` + suite.defaultKosliArguments, + --build-url http://www.example.com --scan-results testdata/snyk_scan_example.json` + suite.defaultKosliArguments, wantError: true, goldenRegex: "Error: required flag\\(s\\) \"flow\" not set\n", }, @@ -91,13 +91,13 @@ func (suite *ArtifactEvidenceSnykCommandTestSuite) TestArtifactEvidenceSnykCmd() { name: "report Snyk test evidence works with sarif snyk results and uploading is enabled", cmd: `report evidence artifact snyk --fingerprint ` + suite.artifactFingerprint + ` --name snyk-result --flow ` + suite.flowName + ` - --build-url example.com --scan-results testdata/snyk_sarif.json` + suite.defaultKosliArguments, + --build-url http://www.example.com --scan-results testdata/snyk_sarif.json` + suite.defaultKosliArguments, goldenRegex: "snyk scan evidence is reported to artifact: " + suite.artifactFingerprint + "\n", }, { name: "report Snyk test evidence works with sarif snyk results and uploading is disabled", cmd: `report evidence artifact snyk --fingerprint ` + suite.artifactFingerprint + ` --name snyk-result --flow ` + suite.flowName + ` - --build-url example.com --scan-results testdata/snyk_sarif.json --upload-results=false` + suite.defaultKosliArguments, + --build-url http://www.example.com --scan-results testdata/snyk_sarif.json --upload-results=false` + suite.defaultKosliArguments, goldenRegex: "snyk scan evidence is reported to artifact: " + suite.artifactFingerprint + "\n", }, } diff --git a/cmd/kosli/reportEvidenceCommitGeneric_test.go b/cmd/kosli/reportEvidenceCommitGeneric_test.go index 6222065e..36c10327 100644 --- a/cmd/kosli/reportEvidenceCommitGeneric_test.go +++ b/cmd/kosli/reportEvidenceCommitGeneric_test.go @@ -36,14 +36,14 @@ func (suite *CommitEvidenceGenericCommandTestSuite) TestCommitEvidenceGenericCom { name: "report Generic test evidence works without files", cmd: fmt.Sprintf(`report evidence commit generic --commit af28ccdeffdfa67f5c5a88be209e94cc4742de3c --name %s --flows %s - --build-url example.com --compliant --description "some description" %s`, + --build-url http://www.example.com --compliant --description "some description" %s`, evidenceName, suite.flowNames, suite.defaultKosliArguments), goldenRegex: fmt.Sprintf("generic evidence '%s' is reported to commit: af28ccdeffdfa67f5c5a88be209e94cc4742de3c\n", evidenceName), }, { name: "report Generic test evidence works when --evidence-url and --evidence-fingerprint are provided", cmd: fmt.Sprintf(`report evidence commit generic --commit af28ccdeffdfa67f5c5a88be209e94cc4742de3c --name %s --flows %s - --build-url example.com --compliant --description "some description" + --build-url http://www.example.com --compliant --description "some description" --evidence-url https://example.com --evidence-fingerprint 847411c6124e719a4e8da2550ac5c116b7ff930493ce8a061486b48db8a5aaa0 %s`, evidenceName, suite.flowNames, suite.defaultKosliArguments), goldenRegex: fmt.Sprintf("generic evidence '%s' is reported to commit: af28ccdeffdfa67f5c5a88be209e94cc4742de3c\n", evidenceName), @@ -51,7 +51,7 @@ func (suite *CommitEvidenceGenericCommandTestSuite) TestCommitEvidenceGenericCom { name: "report Generic test evidence works when --evidence-paths is provided and contains a single file", cmd: fmt.Sprintf(`report evidence commit generic --commit af28ccdeffdfa67f5c5a88be209e94cc4742de3c --name %s --flows %s - --build-url example.com --compliant --description "some description" + --build-url http://www.example.com --compliant --description "some description" --evidence-paths testdata/file1 %s`, evidenceName, suite.flowNames, suite.defaultKosliArguments), goldenRegex: fmt.Sprintf("generic evidence '%s' is reported to commit: af28ccdeffdfa67f5c5a88be209e94cc4742de3c\n", evidenceName), @@ -59,7 +59,7 @@ func (suite *CommitEvidenceGenericCommandTestSuite) TestCommitEvidenceGenericCom { name: "report Generic test evidence works when --evidence-paths is provided and contains a single directory", cmd: fmt.Sprintf(`report evidence commit generic --commit af28ccdeffdfa67f5c5a88be209e94cc4742de3c --name %s --flows %s - --build-url example.com --compliant --description "some description" + --build-url http://www.example.com --compliant --description "some description" --evidence-paths testdata/folder1 %s`, evidenceName, suite.flowNames, suite.defaultKosliArguments), goldenRegex: fmt.Sprintf("generic evidence '%s' is reported to commit: af28ccdeffdfa67f5c5a88be209e94cc4742de3c\n", evidenceName), @@ -67,7 +67,7 @@ func (suite *CommitEvidenceGenericCommandTestSuite) TestCommitEvidenceGenericCom { name: "report Generic test evidence works when --evidence-paths is provided and contains a file and a dir", cmd: fmt.Sprintf(`report evidence commit generic --commit af28ccdeffdfa67f5c5a88be209e94cc4742de3c --name %s --flows %s - --build-url example.com --compliant --description "some description" + --build-url http://www.example.com --compliant --description "some description" --evidence-paths testdata/folder1,testdata/file1 %s`, evidenceName, suite.flowNames, suite.defaultKosliArguments), goldenRegex: fmt.Sprintf("generic evidence '%s' is reported to commit: af28ccdeffdfa67f5c5a88be209e94cc4742de3c\n", evidenceName), @@ -76,7 +76,7 @@ func (suite *CommitEvidenceGenericCommandTestSuite) TestCommitEvidenceGenericCom wantError: true, name: "report Generic test evidence fails when --evidence-paths is provided and contains a non-existing file", cmd: fmt.Sprintf(`report evidence commit generic --commit af28ccdeffdfa67f5c5a88be209e94cc4742de3c --name %s --flows %s - --build-url example.com --compliant --description "some description" + --build-url http://www.example.com --compliant --description "some description" --evidence-paths non-existing.txt %s`, evidenceName, suite.flowNames, suite.defaultKosliArguments), goldenRegex: "Error: stat non-existing.txt: no such file or directory\n", @@ -84,27 +84,27 @@ func (suite *CommitEvidenceGenericCommandTestSuite) TestCommitEvidenceGenericCom { name: "report Generic test evidence works when neither of --description nor --user-data provided", cmd: fmt.Sprintf(`report evidence commit generic --commit af28ccdeffdfa67f5c5a88be209e94cc4742de3c --name %s --flows %s - --build-url example.com --compliant %s`, + --build-url http://www.example.com --compliant %s`, evidenceName, suite.flowNames, suite.defaultKosliArguments), goldenRegex: fmt.Sprintf("generic evidence '%s' is reported to commit: af28ccdeffdfa67f5c5a88be209e94cc4742de3c\n", evidenceName), }, { name: "report Generic test evidence works when neither of --description, --user-data or --compliant is provided", cmd: fmt.Sprintf(`report evidence commit generic --commit af28ccdeffdfa67f5c5a88be209e94cc4742de3c --name %s --flows %s - --build-url example.com %s`, evidenceName, suite.flowNames, suite.defaultKosliArguments), + --build-url http://www.example.com %s`, evidenceName, suite.flowNames, suite.defaultKosliArguments), goldenRegex: fmt.Sprintf("generic evidence '%s' is reported to commit: af28ccdeffdfa67f5c5a88be209e94cc4742de3c\n", evidenceName), }, { name: "report Generic test evidence fails if --name is missing", cmd: fmt.Sprintf(`report evidence commit generic --commit af28ccdeffdfa67f5c5a88be209e94cc4742de3c --flows %s - --build-url example.com %s`, suite.flowNames, suite.defaultKosliArguments), + --build-url http://www.example.com %s`, suite.flowNames, suite.defaultKosliArguments), wantError: true, goldenRegex: "Error: required flag\\(s\\) \"name\" not set\n", }, { name: "report Generic test evidence fails if --commit is missing", cmd: fmt.Sprintf(`report evidence commit generic --name %s --flows %s - --build-url example.com --compliant --description "some description" %s`, + --build-url http://www.example.com --compliant --description "some description" %s`, evidenceName, suite.flowNames, suite.defaultKosliArguments), wantError: true, goldenRegex: "Error: required flag\\(s\\) \"commit\" not set\n", @@ -112,7 +112,7 @@ func (suite *CommitEvidenceGenericCommandTestSuite) TestCommitEvidenceGenericCom { name: "report Generic test evidence works if --flows flag is missing", cmd: fmt.Sprintf(`report evidence commit generic --commit af28ccdeffdfa67f5c5a88be209e94cc4742de3c --name %s - --build-url example.com --compliant --description "some description" %s`, + --build-url http://www.example.com --compliant --description "some description" %s`, evidenceName, suite.defaultKosliArguments), goldenRegex: fmt.Sprintf("generic evidence '%s' is reported to commit: af28ccdeffdfa67f5c5a88be209e94cc4742de3c\n", evidenceName), }, @@ -127,7 +127,7 @@ func (suite *CommitEvidenceGenericCommandTestSuite) TestCommitEvidenceGenericCom { name: "report Generic test evidence fails if user-data is non-existing file", cmd: fmt.Sprintf(`report evidence commit generic --commit af28ccdeffdfa67f5c5a88be209e94cc4742de3c --name %s --flows %s - --build-url example.com --compliant --description "some description" %s --user-data non-existing-file`, + --build-url http://www.example.com --compliant --description "some description" %s --user-data non-existing-file`, evidenceName, suite.flowNames, suite.defaultKosliArguments), wantError: true, goldenRegex: "Error: open non-existing-file: no such file or directory\n", diff --git a/cmd/kosli/reportEvidenceCommitJUnit_test.go b/cmd/kosli/reportEvidenceCommitJUnit_test.go index 51c1171f..043c51b9 100644 --- a/cmd/kosli/reportEvidenceCommitJUnit_test.go +++ b/cmd/kosli/reportEvidenceCommitJUnit_test.go @@ -35,41 +35,41 @@ func (suite *CommitEvidenceJUnitCommandTestSuite) TestCommitEvidenceJUnitCommand { name: "report JUnit test evidence works", cmd: `report evidence commit junit --commit af28ccdeffdfa67f5c5a88be209e94cc4742de3c --name junit-result --flows ` + suite.flowNames + ` - --build-url example.com --results-dir testdata` + suite.defaultKosliArguments, + --build-url http://www.example.com --results-dir testdata` + suite.defaultKosliArguments, goldenRegex: "junit test evidence is reported to commit: af28ccdeffdfa67f5c5a88be209e94cc4742de3c\n", }, { name: "report JUnit test evidence works when --evidence-url and --evidence-fingerprint are provided", cmd: `report evidence commit junit --commit af28ccdeffdfa67f5c5a88be209e94cc4742de3c --name junit-result --flows ` + suite.flowNames + ` - --build-url example.com --results-dir testdata + --build-url http://www.example.com --results-dir testdata --evidence-url https://example.com --evidence-fingerprint 847411c6124e719a4e8da2550ac5c116b7ff930493ce8a061486b48db8a5aaa0` + suite.defaultKosliArguments, goldenRegex: "junit test evidence is reported to commit: af28ccdeffdfa67f5c5a88be209e94cc4742de3c\n", }, { name: "report JUnit test evidence with non-existing results dir", cmd: `report evidence commit junit --commit af28ccdeffdfa67f5c5a88be209e94cc4742de3c --name junit-result --flows ` + suite.flowNames + ` - --build-url example.com --results-dir foo` + suite.defaultKosliArguments, + --build-url http://www.example.com --results-dir foo` + suite.defaultKosliArguments, wantError: true, goldenRegex: "Error: lstat foo: no such file or directory\n", }, { name: "report JUnit test evidence with a results dir that does not contain any results", cmd: `report evidence commit junit --commit af28ccdeffdfa67f5c5a88be209e94cc4742de3c --name junit-result --flows ` + suite.flowNames + ` - --build-url example.com --results-dir testdata/folder1` + suite.defaultKosliArguments, + --build-url http://www.example.com --results-dir testdata/folder1` + suite.defaultKosliArguments, wantError: true, goldenRegex: "Error: no tests found in testdata/folder1 directory\n", }, { name: "report JUnit test evidence with missing name flag", cmd: `report evidence commit junit --commit af28ccdeffdfa67f5c5a88be209e94cc4742de3c --flows ` + suite.flowNames + ` - --build-url example.com --results-dir testdata` + suite.defaultKosliArguments, + --build-url http://www.example.com --results-dir testdata` + suite.defaultKosliArguments, wantError: true, goldenRegex: "Error: required flag\\(s\\) \"name\" not set\n", }, { name: "report JUnit test evidence with a missing --flows flag", cmd: `report evidence commit junit --commit af28ccdeffdfa67f5c5a88be209e94cc4742de3c --name junit-result - --build-url example.com --results-dir testdata` + suite.defaultKosliArguments, + --build-url http://www.example.com --results-dir testdata` + suite.defaultKosliArguments, goldenRegex: "junit test evidence is reported to commit: af28ccdeffdfa67f5c5a88be209e94cc4742de3c\n", }, { @@ -82,7 +82,7 @@ func (suite *CommitEvidenceJUnitCommandTestSuite) TestCommitEvidenceJUnitCommand { name: "report JUnit test evidence with a missing commit flag", cmd: `report evidence commit junit --flows ` + suite.flowNames + ` - --build-url example.com --name junit-result --results-dir testdata` + suite.defaultKosliArguments, + --build-url http://www.example.com --name junit-result --results-dir testdata` + suite.defaultKosliArguments, wantError: true, goldenRegex: "Error: required flag\\(s\\) \"commit\" not set\n", }, diff --git a/cmd/kosli/reportEvidenceCommitJira_test.go b/cmd/kosli/reportEvidenceCommitJira_test.go index 7ce8512e..3362dd3a 100644 --- a/cmd/kosli/reportEvidenceCommitJira_test.go +++ b/cmd/kosli/reportEvidenceCommitJira_test.go @@ -59,7 +59,7 @@ func (suite *CommitEvidenceJiraCommandTestSuite) TestCommitEvidenceJiraCommandCm cmd: fmt.Sprintf(`report evidence commit jira --name jira-validation --jira-base-url https://kosli-test.atlassian.net --jira-username tore@kosli.com --repo-root %s - --build-url example.com %s`, suite.tmpDir, suite.defaultKosliArguments), + --build-url http://www.example.com %s`, suite.tmpDir, suite.defaultKosliArguments), goldenRegex: "Jira evidence is reported to commit: [0-9a-f]{40}\n.*Issues references reported:.*\n.*EX-1: issue found", additionalConfig: jiraTestsAdditionalConfig{ commitMessage: "EX-1 test commit", @@ -71,7 +71,7 @@ func (suite *CommitEvidenceJiraCommandTestSuite) TestCommitEvidenceJiraCommandCm --jira-base-url https://kosli-test.atlassian.net --jira-username tore@kosli.com --repo-root %s --flows %s - --build-url example.com %s`, suite.tmpDir, suite.flowName, suite.defaultKosliArguments), + --build-url http://www.example.com %s`, suite.tmpDir, suite.flowName, suite.defaultKosliArguments), goldenRegex: "Jira evidence is reported to commit: [0-9a-f]{40}\n.*Issues references reported:.*\n.*EX-1: issue found", additionalConfig: jiraTestsAdditionalConfig{ commitMessage: "EX-1 test commit", @@ -82,7 +82,7 @@ func (suite *CommitEvidenceJiraCommandTestSuite) TestCommitEvidenceJiraCommandCm cmd: fmt.Sprintf(`report evidence commit jira --name jira-validation --jira-base-url https://kosli-test.atlassian.net --jira-username tore@kosli.com --repo-root %s - --build-url example.com %s`, suite.tmpDir, suite.defaultKosliArguments), + --build-url http://www.example.com %s`, suite.tmpDir, suite.defaultKosliArguments), goldenRegex: "Jira evidence is reported to commit: [0-9a-f]{40}\n" + ".*Issues references reported:.*\n.*SAMI-1: issue not found", additionalConfig: jiraTestsAdditionalConfig{ @@ -94,7 +94,7 @@ func (suite *CommitEvidenceJiraCommandTestSuite) TestCommitEvidenceJiraCommandCm cmd: fmt.Sprintf(`report evidence commit jira --name jira-validation --jira-base-url https://kosli-test.atlassian.net --jira-username tore@kosli.com --repo-root %s - --build-url example.com %s`, suite.tmpDir, suite.defaultKosliArguments), + --build-url http://www.example.com %s`, suite.tmpDir, suite.defaultKosliArguments), goldenRegex: "Jira evidence is reported to commit: [0-9a-f]{40}\n" + ".*Issues references reported:.*\n.*EX-1: issue found\n.*SAMI-1: issue not found", additionalConfig: jiraTestsAdditionalConfig{ @@ -106,7 +106,7 @@ func (suite *CommitEvidenceJiraCommandTestSuite) TestCommitEvidenceJiraCommandCm cmd: fmt.Sprintf(`report evidence commit jira --name jira-validation --jira-base-url https://kosli-test.atlassian.net --jira-username tore@kosli.com --repo-root %s - --build-url example.com %s`, suite.tmpDir, suite.defaultKosliArguments), + --build-url http://www.example.com %s`, suite.tmpDir, suite.defaultKosliArguments), goldenRegex: "Jira evidence is reported to commit: [0-9a-f]{40}\n.*Issues references reported:.*\n.*EX-1: issue found", additionalConfig: jiraTestsAdditionalConfig{ commitMessage: "Lets test EX-1 test commit", @@ -117,7 +117,7 @@ func (suite *CommitEvidenceJiraCommandTestSuite) TestCommitEvidenceJiraCommandCm cmd: fmt.Sprintf(`report evidence commit jira --name jira-validation --jira-base-url https://kosli-test.atlassian.net --jira-username tore@kosli.com --repo-root %s - --build-url example.com %s`, suite.tmpDir, suite.defaultKosliArguments), + --build-url http://www.example.com %s`, suite.tmpDir, suite.defaultKosliArguments), goldenRegex: "Jira evidence is reported to commit: [0-9a-f]{40}\n.*Issues references reported:.*\n.*EX-1: issue found", additionalConfig: jiraTestsAdditionalConfig{ commitMessage: "Lets test EX-1", @@ -128,7 +128,7 @@ func (suite *CommitEvidenceJiraCommandTestSuite) TestCommitEvidenceJiraCommandCm cmd: fmt.Sprintf(`report evidence commit jira --name jira-validation --jira-base-url https://kosli-test.atlassian.net/ --jira-username tore@kosli.com --repo-root %s - --build-url example.com %s`, suite.tmpDir, suite.defaultKosliArguments), + --build-url http://www.example.com %s`, suite.tmpDir, suite.defaultKosliArguments), goldenRegex: "Jira evidence is reported to commit: [0-9a-f]{40}\n.*Issues references reported:.*\n.*EX-1: issue found", additionalConfig: jiraTestsAdditionalConfig{ branchName: "EX-1", @@ -140,7 +140,7 @@ func (suite *CommitEvidenceJiraCommandTestSuite) TestCommitEvidenceJiraCommandCm cmd: fmt.Sprintf(`report evidence commit jira --name jira-validation --jira-base-url https://kosli-test.atlassian.net/ --jira-username tore@kosli.com --repo-root %s - --build-url example.com %s`, suite.tmpDir, suite.defaultKosliArguments), + --build-url http://www.example.com %s`, suite.tmpDir, suite.defaultKosliArguments), goldenRegex: "Jira evidence is reported to commit: [0-9a-f]{40}\n.*Issues references reported:.*\n.*EX-1: issue found", additionalConfig: jiraTestsAdditionalConfig{ commitMessage: "Lets test EX-1 test commit", @@ -152,7 +152,7 @@ func (suite *CommitEvidenceJiraCommandTestSuite) TestCommitEvidenceJiraCommandCm cmd: fmt.Sprintf(`report evidence commit jira --name jira-validation --jira-base-url https://kosli-test.atlassian.net --jira-api-token xxx --jira-pat xxxx --repo-root %s --commit 61ab3ea22bd4264996b35bfb82869c482d9f4a06 - --build-url example.com %s`, suite.tmpDir, suite.defaultKosliArguments), + --build-url http://www.example.com %s`, suite.tmpDir, suite.defaultKosliArguments), goldenRegex: "Error: only one of --jira-pat, --jira-api-token is allowed\n", }, { @@ -161,7 +161,7 @@ func (suite *CommitEvidenceJiraCommandTestSuite) TestCommitEvidenceJiraCommandCm cmd: fmt.Sprintf(`report evidence commit jira --name jira-validation --jira-base-url https://kosli-test.atlassian.net --jira-api-token xxx --repo-root %s --commit 61ab3ea22bd4264996b35bfb82869c482d9f4a06 - --build-url example.com %s`, suite.tmpDir, suite.defaultKosliArguments), + --build-url http://www.example.com %s`, suite.tmpDir, suite.defaultKosliArguments), goldenRegex: "Error: at least one of --jira-pat, --jira-username is required\n", }, { @@ -170,7 +170,7 @@ func (suite *CommitEvidenceJiraCommandTestSuite) TestCommitEvidenceJiraCommandCm cmd: fmt.Sprintf(`report evidence commit jira --name jira-validation --jira-base-url https://kosli-test.atlassian.net --jira-username tore@kosli.com --repo-root %s - --build-url example.com %s`, suite.tmpDir, suite.defaultKosliArguments), + --build-url http://www.example.com %s`, suite.tmpDir, suite.defaultKosliArguments), goldenRegex: "Error: required flag\\(s\\) \"commit\" not set\n", }, { @@ -180,7 +180,7 @@ func (suite *CommitEvidenceJiraCommandTestSuite) TestCommitEvidenceJiraCommandCm --jira-base-url https://kosli-test.atlassian.net --jira-username tore@kosli.com --repo-root %s --assert - --build-url example.com %s`, suite.tmpDir, suite.defaultKosliArguments), + --build-url http://www.example.com %s`, suite.tmpDir, suite.defaultKosliArguments), goldenRegex: "Error: missing Jira issues from references found in commit message or branch name.*", additionalConfig: jiraTestsAdditionalConfig{ commitMessage: "SAMI-1 test commit", @@ -193,7 +193,7 @@ func (suite *CommitEvidenceJiraCommandTestSuite) TestCommitEvidenceJiraCommandCm --jira-base-url https://kosli-test.atlassian.net --jira-username tore@kosli.com --repo-root %s --assert - --build-url example.com %s`, suite.tmpDir, suite.defaultKosliArguments), + --build-url http://www.example.com %s`, suite.tmpDir, suite.defaultKosliArguments), goldenRegex: "Error: no Jira references are found in commit message or branch name", additionalConfig: jiraTestsAdditionalConfig{ commitMessage: "test commit without reference", diff --git a/cmd/kosli/reportEvidenceCommitPRAzure_test.go b/cmd/kosli/reportEvidenceCommitPRAzure_test.go index 28ae7dab..3c06d71c 100644 --- a/cmd/kosli/reportEvidenceCommitPRAzure_test.go +++ b/cmd/kosli/reportEvidenceCommitPRAzure_test.go @@ -36,14 +36,14 @@ func (suite *CommitEvidencePRAzureCommandTestSuite) TestCommitEvidencePRAzureCmd { name: "report Azure PR evidence works", cmd: `report evidence commit pullrequest azure --name az-pr --flows ` + suite.flowNames + ` - --build-url example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, + --build-url http://www.example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, goldenRegex: "found 1 pull request\\(s\\) for commit: 5f61be8f00a01c84e491922a630c9a418c684c7a\nazure pull request evidence is reported to commit: 5f61be8f00a01c84e491922a630c9a418c684c7a\n", }, { wantError: true, name: "report Azure PR evidence fails when --org is missing", cmd: `report evidence commit pullrequest azure --name az-pr --flows ` + suite.flowNames + ` - --build-url example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a --api-token foo --host bar`, + --build-url http://www.example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a --api-token foo --host bar`, goldenRegex: "Error: --org is not set\n" + "Usage: kosli report evidence commit pullrequest azure \\[flags\\]\n", }, @@ -51,41 +51,41 @@ func (suite *CommitEvidencePRAzureCommandTestSuite) TestCommitEvidencePRAzureCmd wantError: true, name: "report Azure PR evidence fails when --name is missing", cmd: `report evidence commit pullrequest azure --flows ` + suite.flowNames + ` --azure-org-url https://dev.azure.com/kosli --project kosli-azure - --build-url example.com --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, + --build-url http://www.example.com --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"name\" not set\n", }, { wantError: true, name: "report Azure PR evidence fails when --azure-org-url is missing", cmd: `report evidence commit pullrequest azure --name az-pr --flows ` + suite.flowNames + ` - --build-url example.com --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, + --build-url http://www.example.com --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"azure-org-url\" not set\n", }, { wantError: true, name: "report Azure PR evidence fails when --project is missing", cmd: `report evidence commit pullrequest azure --name az-pr --flows ` + suite.flowNames + ` - --build-url example.com --azure-org-url https://dev.azure.com/kosli --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, + --build-url http://www.example.com --azure-org-url https://dev.azure.com/kosli --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"project\" not set\n", }, { wantError: true, name: "report Azure PR evidence fails when --repository is missing", cmd: `report evidence commit pullrequest azure --name az-pr --flows ` + suite.flowNames + ` - --build-url example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, + --build-url http://www.example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"repository\" not set\n", }, { wantError: true, name: "report Azure PR evidence fails when --commit is missing", cmd: `report evidence commit pullrequest azure --name az-pr --flows ` + suite.flowNames + ` - --build-url example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli` + suite.defaultKosliArguments, + --build-url http://www.example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"commit\" not set\n", }, { name: "report Azure PR evidence does not fail when commit does not exist, empty evidence is reported instead", cmd: `report evidence commit pullrequest azure --name az-pr --flows ` + suite.flowNames + ` - --build-url example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 1111111111111111111111111111111111111111` + suite.defaultKosliArguments, + --build-url http://www.example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 1111111111111111111111111111111111111111` + suite.defaultKosliArguments, goldenRegex: "found 0 pull request\\(s\\) for commit: 1111111111111111111111111111111111111111\n" + "azure pull request evidence is reported to commit: 1111111111111111111111111111111111111111\n", }, @@ -93,13 +93,13 @@ func (suite *CommitEvidencePRAzureCommandTestSuite) TestCommitEvidencePRAzureCmd wantError: true, name: "report Azure PR evidence fails when --assert is used and commit has no PRs", cmd: `report evidence commit pullrequest azure --name az-pr --flows ` + suite.flowNames + ` --assert - --build-url example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 1a877d0c3cf4644b4225bf3eb23ced26818d685a` + suite.defaultKosliArguments, + --build-url http://www.example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 1a877d0c3cf4644b4225bf3eb23ced26818d685a` + suite.defaultKosliArguments, goldenRegex: "found 0 pull request\\(s\\) for commit: .*\nazure pull request evidence is reported to commit: .*\nError: assert failed: no pull request found for the given commit: .*\n", }, { name: "report Azure PR evidence does not fail when commit has no PRs", cmd: `report evidence commit pullrequest azure --name az-pr --flows ` + suite.flowNames + ` - --build-url example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 1a877d0c3cf4644b4225bf3eb23ced26818d685a` + suite.defaultKosliArguments, + --build-url http://www.example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 1a877d0c3cf4644b4225bf3eb23ced26818d685a` + suite.defaultKosliArguments, goldenRegex: "found 0 pull request\\(s\\) for commit: .*\nazure pull request evidence is reported to commit: .*\n", }, { @@ -107,7 +107,7 @@ func (suite *CommitEvidencePRAzureCommandTestSuite) TestCommitEvidencePRAzureCmd name: "report Azure PR evidence fails when --user-data is not found", cmd: `report evidence commit pullrequest azure --name az-pr --flows ` + suite.flowNames + ` --user-data non-existing.json - --build-url example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, + --build-url http://www.example.com --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit 5f61be8f00a01c84e491922a630c9a418c684c7a` + suite.defaultKosliArguments, goldenRegex: "Error: open non-existing.json: no such file or directory\n", }, } diff --git a/cmd/kosli/reportEvidenceCommitPRBitbucket_test.go b/cmd/kosli/reportEvidenceCommitPRBitbucket_test.go index 04628a85..c089b368 100644 --- a/cmd/kosli/reportEvidenceCommitPRBitbucket_test.go +++ b/cmd/kosli/reportEvidenceCommitPRBitbucket_test.go @@ -36,14 +36,14 @@ func (suite *CommitEvidencePRBitbucketCommandTestSuite) TestCommitEvidencePRBitb { name: "report Bitbucket PR evidence works", cmd: `report evidence commit pullrequest bitbucket --name bb-pr --flows ` + suite.flowNames + ` - --build-url example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, goldenRegex: "found 1 pull request\\(s\\) for commit: 2492011ef04a9da09d35be706cf6a4c5bc6f1e69\nbitbucket pull request evidence is reported to commit: 2492011ef04a9da09d35be706cf6a4c5bc6f1e69\n", }, { wantError: true, name: "report Bitbucket PR evidence fails when --org is missing", cmd: `report evidence commit pullrequest bitbucket --name bb-pr --flows ` + suite.flowNames + ` - --build-url example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69 --api-token foo --host bar`, + --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69 --api-token foo --host bar`, goldenRegex: "Error: --org is not set\n" + "Usage: kosli report evidence commit pullrequest bitbucket \\[flags\\]\n", }, @@ -51,35 +51,35 @@ func (suite *CommitEvidencePRBitbucketCommandTestSuite) TestCommitEvidencePRBitb wantError: true, name: "report Bitbucket PR evidence fails when --name is missing", cmd: `report evidence commit pullrequest bitbucket --flows ` + suite.flowNames + ` - --build-url example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"name\" not set\n", }, { wantError: true, name: "report Bitbucket PR evidence fails when --bitbucket-username is missing", cmd: `report evidence commit pullrequest bitbucket --name bb-pr --flows ` + suite.flowNames + ` - --build-url example.com --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"bitbucket-username\" not set\n", }, { wantError: true, name: "report Bitbucket PR evidence fails when --repository is missing", cmd: `report evidence commit pullrequest bitbucket --name bb-pr --flows ` + suite.flowNames + ` - --build-url example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"repository\" not set\n", }, { wantError: true, name: "report Bitbucket PR evidence fails when --commit is missing", cmd: `report evidence commit pullrequest bitbucket --name bb-pr --flows ` + suite.flowNames + ` - --build-url example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"commit\" not set\n", }, { wantError: true, name: "report Bitbucket PR evidence fails when commit does not exist", cmd: `report evidence commit pullrequest bitbucket --name bb-pr --flows ` + suite.flowNames + ` - --build-url example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 73d7fee2f31ade8e1a9c456c324255212c3123ab` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 73d7fee2f31ade8e1a9c456c324255212c3123ab` + suite.defaultKosliArguments, goldenRegex: "Error: map\\[error:map\\[message:Resource not found\\] type:error\\]\n", }, { @@ -87,13 +87,13 @@ func (suite *CommitEvidencePRBitbucketCommandTestSuite) TestCommitEvidencePRBitb name: "report Bitbucket PR evidence fails when --assert is used and commit has no PRs", cmd: `report evidence commit pullrequest bitbucket --name bb-pr --flows ` + suite.flowNames + ` --assert - --build-url example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit cb6ec5fcbb25b1ebe4859d35ab7995ab973f894c` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit cb6ec5fcbb25b1ebe4859d35ab7995ab973f894c` + suite.defaultKosliArguments, goldenRegex: "found 0 pull request\\(s\\) for commit: .*\nbitbucket pull request evidence is reported to commit: .*\nError: assert failed: no pull request found for the given commit: .*\n", }, { name: "report Bitbucket PR evidence does not fail when commit has no PRs", cmd: `report evidence commit pullrequest bitbucket --name bb-pr --flows ` + suite.flowNames + ` - --build-url example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit cb6ec5fcbb25b1ebe4859d35ab7995ab973f894c` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit cb6ec5fcbb25b1ebe4859d35ab7995ab973f894c` + suite.defaultKosliArguments, goldenRegex: "found 0 pull request\\(s\\) for commit: cb6ec5fcbb25b1ebe4859d35ab7995ab973f894c\n" + "bitbucket pull request evidence is reported to commit: cb6ec5fcbb25b1ebe4859d35ab7995ab973f894c\n", }, @@ -102,7 +102,7 @@ func (suite *CommitEvidencePRBitbucketCommandTestSuite) TestCommitEvidencePRBitb name: "report Bitbucket PR evidence fails when --user-data is not found", cmd: `report evidence commit pullrequest bitbucket --name bb-pr --flows ` + suite.flowNames + ` --user-data non-existing.json - --build-url example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, goldenRegex: "Error: open non-existing.json: no such file or directory\n", }, } diff --git a/cmd/kosli/reportEvidenceCommitPRGithub_test.go b/cmd/kosli/reportEvidenceCommitPRGithub_test.go index de149e22..81ddeebf 100644 --- a/cmd/kosli/reportEvidenceCommitPRGithub_test.go +++ b/cmd/kosli/reportEvidenceCommitPRGithub_test.go @@ -38,14 +38,14 @@ func (suite *CommitEvidencePRGithubCommandTestSuite) TestCommitEvidencePRGithubC { name: "report Github PR evidence works", cmd: `report evidence commit pullrequest github --name gh-pr --flows ` + suite.flowNames + ` - --build-url example.com --github-org kosli-dev --repository cli --commit ` + suite.commitWithPR + suite.defaultKosliArguments, + --build-url http://www.example.com --github-org kosli-dev --repository cli --commit ` + suite.commitWithPR + suite.defaultKosliArguments, goldenRegex: "found 1 pull request\\(s\\) for commit: e21a8afff429e0c87ee523d683f2438113f0a105\ngithub pull request evidence is reported to commit: e21a8afff429e0c87ee523d683f2438113f0a105\n", }, { wantError: true, name: "report Github PR evidence fails when --org is missing", cmd: `report evidence commit pullrequest github --name gh-pr --flows ` + suite.flowNames + ` - --build-url example.com --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6 --api-token foo --host bar`, + --build-url http://www.example.com --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6 --api-token foo --host bar`, goldenRegex: "Error: --org is not set\n" + "Usage: kosli report evidence commit pullrequest github \\[flags\\]\n", }, @@ -53,48 +53,48 @@ func (suite *CommitEvidencePRGithubCommandTestSuite) TestCommitEvidencePRGithubC wantError: true, name: "report Github PR evidence fails when --name is missing", cmd: `report evidence commit pullrequest github --flows ` + suite.flowNames + ` --github-org kosli-dev - --build-url example.com --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, + --build-url http://www.example.com --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"name\" not set\n", }, { wantError: true, name: "report Github PR evidence fails when --github-org is missing", cmd: `report evidence commit pullrequest github --name gh-pr --flows ` + suite.flowNames + ` - --build-url example.com --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, + --build-url http://www.example.com --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"github-org\" not set\n", }, { wantError: true, name: "report Github PR evidence fails when --repository is missing", cmd: `report evidence commit pullrequest github --name gh-pr --flows ` + suite.flowNames + ` - --build-url example.com --github-org kosli-dev --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, + --build-url http://www.example.com --github-org kosli-dev --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"repository\" not set\n", }, { wantError: true, name: "report Github PR evidence fails when --commit is missing", cmd: `report evidence commit pullrequest github --name gh-pr --flows ` + suite.flowNames + ` - --build-url example.com --github-org kosli-dev --repository cli` + suite.defaultKosliArguments, + --build-url http://www.example.com --github-org kosli-dev --repository cli` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"commit\" not set\n", }, { wantError: true, name: "report Github PR evidence fails when commit does not exist", cmd: `report evidence commit pullrequest github --name gh-pr --flows ` + suite.flowNames + ` - --build-url example.com --github-org kosli-dev --repository cli --commit 1111111111111111111111111111111111111111` + suite.defaultKosliArguments, + --build-url http://www.example.com --github-org kosli-dev --repository cli --commit 1111111111111111111111111111111111111111` + suite.defaultKosliArguments, goldenRegex: "Error: GET https://api.github.com/repos/kosli-dev/cli/commits/1111111111111111111111111111111111111111/pulls: 422 No commit found for SHA: 1111111111111111111111111111111111111111 \\[\\]\n", }, { wantError: true, name: "report Github PR evidence fails when --assert is used and commit has no PRs", cmd: `report evidence commit pullrequest github --name gh-pr --flows ` + suite.flowNames + ` --assert - --build-url example.com --github-org kosli-dev --repository cli --commit 9bca2c44eaf221a79fb18a1a11bdf2997adaf870` + suite.defaultKosliArguments, + --build-url http://www.example.com --github-org kosli-dev --repository cli --commit 9bca2c44eaf221a79fb18a1a11bdf2997adaf870` + suite.defaultKosliArguments, goldenRegex: "found 0 pull request\\(s\\) for commit: .*\ngithub pull request evidence is reported to commit: .*\nError: assert failed: no pull request found for the given commit: .*\n", }, { name: "report Github PR evidence does not fail when commit has no PRs", cmd: `report evidence commit pullrequest github --name gh-pr --flows ` + suite.flowNames + ` - --build-url example.com --github-org kosli-dev --repository cli --commit 9bca2c44eaf221a79fb18a1a11bdf2997adaf870` + suite.defaultKosliArguments, + --build-url http://www.example.com --github-org kosli-dev --repository cli --commit 9bca2c44eaf221a79fb18a1a11bdf2997adaf870` + suite.defaultKosliArguments, goldenRegex: "found 0 pull request\\(s\\) for commit: 9bca2c44eaf221a79fb18a1a11bdf2997adaf870\n" + "github pull request evidence is reported to commit: 9bca2c44eaf221a79fb18a1a11bdf2997adaf870\n", }, @@ -103,13 +103,13 @@ func (suite *CommitEvidencePRGithubCommandTestSuite) TestCommitEvidencePRGithubC name: "report Github PR evidence fails when --user-data is not found", cmd: `report evidence commit pullrequest github --name gh-pr --flows ` + suite.flowNames + ` --user-data non-existing.json - --build-url example.com --github-org kosli-dev --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, + --build-url http://www.example.com --github-org kosli-dev --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, goldenRegex: "Error: open non-existing.json: no such file or directory\n", }, { name: "report Github PR evidence works with --repository=owner/repo", cmd: `report evidence commit pullrequest github --name gh-pr --flows ` + suite.flowNames + ` - --build-url example.com --github-org kosli-dev --repository kosli-dev/cli --commit ` + suite.commitWithPR + suite.defaultKosliArguments, + --build-url http://www.example.com --github-org kosli-dev --repository kosli-dev/cli --commit ` + suite.commitWithPR + suite.defaultKosliArguments, goldenRegex: "found 1 pull request\\(s\\) for commit: e21a8afff429e0c87ee523d683f2438113f0a105\ngithub pull request evidence is reported to commit: e21a8afff429e0c87ee523d683f2438113f0a105\n", }, } diff --git a/cmd/kosli/reportEvidenceCommitPRGitlab_test.go b/cmd/kosli/reportEvidenceCommitPRGitlab_test.go index 1dec2144..a443df2d 100644 --- a/cmd/kosli/reportEvidenceCommitPRGitlab_test.go +++ b/cmd/kosli/reportEvidenceCommitPRGitlab_test.go @@ -36,28 +36,28 @@ func (suite *CommitEvidencePRGitlabCommandTestSuite) TestCommitEvidencePRGitlabC { name: "report Gitlab PR evidence works when no merge requests are found", cmd: `report evidence commit pullrequest gitlab --name gl-pr --flows ` + suite.flowName + ` - --build-url example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit 2ec23dda01fc85e3f94a2b5ea8cb8cf7e79c4ed6` + suite.defaultKosliArguments, + --build-url http://www.example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit 2ec23dda01fc85e3f94a2b5ea8cb8cf7e79c4ed6` + suite.defaultKosliArguments, goldenRegex: "found 0 merge request\\(s\\) for commit: 2ec23dda01fc85e3f94a2b5ea8cb8cf7e79c4ed6\n" + "gitlab merge request evidence is reported to commit: 2ec23dda01fc85e3f94a2b5ea8cb8cf7e79c4ed6\n", }, { name: "report Gitlab PR evidence works when there are merge requests", cmd: `report evidence commit pullrequest gitlab --name gl-pr --flows ` + suite.flowName + ` - --build-url example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit e6510880aecdc05d79104d937e1adb572bd91911` + suite.defaultKosliArguments, + --build-url http://www.example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit e6510880aecdc05d79104d937e1adb572bd91911` + suite.defaultKosliArguments, goldenRegex: "found 1 merge request\\(s\\) for commit: e6510880aecdc05d79104d937e1adb572bd91911\ngitlab merge request evidence is reported to commit: e6510880aecdc05d79104d937e1adb572bd91911\n", }, { wantError: true, name: "report Gitlab PR evidence fails when --name is missing", cmd: `report evidence commit pullrequest gitlab --flows ` + suite.flowName + ` - --build-url example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit e6510880aecdc05d79104d937e1adb572bd91911` + suite.defaultKosliArguments, + --build-url http://www.example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit e6510880aecdc05d79104d937e1adb572bd91911` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"name\" not set\n", }, { wantError: true, name: "report Gitlab PR evidence fails when --org is missing", cmd: `report evidence commit pullrequest gitlab --name gl-pr --flows ` + suite.flowName + ` - --build-url example.com --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6 --api-token foo --host bar`, + --build-url http://www.example.com --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6 --api-token foo --host bar`, goldenRegex: "Error: --org is not set\n" + "Usage: kosli report evidence commit pullrequest gitlab \\[flags\\]\n", }, @@ -65,28 +65,28 @@ func (suite *CommitEvidencePRGitlabCommandTestSuite) TestCommitEvidencePRGitlabC wantError: true, name: "report Gitlab PR evidence fails when --gitlab-org is missing", cmd: `report evidence commit pullrequest gitlab --name gl-pr --flows ` + suite.flowName + ` - --build-url example.com --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, + --build-url http://www.example.com --repository cli --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"gitlab-org\" not set\n", }, { wantError: true, name: "report Gitlab PR evidence fails when --repository is missing", cmd: `report evidence commit pullrequest gitlab --name gl-pr --flows ` + suite.flowName + ` - --build-url example.com --gitlab-org kosli-dev --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, + --build-url http://www.example.com --gitlab-org kosli-dev --commit 73d7fee2f31ade8e1a9c456c324255212c30c2a6` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"repository\" not set\n", }, { wantError: true, name: "report Gitlab PR evidence fails when --commit is missing", cmd: `report evidence commit pullrequest gitlab --name gl-pr --flows ` + suite.flowName + ` - --build-url example.com --gitlab-org kosli-dev --repository cli` + suite.defaultKosliArguments, + --build-url http://www.example.com --gitlab-org kosli-dev --repository cli` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"commit\" not set\n", }, { wantError: true, name: "report Gitlab PR evidence fails when commit does not exist", cmd: `report evidence commit pullrequest gitlab --name gl-pr --flows ` + suite.flowName + ` - --build-url example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit 73d7fee2f31ade8e1a9c456c324255212c3123ab` + suite.defaultKosliArguments, + --build-url http://www.example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit 73d7fee2f31ade8e1a9c456c324255212c3123ab` + suite.defaultKosliArguments, goldenRegex: "Error: GET https://gitlab.com/api/v4/projects/ewelinawilkosz/merkely-gitlab-demo/repository/commits/73d7fee2f31ade8e1a9c456c324255212c3123ab/merge_requests: 404 {message: 404 Commit Not Found}\n", }, { @@ -94,7 +94,7 @@ func (suite *CommitEvidencePRGitlabCommandTestSuite) TestCommitEvidencePRGitlabC name: "report Gitlab PR evidence fails when --assert is used and commit has no PRs", cmd: `report evidence commit pullrequest gitlab --name gl-pr --flows ` + suite.flowName + ` --assert - --build-url example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit 2ec23dda01fc85e3f94a2b5ea8cb8cf7e79c4ed6` + suite.defaultKosliArguments, + --build-url http://www.example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit 2ec23dda01fc85e3f94a2b5ea8cb8cf7e79c4ed6` + suite.defaultKosliArguments, goldenRegex: "found 0 merge request\\(s\\) for commit: .*\ngitlab merge request evidence is reported to commit: .*\nError: assert failed: no merge request found for the given commit: .*\n", }, { @@ -102,7 +102,7 @@ func (suite *CommitEvidencePRGitlabCommandTestSuite) TestCommitEvidencePRGitlabC name: "report Gitlab PR evidence fails when --user-data is not found", cmd: `report evidence commit pullrequest gitlab --name gl-pr --flows ` + suite.flowName + ` --user-data non-existing.json - --build-url example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit e6510880aecdc05d79104d937e1adb572bd91911` + suite.defaultKosliArguments, + --build-url http://www.example.com --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo --commit e6510880aecdc05d79104d937e1adb572bd91911` + suite.defaultKosliArguments, goldenRegex: "Error: open non-existing.json: no such file or directory\n", }, } diff --git a/cmd/kosli/reportEvidenceCommitSnyk_test.go b/cmd/kosli/reportEvidenceCommitSnyk_test.go index 14dad715..aaaab09a 100644 --- a/cmd/kosli/reportEvidenceCommitSnyk_test.go +++ b/cmd/kosli/reportEvidenceCommitSnyk_test.go @@ -33,41 +33,41 @@ func (suite *CommitEvidenceSnykCommandTestSuite) TestCommitEvidenceSnykCmd() { { name: "report Snyk test evidence works", cmd: `report evidence commit snyk --commit 239d7cee00ca341f124fa710fc694b67cdf8011b --name snyk-result --flows ` + suite.flowName + ` - --build-url example.com --scan-results testdata/snyk_scan_example.json` + suite.defaultKosliArguments, + --build-url http://www.example.com --scan-results testdata/snyk_scan_example.json` + suite.defaultKosliArguments, goldenRegex: "snyk scan evidence is reported to commit: 239d7cee00ca341f124fa710fc694b67cdf8011b\n", }, { name: "report Snyk test evidence works when --evidence-url and --evidence-fingerprint are provided", cmd: `report evidence commit snyk --commit 239d7cee00ca341f124fa710fc694b67cdf8011b --name snyk-result --flows ` + suite.flowName + ` - --build-url example.com --scan-results testdata/snyk_scan_example.json - --evidence-url https://example.com --evidence-fingerprint 847411c6124e719a4e8da2550ac5c116b7ff930493ce8a061486b48db8a5aaa0` + suite.defaultKosliArguments, + --build-url http://www.example.com --scan-results testdata/snyk_scan_example.json + --evidence-url https://http://www.example.com --evidence-fingerprint 847411c6124e719a4e8da2550ac5c116b7ff930493ce8a061486b48db8a5aaa0` + suite.defaultKosliArguments, goldenRegex: "snyk scan evidence is reported to commit: 239d7cee00ca341f124fa710fc694b67cdf8011b\n", }, { name: "report Snyk scan evidence with non-existing scan-results", cmd: `report evidence commit snyk --commit 239d7cee00ca341f124fa710fc694b67cdf8011b --name snyk-result --flows ` + suite.flowName + ` - --build-url example.com --scan-results testdata/foo.json` + suite.defaultKosliArguments, + --build-url http://www.example.com --scan-results testdata/foo.json` + suite.defaultKosliArguments, wantError: true, goldenRegex: "Error: failed to parse Snyk results file \\[testdata\\/foo.json\\]. Failed to parse as Sarif: open testdata\\/foo.json: no such file or directory. Fallen back to parse Snyk Json, but also failed: the provided file path doesn't have a file\n", }, { name: "report Snyk scan evidence with missing scan-results flag", cmd: `report evidence commit snyk --commit 239d7cee00ca341f124fa710fc694b67cdf8011b --name snyk-result --flows ` + suite.flowName + ` - --build-url example.com` + suite.defaultKosliArguments, + --build-url http://www.example.com` + suite.defaultKosliArguments, wantError: true, goldenRegex: "Error: required flag\\(s\\) \"scan-results\" not set\n", }, { name: "report Snyk scan evidence with missing name flag", cmd: `report evidence commit snyk --commit 239d7cee00ca341f124fa710fc694b67cdf8011b --flows ` + suite.flowName + ` - --build-url example.com --scan-results testdata/snyk_scan_example.json` + suite.defaultKosliArguments, + --build-url http://www.example.com --scan-results testdata/snyk_scan_example.json` + suite.defaultKosliArguments, wantError: true, goldenRegex: "Error: required flag\\(s\\) \"name\" not set\n", }, { name: "report Snyk scan evidence with a missing --flows flag works", cmd: `report evidence commit snyk --commit 239d7cee00ca341f124fa710fc694b67cdf8011b --name snyk-result - --build-url example.com --scan-results testdata/snyk_scan_example.json` + suite.defaultKosliArguments, + --build-url http://www.example.com --scan-results testdata/snyk_scan_example.json` + suite.defaultKosliArguments, goldenRegex: "snyk scan evidence is reported to commit: 239d7cee00ca341f124fa710fc694b67cdf8011b\n", }, { @@ -80,13 +80,13 @@ func (suite *CommitEvidenceSnykCommandTestSuite) TestCommitEvidenceSnykCmd() { { name: "report Snyk scan with a sarif file and upload it", cmd: `report evidence commit snyk --commit 239d7cee00ca341f124fa710fc694b67cdf8011b --name snyk-result - --build-url example.com --scan-results testdata/snyk_sarif.json` + suite.defaultKosliArguments, + --build-url http://www.example.com --scan-results testdata/snyk_sarif.json` + suite.defaultKosliArguments, goldenRegex: "snyk scan evidence is reported to commit: 239d7cee00ca341f124fa710fc694b67cdf8011b\n", }, { name: "report Snyk scan with a sarif file and DO NOT upload it", cmd: `report evidence commit snyk --commit 239d7cee00ca341f124fa710fc694b67cdf8011b --name snyk-result - --build-url example.com --scan-results testdata/snyk_sarif.json --upload-results=false` + suite.defaultKosliArguments, + --build-url http://www.example.com --scan-results testdata/snyk_sarif.json --upload-results=false` + suite.defaultKosliArguments, goldenRegex: "snyk scan evidence is reported to commit: 239d7cee00ca341f124fa710fc694b67cdf8011b\n", }, }