From 132818f927a2cda7487421cd652afa6f8ce9524d Mon Sep 17 00:00:00 2001 From: Keith Zantow Date: Fri, 9 Feb 2024 14:41:50 -0500 Subject: [PATCH 1/3] fix: ensure version output to stdout Signed-off-by: Keith Zantow --- go.mod | 6 +++--- go.sum | 12 ++++++------ test/cli/trait_assertions_test.go | 7 +++++++ test/cli/version_cmd_test.go | 30 ++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 9 deletions(-) create mode 100644 test/cli/version_cmd_test.go diff --git a/go.mod b/go.mod index 166f9f12749..8e253cbdd99 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d github.com/adrg/xdg v0.4.0 github.com/anchore/bubbly v0.0.0-20231115134915-def0aba654a9 - github.com/anchore/clio v0.0.0-20240131202212-9eba61247448 + github.com/anchore/clio v0.0.0-20240209191000-1e2e1c5d7050 github.com/anchore/go-logger v0.0.0-20230725134548-c21dafa1ec5a github.com/anchore/go-testutils v0.0.0-20200925183923-d5f45b0d3c04 github.com/anchore/go-version v1.2.2-0.20210903204242-51efa5b487c4 @@ -238,8 +238,8 @@ require ( golang.org/x/net v0.20.0 // indirect golang.org/x/oauth2 v0.15.0 // indirect golang.org/x/sync v0.5.0 // indirect - golang.org/x/sys v0.16.0 // indirect - golang.org/x/term v0.16.0 // indirect + golang.org/x/sys v0.17.0 // indirect + golang.org/x/term v0.17.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.5.0 // indirect golang.org/x/tools v0.13.0 // indirect diff --git a/go.sum b/go.sum index 0bb937faa30..d4280605a7d 100644 --- a/go.sum +++ b/go.sum @@ -235,8 +235,8 @@ github.com/anchore/archiver/v3 v3.5.2 h1:Bjemm2NzuRhmHy3m0lRe5tNoClB9A4zYyDV58Pa github.com/anchore/archiver/v3 v3.5.2/go.mod h1:e3dqJ7H78uzsRSEACH1joayhuSyhnonssnDhppzS1L4= github.com/anchore/bubbly v0.0.0-20231115134915-def0aba654a9 h1:p0ZIe0htYOX284Y4axJaGBvXHU0VCCzLN5Wf5XbKStU= github.com/anchore/bubbly v0.0.0-20231115134915-def0aba654a9/go.mod h1:3ZsFB9tzW3vl4gEiUeuSOMDnwroWxIxJelOOHUp8dSw= -github.com/anchore/clio v0.0.0-20240131202212-9eba61247448 h1:ZgecmkxhH5im+9jPs7Ra1Thmv/p4IBDsoCFD6W8pENg= -github.com/anchore/clio v0.0.0-20240131202212-9eba61247448/go.mod h1:t5Mld8naKcG8RTPjW/2n7bfyBKFl1A6PvtXw+v64gK0= +github.com/anchore/clio v0.0.0-20240209191000-1e2e1c5d7050 h1:Edh572jd+zntYOop8Q4Nx6pYtCHwxz5sLeMP0XkFkog= +github.com/anchore/clio v0.0.0-20240209191000-1e2e1c5d7050/go.mod h1:8Jr7CjmwFVcBPtkJdTpaAGHimoGJGfbExypjzOu87Og= github.com/anchore/fangs v0.0.0-20231201140849-5075d28d6d8b h1:L/djgY7ZbZ/38+wUtdkk398W3PIBJLkt1N8nU/7e47A= github.com/anchore/fangs v0.0.0-20231201140849-5075d28d6d8b/go.mod h1:TLcE0RE5+8oIx2/NPWem/dq1DeaMoC+fPEH7hoSzPLo= github.com/anchore/go-logger v0.0.0-20230725134548-c21dafa1ec5a h1:nJ2G8zWKASyVClGVgG7sfM5mwoZlZ2zYpIzN2OhjWkw= @@ -1320,16 +1320,16 @@ golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= -golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE= -golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY= +golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U= +golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/test/cli/trait_assertions_test.go b/test/cli/trait_assertions_test.go index 9681c91e154..8aa14b09850 100644 --- a/test/cli/trait_assertions_test.go +++ b/test/cli/trait_assertions_test.go @@ -9,6 +9,13 @@ import ( type traitAssertion func(tb testing.TB, stdout, stderr string, rc int) +func assertNoStderr(tb testing.TB, _, stderr string, _ int) { + tb.Helper() + if len(stderr) > 0 { + tb.Errorf("expected stderr to be empty, but wasn't") + } +} + func assertInOutput(data string) traitAssertion { return func(tb testing.TB, stdout, stderr string, _ int) { tb.Helper() diff --git a/test/cli/version_cmd_test.go b/test/cli/version_cmd_test.go new file mode 100644 index 00000000000..c043c8e08a0 --- /dev/null +++ b/test/cli/version_cmd_test.go @@ -0,0 +1,30 @@ +package cli + +import ( + "testing" +) + +func TestVersionCmdPrintsToStdout(t *testing.T) { + tests := []struct { + name string + env map[string]string + assertions []traitAssertion + }{ + { + name: "version command prints to stdout", + assertions: []traitAssertion{ + assertInOutput("Version:"), + assertNoStderr, + }, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + pkgCmd, pkgsStdout, pkgsStderr := runGrype(t, test.env, "version") + for _, traitFn := range test.assertions { + traitFn(t, pkgsStdout, pkgsStderr, pkgCmd.ProcessState.ExitCode()) + } + }) + } +} From a575413111fdca6a5bb2e4765596292dd0022311 Mon Sep 17 00:00:00 2001 From: Keith Zantow Date: Fri, 9 Feb 2024 15:38:26 -0500 Subject: [PATCH 2/3] chore: comment out invalid test Signed-off-by: Keith Zantow --- test/cli/cmd_test.go | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/test/cli/cmd_test.go b/test/cli/cmd_test.go index f37d9d1b9fc..36cabe5d2b9 100644 --- a/test/cli/cmd_test.go +++ b/test/cli/cmd_test.go @@ -41,23 +41,24 @@ func TestCmd(t *testing.T) { assertInOutput("sha256:1ee006886991ad4689838d3a288e0dd3fd29b70e276622f16b67a8922831a853"), // linux/arm64 image digest }, }, - { - name: "responds-to-search-options", - args: []string{"--help"}, - env: map[string]string{ - "GRYPE_SEARCH_UNINDEXED_ARCHIVES": "true", - "GRYPE_SEARCH_INDEXED_ARCHIVES": "false", - "GRYPE_SEARCH_SCOPE": "all-layers", - }, - assertions: []traitAssertion{ - // the application config in the log matches that of what we expect to have been configured. Note: - // we are not testing further wiring of this option, only that the config responds to - // package-cataloger-level options. - assertInOutput("unindexed-archives: true"), - assertInOutput("indexed-archives: false"), - assertInOutput("scope: 'all-layers'"), - }, - }, + // TODO: uncomment this test when we can use `grype config` + //{ + // name: "responds-to-search-options", + // args: []string{"--help"}, + // env: map[string]string{ + // "GRYPE_SEARCH_UNINDEXED_ARCHIVES": "true", + // "GRYPE_SEARCH_INDEXED_ARCHIVES": "false", + // "GRYPE_SEARCH_SCOPE": "all-layers", + // }, + // assertions: []traitAssertion{ + // // the application config in the log matches that of what we expect to have been configured. Note: + // // we are not testing further wiring of this option, only that the config responds to + // // package-cataloger-level options. + // assertInOutput("unindexed-archives: true"), + // assertInOutput("indexed-archives: false"), + // assertInOutput("scope: 'all-layers'"), + // }, + //}, { name: "vulnerabilities in output on -f with failure", args: []string{"registry:busybox:1.31", "-f", "high", "--platform", "linux/amd64"}, From cc367822b76e32ad7ab43fa0e53560440ca5826e Mon Sep 17 00:00:00 2001 From: Keith Zantow Date: Fri, 9 Feb 2024 15:50:28 -0500 Subject: [PATCH 3/3] chore: update clio Signed-off-by: Keith Zantow --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 8e253cbdd99..0c25db3fc4f 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d github.com/adrg/xdg v0.4.0 github.com/anchore/bubbly v0.0.0-20231115134915-def0aba654a9 - github.com/anchore/clio v0.0.0-20240209191000-1e2e1c5d7050 + github.com/anchore/clio v0.0.0-20240209204744-cb94e40a4f65 github.com/anchore/go-logger v0.0.0-20230725134548-c21dafa1ec5a github.com/anchore/go-testutils v0.0.0-20200925183923-d5f45b0d3c04 github.com/anchore/go-version v1.2.2-0.20210903204242-51efa5b487c4 diff --git a/go.sum b/go.sum index d4280605a7d..fdbce7647f3 100644 --- a/go.sum +++ b/go.sum @@ -235,8 +235,8 @@ github.com/anchore/archiver/v3 v3.5.2 h1:Bjemm2NzuRhmHy3m0lRe5tNoClB9A4zYyDV58Pa github.com/anchore/archiver/v3 v3.5.2/go.mod h1:e3dqJ7H78uzsRSEACH1joayhuSyhnonssnDhppzS1L4= github.com/anchore/bubbly v0.0.0-20231115134915-def0aba654a9 h1:p0ZIe0htYOX284Y4axJaGBvXHU0VCCzLN5Wf5XbKStU= github.com/anchore/bubbly v0.0.0-20231115134915-def0aba654a9/go.mod h1:3ZsFB9tzW3vl4gEiUeuSOMDnwroWxIxJelOOHUp8dSw= -github.com/anchore/clio v0.0.0-20240209191000-1e2e1c5d7050 h1:Edh572jd+zntYOop8Q4Nx6pYtCHwxz5sLeMP0XkFkog= -github.com/anchore/clio v0.0.0-20240209191000-1e2e1c5d7050/go.mod h1:8Jr7CjmwFVcBPtkJdTpaAGHimoGJGfbExypjzOu87Og= +github.com/anchore/clio v0.0.0-20240209204744-cb94e40a4f65 h1:u9XrEabKlGPsrmRvAER+kUKkwXiJfLyqGhmOTFsXjX4= +github.com/anchore/clio v0.0.0-20240209204744-cb94e40a4f65/go.mod h1:8Jr7CjmwFVcBPtkJdTpaAGHimoGJGfbExypjzOu87Og= github.com/anchore/fangs v0.0.0-20231201140849-5075d28d6d8b h1:L/djgY7ZbZ/38+wUtdkk398W3PIBJLkt1N8nU/7e47A= github.com/anchore/fangs v0.0.0-20231201140849-5075d28d6d8b/go.mod h1:TLcE0RE5+8oIx2/NPWem/dq1DeaMoC+fPEH7hoSzPLo= github.com/anchore/go-logger v0.0.0-20230725134548-c21dafa1ec5a h1:nJ2G8zWKASyVClGVgG7sfM5mwoZlZ2zYpIzN2OhjWkw=