From 9167ad39a65135cac9301d1c945ce858494b9650 Mon Sep 17 00:00:00 2001 From: Ceridwen Driskill Date: Wed, 21 Sep 2022 21:16:33 +0000 Subject: [PATCH 1/9] configuring app for test coverage Signed-off-by: Ceridwen Driskill --- cmd/rekor-cli/main_test.go | 26 ++++++++++++++++++++++++++ cmd/rekor-server/app/root.go | 1 + cmd/rekor-server/app/serve.go | 6 ++++++ cmd/rekor-server/main_test.go | 26 ++++++++++++++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 cmd/rekor-cli/main_test.go create mode 100644 cmd/rekor-server/main_test.go diff --git a/cmd/rekor-cli/main_test.go b/cmd/rekor-cli/main_test.go new file mode 100644 index 000000000..6a11ccbb1 --- /dev/null +++ b/cmd/rekor-cli/main_test.go @@ -0,0 +1,26 @@ +// +// Copyright 2022 The Sigstore Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "testing" + + "github.com/sigstore/rekor/cmd/rekor-cli/app" +) + +func TestCover(t *testing.T) { + app.Execute() +} diff --git a/cmd/rekor-server/app/root.go b/cmd/rekor-server/app/root.go index 0d10b2f38..dd3f23d61 100644 --- a/cmd/rekor-server/app/root.go +++ b/cmd/rekor-server/app/root.go @@ -61,6 +61,7 @@ func init() { rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.rekor-server.yaml)") rootCmd.PersistentFlags().StringVar(&logType, "log_type", "dev", "logger type to use (dev/prod)") rootCmd.PersistentFlags().BoolVar(&enablePprof, "enable_pprof", false, "enable pprof for profiling on port 6060") + rootCmd.PersistentFlags().Bool("enable_killswitch", false, "enable killswitch for TESTING ONLY on port 2112") rootCmd.PersistentFlags().String("trillian_log_server.address", "127.0.0.1", "Trillian log server address") rootCmd.PersistentFlags().Uint16("trillian_log_server.port", 8090, "Trillian log server port") diff --git a/cmd/rekor-server/app/serve.go b/cmd/rekor-server/app/serve.go index 240b64183..bdd217785 100644 --- a/cmd/rekor-server/app/serve.go +++ b/cmd/rekor-server/app/serve.go @@ -114,6 +114,12 @@ var serveCmd = &cobra.Command{ server.ConfigureAPI() http.Handle("/metrics", promhttp.Handler()) + if viper.GetBool("enable_killswitch") { + http.Handle("/kill", http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) { + server.Shutdown() + w.WriteHeader(http.StatusOK) + })) + } go func() { srv := &http.Server{ Addr: ":2112", diff --git a/cmd/rekor-server/main_test.go b/cmd/rekor-server/main_test.go new file mode 100644 index 000000000..8fa9c4e13 --- /dev/null +++ b/cmd/rekor-server/main_test.go @@ -0,0 +1,26 @@ +// +// Copyright 2022 The Sigstore Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "testing" + + "github.com/sigstore/rekor/cmd/rekor-server/app" +) + +func TestCover(t *testing.T) { + app.Execute() +} From 56b0ab0750d51557b953d9d7aff27dc8707447c9 Mon Sep 17 00:00:00 2001 From: Ceridwen Driskill Date: Wed, 21 Sep 2022 21:17:51 +0000 Subject: [PATCH 2/9] update docker files to build and run with coverage Signed-off-by: Ceridwen Driskill --- Dockerfile | 5 +++++ docker-compose.test.yml | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 docker-compose.test.yml diff --git a/Dockerfile b/Dockerfile index 1fa1fcf06..142a08381 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,6 +28,7 @@ ADD ./pkg/ $APP_ROOT/src/pkg/ ARG SERVER_LDFLAGS RUN go build -ldflags "${SERVER_LDFLAGS}" ./cmd/rekor-server RUN CGO_ENABLED=0 go build -gcflags "all=-N -l" -ldflags "${SERVER_LDFLAGS}" -o rekor-server_debug ./cmd/rekor-server +RUN go test -c -ldflags "${SERVER_LDFLAGS}" -cover -covermode=count -coverpkg=./... -o rekor-server_test ./cmd/rekor-server # Multi-Stage production build FROM golang:1.19.1@sha256:2d17ffd12a2cdb25d4a633ad25f8dc29608ed84f31b3b983427d825280427095 as deploy @@ -44,3 +45,7 @@ RUN go install github.com/go-delve/delve/cmd/dlv@v1.8.0 # overwrite server and include debugger COPY --from=builder /opt/app-root/src/rekor-server_debug /usr/local/bin/rekor-server + +FROM deploy as test +# overwrite server with test build with code coverage +COPY --from=builder /opt/app-root/src/rekor-server_test /usr/local/bin/rekor-server diff --git a/docker-compose.test.yml b/docker-compose.test.yml new file mode 100644 index 000000000..dbb2b60ed --- /dev/null +++ b/docker-compose.test.yml @@ -0,0 +1,35 @@ +# +# Copyright 2022 The Sigstore Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +version: '3.4' +services: + rekor-server: + build: + context: . + target: "test" + command: [ + "rekor-server", + "-test.coverprofile=rekor-server.cov", + "serve", + "--trillian_log_server.address=trillian-log-server", + "--trillian_log_server.port=8090", + "--redis_server.address=redis-server", + "--redis_server.port=6379", + "--rekor_server.address=0.0.0.0", + "--rekor_server.signer=memory", + "--enable_attestation_storage", + "--attestation_storage_bucket=file:///var/run/attestations", + "--enable_killswitch", + ] From 57a22cc41f2310fe5ebe81224e12270e30726c86 Mon Sep 17 00:00:00 2001 From: Ceridwen Driskill Date: Wed, 21 Sep 2022 21:22:59 +0000 Subject: [PATCH 3/9] updating tests to account for test coverage output Signed-off-by: Ceridwen Driskill --- tests/apk.go | 3 ++- tests/e2e-test.sh | 22 +++++++++++++++++++--- tests/jar.go | 3 ++- tests/rpm.go | 16 +++------------- tests/util.go | 32 +++++++++++++++++++++++++++++--- 5 files changed, 55 insertions(+), 21 deletions(-) diff --git a/tests/apk.go b/tests/apk.go index dd85dc49a..fbd3672b4 100644 --- a/tests/apk.go +++ b/tests/apk.go @@ -1,3 +1,4 @@ +//go:build e2e // +build e2e // @@ -51,7 +52,7 @@ func createSignedApk(t *testing.T, artifactPath string) { datahash := sha256.Sum256(dataTGZBuf.Bytes()) ctlData := strings.Builder{} - ctlData.WriteString("name = " + randomRpmSuffix()) + ctlData.WriteString("name = " + randomSuffix(16)) ctlData.WriteRune('\n') ctlData.WriteString("datahash = " + hex.EncodeToString(datahash[:])) ctlData.WriteRune('\n') diff --git a/tests/e2e-test.sh b/tests/e2e-test.sh index f930e4b41..98689cfb3 100755 --- a/tests/e2e-test.sh +++ b/tests/e2e-test.sh @@ -17,12 +17,14 @@ set -e testdir=$(dirname "$0") +rm -f /tmp/rekor-*.cov + echo "starting services" -docker-compose up -d +docker-compose -f docker-compose.yml -f docker-compose.test.yml up -d --force-recreate --build echo "building CLI and server" -go build -o rekor-cli ./cmd/rekor-cli -go build -o rekor-server ./cmd/rekor-server +go test -c ./cmd/rekor-cli -o rekor-cli -cover -covermode=count -coverpkg=./... +go test -c ./cmd/rekor-server -o rekor-server -covermode=count -coverpkg=./... count=0 @@ -54,3 +56,17 @@ if docker-compose logs --no-color | grep -q "panic: runtime error:" ; then docker-compose logs --no-color > /tmp/docker-compose.log exit 1 fi + +echo "generating code coverage" +curl -X GET 0.0.0.0:2112/kill +sleep 5 + +if ! docker cp $(docker ps -aqf "name=rekor_rekor-server"):go/rekor-server.cov /tmp/rekor-server.cov ; then + # failed to copy code coverage report from server + echo "Failed to retrieve server code coverage report" + docker-compose logs --no-color > /tmp/docker-compose.log + exit 1 +fi + +gocovmerge /tmp/rekor-*.cov > /tmp/rekor-merged.cov +echo "code coverage $(go tool cover -func=/tmp/rekor-merged.cov | grep -E '^total\:' | sed -E 's/\s+/ /g')" diff --git a/tests/jar.go b/tests/jar.go index fe4f07d89..dcde9659f 100644 --- a/tests/jar.go +++ b/tests/jar.go @@ -13,6 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build e2e // +build e2e package e2e @@ -60,7 +61,7 @@ func createSignedJar(t *testing.T, artifactPath string) { if err != nil { t.Fatal(err) } - randManifest := strings.Replace(manifest, "REPLACE", randomRpmSuffix(), 1) + randManifest := strings.Replace(manifest, "REPLACE", randomSuffix(16), 1) mf.Write([]byte(randManifest)) if err := zw.Close(); err != nil { t.Fatal(err) diff --git a/tests/rpm.go b/tests/rpm.go index db63ce07f..6cc2b3656 100644 --- a/tests/rpm.go +++ b/tests/rpm.go @@ -1,3 +1,4 @@ +//go:build e2e // +build e2e // @@ -20,28 +21,17 @@ package e2e import ( "bytes" "io/ioutil" - "math/rand" "os" "testing" "github.com/google/rpmpack" ) -func randomRpmSuffix() string { - const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" - - b := make([]byte, 16) - for i := range b { - b[i] = letterBytes[rand.Intn(len(letterBytes))] - } - return string(b) -} - func createSignedRpm(t *testing.T, artifactPath string) { t.Helper() rpmMetadata := rpmpack.RPMMetaData{ - Name: "test-rpm-" + randomRpmSuffix(), + Name: "test-rpm-" + randomSuffix(16), Epoch: 0, Version: "1", Release: "2", @@ -57,7 +47,7 @@ func createSignedRpm(t *testing.T, artifactPath string) { data := randomData(t, 100) rpm.AddFile(rpmpack.RPMFile{ - Name: randomRpmSuffix(), + Name: randomSuffix(16), Body: data, Type: rpmpack.GenericFile, Owner: "testOwner", diff --git a/tests/util.go b/tests/util.go index aec3b756d..9961b2a64 100644 --- a/tests/util.go +++ b/tests/util.go @@ -47,6 +47,9 @@ func outputContains(t *testing.T, output, sub string) { func run(t *testing.T, stdin, cmd string, arg ...string) string { t.Helper() + // Coverage flag must be the first arg passed to coverage binary + // No impact when running with regular binary + arg = append([]string{coverageFlag()}, arg...) c := exec.Command(cmd, arg...) if stdin != "" { c.Stdin = strings.NewReader(stdin) @@ -61,7 +64,8 @@ func run(t *testing.T, stdin, cmd string, arg ...string) string { t.Fatal(err) } - return string(b) + // Remove test coverage output + return strings.Split(strings.Split(string(b), "PASS")[0], "FAIL")[0] } func runCli(t *testing.T, arg ...string) string { @@ -76,6 +80,9 @@ func runCli(t *testing.T, arg ...string) string { func runCliStdout(t *testing.T, arg ...string) string { t.Helper() + // Coverage flag must be the first arg passed to coverage binary + // No impact when running with regular binary + arg = append([]string{coverageFlag()}, arg...) arg = append(arg, rekorServerFlag()) c := exec.Command(cli, arg...) @@ -88,11 +95,15 @@ func runCliStdout(t *testing.T, arg ...string) string { t.Log(string(b)) t.Fatal(err) } - return string(b) + // Remove test coverage output + return strings.Split(strings.Split(string(b), "PASS")[0], "FAIL")[0] } func runCliErr(t *testing.T, arg ...string) string { t.Helper() + // Coverage flag must be the first arg passed to coverage binary + // No impact when running with regular binary + arg = append([]string{coverageFlag()}, arg...) arg = append(arg, rekorServerFlag()) // use a blank config file to ensure no collision if os.Getenv("REKORTMPDIR") != "" { @@ -104,7 +115,8 @@ func runCliErr(t *testing.T, arg ...string) string { t.Log(string(b)) t.Fatalf("expected error, got %s", string(b)) } - return string(b) + // Remove test coverage output + return strings.Split(strings.Split(string(b), "PASS")[0], "FAIL")[0] } func rekorServerFlag() string { @@ -118,6 +130,10 @@ func rekorServer() string { return "http://localhost:3000" } +func coverageFlag() string { + return "-test.coverprofile=/tmp/rekor-cli."+randomSuffix(8)+".cov" +} + func readFile(t *testing.T, p string) string { b, err := ioutil.ReadFile(p) if err != nil { @@ -126,6 +142,16 @@ func readFile(t *testing.T, p string) string { return strings.TrimSpace(string(b)) } +func randomSuffix(n int) string { + const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + + b := make([]byte, n) + for i := range b { + b[i] = letterBytes[rand.Intn(len(letterBytes))] + } + return string(b) +} + func randomData(t *testing.T, n int) []byte { t.Helper() rand.Seed(time.Now().UnixNano()) From 706d2ec53b54c457dfcc2c1788c68d5f6ba15b09 Mon Sep 17 00:00:00 2001 From: Ceridwen Driskill Date: Wed, 21 Sep 2022 21:34:40 +0000 Subject: [PATCH 4/9] adding e2e coverage to github actions in theory Signed-off-by: Ceridwen Driskill --- .github/workflows/main.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bcd42910a..38eb9d492 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -44,6 +44,8 @@ jobs: run: go test -v -coverprofile=coverage.txt -covermode=atomic ./... - name: Upload Coverage Report uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.0 + with: + flags: unittests - name: Ensure no files were modified as a result of the build run: git update-index --refresh && git diff-index --quiet HEAD -- || git diff --exit-code @@ -72,13 +74,13 @@ jobs: - name: download minisign run: sudo add-apt-repository ppa:dysfunctionalprogramming/minisign && sudo apt-get update && sudo apt-get install minisign - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2 - - name: Docker Build - run: docker-compose build - name: Extract version of Go to use run: echo "GOVERSION=$(cat Dockerfile|grep golang | awk ' { print $2 } ' | cut -d '@' -f 1 | cut -d ':' -f 2 | uniq)" >> $GITHUB_ENV - uses: actions/setup-go@268d8c0ca0432bb2cf416faae41297df9d262d7f # v3.1.0 with: go-version: ${{ env.GOVERSION }} + - name: install gocovmerge + run: go install github.com/wadey/gocovmerge@latest - name: CLI run: ./tests/e2e-test.sh @@ -88,6 +90,11 @@ jobs: with: name: E2E Docker Compose logs path: /tmp/docker-compose.log + - name: Upload Coverage Report + uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 + with: + files: /tmp/rekor-merged.cov + flags: e2etests sharding-e2e: runs-on: ubuntu-20.04 From e1124d2b995757faf59916d2115f1ba2db21260b Mon Sep 17 00:00:00 2001 From: Ceridwen Driskill Date: Thu, 22 Sep 2022 17:22:02 +0000 Subject: [PATCH 5/9] removing /pkg/generated/ from coverage report Signed-off-by: Ceridwen Driskill --- tests/e2e-test.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/e2e-test.sh b/tests/e2e-test.sh index 98689cfb3..c485bb8a7 100755 --- a/tests/e2e-test.sh +++ b/tests/e2e-test.sh @@ -68,5 +68,6 @@ if ! docker cp $(docker ps -aqf "name=rekor_rekor-server"):go/rekor-server.cov / exit 1 fi -gocovmerge /tmp/rekor-*.cov > /tmp/rekor-merged.cov +# merging coverage reports and filtering out /pkg/generated from final report +gocovmerge /tmp/rekor-*.cov | grep -v "/pkg/generated/" > /tmp/rekor-merged.cov echo "code coverage $(go tool cover -func=/tmp/rekor-merged.cov | grep -E '^total\:' | sed -E 's/\s+/ /g')" From 836e33a84fbd67a35fb8cd95ac57dd5d39072109 Mon Sep 17 00:00:00 2001 From: Ceridwen Driskill Date: Thu, 22 Sep 2022 18:20:51 +0000 Subject: [PATCH 6/9] lint Signed-off-by: Ceridwen Driskill --- cmd/rekor-server/app/serve.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/rekor-server/app/serve.go b/cmd/rekor-server/app/serve.go index bdd217785..23806f0a1 100644 --- a/cmd/rekor-server/app/serve.go +++ b/cmd/rekor-server/app/serve.go @@ -115,8 +115,10 @@ var serveCmd = &cobra.Command{ http.Handle("/metrics", promhttp.Handler()) if viper.GetBool("enable_killswitch") { - http.Handle("/kill", http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) { - server.Shutdown() + http.Handle("/kill", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if err := server.Shutdown(); err != nil { + log.Logger.Error(err) + } w.WriteHeader(http.StatusOK) })) } From 03fbc0847cbd6fff90f1ed2944d0d626bb0b6851 Mon Sep 17 00:00:00 2001 From: Ceridwen Driskill Date: Thu, 22 Sep 2022 20:25:25 +0000 Subject: [PATCH 7/9] separate port for server test killswitch Signed-off-by: Ceridwen Driskill --- cmd/rekor-server/app/root.go | 2 +- cmd/rekor-server/app/serve.go | 29 +++++++++++++++++++++-------- docker-compose.test.yml | 4 ++++ tests/e2e-test.sh | 2 +- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/cmd/rekor-server/app/root.go b/cmd/rekor-server/app/root.go index dd3f23d61..0191abfd8 100644 --- a/cmd/rekor-server/app/root.go +++ b/cmd/rekor-server/app/root.go @@ -61,7 +61,7 @@ func init() { rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.rekor-server.yaml)") rootCmd.PersistentFlags().StringVar(&logType, "log_type", "dev", "logger type to use (dev/prod)") rootCmd.PersistentFlags().BoolVar(&enablePprof, "enable_pprof", false, "enable pprof for profiling on port 6060") - rootCmd.PersistentFlags().Bool("enable_killswitch", false, "enable killswitch for TESTING ONLY on port 2112") + rootCmd.PersistentFlags().Bool("enable_killswitch", false, "enable killswitch for TESTING ONLY on port 2345") rootCmd.PersistentFlags().String("trillian_log_server.address", "127.0.0.1", "Trillian log server address") rootCmd.PersistentFlags().Uint16("trillian_log_server.port", 8090, "Trillian log server port") diff --git a/cmd/rekor-server/app/serve.go b/cmd/rekor-server/app/serve.go index 23806f0a1..b7628aea1 100644 --- a/cmd/rekor-server/app/serve.go +++ b/cmd/rekor-server/app/serve.go @@ -114,14 +114,6 @@ var serveCmd = &cobra.Command{ server.ConfigureAPI() http.Handle("/metrics", promhttp.Handler()) - if viper.GetBool("enable_killswitch") { - http.Handle("/kill", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if err := server.Shutdown(); err != nil { - log.Logger.Error(err) - } - w.WriteHeader(http.StatusOK) - })) - } go func() { srv := &http.Server{ Addr: ":2112", @@ -131,6 +123,27 @@ var serveCmd = &cobra.Command{ _ = srv.ListenAndServe() }() + if viper.GetBool("enable_killswitch") { + go func() { + mux := http.NewServeMux() + mux.Handle("/kill", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if err := server.Shutdown(); err != nil { + log.Logger.Error(err) + } + w.WriteHeader(http.StatusOK) + })) + + srv := &http.Server{ + Addr: ":2345", + ReadTimeout: 10 * time.Second, + WriteTimeout: 10 * time.Second, + Handler: mux, + } + + _ = srv.ListenAndServe() + }() + } + if err := server.Serve(); err != nil { log.Logger.Fatal(err) } diff --git a/docker-compose.test.yml b/docker-compose.test.yml index dbb2b60ed..6a0b780c4 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -33,3 +33,7 @@ services: "--attestation_storage_bucket=file:///var/run/attestations", "--enable_killswitch", ] + ports: + - "3000:3000" + - "2112:2112" + - "2345:2345" diff --git a/tests/e2e-test.sh b/tests/e2e-test.sh index c485bb8a7..6b97a3701 100755 --- a/tests/e2e-test.sh +++ b/tests/e2e-test.sh @@ -58,7 +58,7 @@ if docker-compose logs --no-color | grep -q "panic: runtime error:" ; then fi echo "generating code coverage" -curl -X GET 0.0.0.0:2112/kill +curl -X GET 0.0.0.0:2345/kill sleep 5 if ! docker cp $(docker ps -aqf "name=rekor_rekor-server"):go/rekor-server.cov /tmp/rekor-server.cov ; then From 7e4a588ae2d8d83aa1445891363ffe7d08f69e98 Mon Sep 17 00:00:00 2001 From: Ceridwen Driskill Date: Fri, 23 Sep 2022 16:25:38 +0000 Subject: [PATCH 8/9] hide killswitch flag Signed-off-by: Ceridwen Driskill --- cmd/rekor-server/app/root.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/rekor-server/app/root.go b/cmd/rekor-server/app/root.go index 0191abfd8..fdecd742b 100644 --- a/cmd/rekor-server/app/root.go +++ b/cmd/rekor-server/app/root.go @@ -62,6 +62,7 @@ func init() { rootCmd.PersistentFlags().StringVar(&logType, "log_type", "dev", "logger type to use (dev/prod)") rootCmd.PersistentFlags().BoolVar(&enablePprof, "enable_pprof", false, "enable pprof for profiling on port 6060") rootCmd.PersistentFlags().Bool("enable_killswitch", false, "enable killswitch for TESTING ONLY on port 2345") + _ = rootCmd.PersistentFlags().MarkHidden("enable_killswitch") rootCmd.PersistentFlags().String("trillian_log_server.address", "127.0.0.1", "Trillian log server address") rootCmd.PersistentFlags().Uint16("trillian_log_server.port", 8090, "Trillian log server port") From a62fbc66d21ee8979f2cde2eb24a3b7c7f78c159 Mon Sep 17 00:00:00 2001 From: Ceridwen Driskill Date: Fri, 23 Sep 2022 16:53:33 +0000 Subject: [PATCH 9/9] pin gocovmerge, factor out stripCoverageOutput Signed-off-by: Ceridwen Driskill --- .github/workflows/main.yml | 2 +- tests/util.go | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 38eb9d492..d2d7567fa 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -80,7 +80,7 @@ jobs: with: go-version: ${{ env.GOVERSION }} - name: install gocovmerge - run: go install github.com/wadey/gocovmerge@latest + run: go install github.com/wadey/gocovmerge@b5bfa59ec0adc420475f97f89b58045c721d761c - name: CLI run: ./tests/e2e-test.sh diff --git a/tests/util.go b/tests/util.go index 9961b2a64..0b4a15025 100644 --- a/tests/util.go +++ b/tests/util.go @@ -63,9 +63,7 @@ func run(t *testing.T, stdin, cmd string, arg ...string) string { t.Log(string(b)) t.Fatal(err) } - - // Remove test coverage output - return strings.Split(strings.Split(string(b), "PASS")[0], "FAIL")[0] + return stripCoverageOutput(string(b)) } func runCli(t *testing.T, arg ...string) string { @@ -95,8 +93,7 @@ func runCliStdout(t *testing.T, arg ...string) string { t.Log(string(b)) t.Fatal(err) } - // Remove test coverage output - return strings.Split(strings.Split(string(b), "PASS")[0], "FAIL")[0] + return stripCoverageOutput(string(b)) } func runCliErr(t *testing.T, arg ...string) string { @@ -115,8 +112,7 @@ func runCliErr(t *testing.T, arg ...string) string { t.Log(string(b)) t.Fatalf("expected error, got %s", string(b)) } - // Remove test coverage output - return strings.Split(strings.Split(string(b), "PASS")[0], "FAIL")[0] + return stripCoverageOutput(string(b)) } func rekorServerFlag() string { @@ -134,6 +130,10 @@ func coverageFlag() string { return "-test.coverprofile=/tmp/rekor-cli."+randomSuffix(8)+".cov" } +func stripCoverageOutput(out string) string { + return strings.Split(strings.Split(out, "PASS")[0], "FAIL")[0] +} + func readFile(t *testing.T, p string) string { b, err := ioutil.ReadFile(p) if err != nil {