From 6fc511e1887097a853b5a58899e84fc18d262b59 Mon Sep 17 00:00:00 2001 From: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> Date: Mon, 12 Sep 2022 13:57:44 -0500 Subject: [PATCH 1/7] Refactor - e2e tests - Refactor e2e tests to move it to specific folders. Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> --- .github/workflows/main.yml | 2 + .gitignore | 4 +- pkg/e2e-test.sh | 55 ++++++ pkg/pki/tuf/e2e_test.go | 44 +++++ tests/tuf.go => pkg/pki/tuf/tuf_e2e_test.go | 3 +- pkg/util/util.go | 177 ++++++++++++++++++++ tests/e2e_test.go | 19 --- 7 files changed, 282 insertions(+), 22 deletions(-) create mode 100755 pkg/e2e-test.sh create mode 100644 pkg/pki/tuf/e2e_test.go rename tests/tuf.go => pkg/pki/tuf/tuf_e2e_test.go (98%) create mode 100644 pkg/util/util.go diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dc7720dd4..90ea93035 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -84,6 +84,8 @@ jobs: - name: CLI run: ./tests/e2e-test.sh + - name: PKG-CLI # this will a WIP to move all the CLI tests to the pkg repo + run: ./pkg/e2e-test.sh - name: Upload logs if they exist uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3 if: failure() diff --git a/.gitignore b/.gitignore index 55fce30e7..65fdb6c0c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,8 +3,8 @@ .vscode/* /cli logid -/rekor-cli -/rekor-server +rekor-cli +rekor-server /tests/rekor-server /server swagger diff --git a/pkg/e2e-test.sh b/pkg/e2e-test.sh new file mode 100755 index 000000000..34e9ed450 --- /dev/null +++ b/pkg/e2e-test.sh @@ -0,0 +1,55 @@ +#!/bin/bash +# +# Copyright 2021 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. + +set -e + +echo "starting services" +docker-compose up -d + +echo "building CLI and server" +go build -o rekor-cli ./cmd/rekor-cli +go build -o rekor-server ./cmd/rekor-server + +count=0 + +echo -n "waiting up to 60 sec for system to start" +until [ $(docker-compose ps | grep -c "(healthy)") == 3 ]; +do + if [ $count -eq 6 ]; then + echo "! timeout reached" + exit 1 + else + echo -n "." + sleep 10 + let 'count+=1' + fi +done + +echo +echo "running tests" +REKORTMPDIR="$(mktemp -d -t rekor_test.XXXXXX)" +touch $REKORTMPDIR.rekor.yaml +trap "rm -rf $REKORTMPDIR" EXIT +if ! REKORTMPDIR=$REKORTMPDIR go test -tags=e2e ./...; then + docker-compose logs --no-color > /tmp/docker-compose.log + exit 1 +fi +if docker-compose logs --no-color | grep -q "panic: runtime error:" ; then + # if we're here, we found a panic + echo "Failing due to panics detected in logs" + docker-compose logs --no-color > /tmp/docker-compose.log + exit 1 +fi diff --git a/pkg/pki/tuf/e2e_test.go b/pkg/pki/tuf/e2e_test.go new file mode 100644 index 000000000..fd5aa6dc1 --- /dev/null +++ b/pkg/pki/tuf/e2e_test.go @@ -0,0 +1,44 @@ +// +// 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. + +//go:build e2e +// +build e2e + +package tuf + +import ( + "github.com/sigstore/rekor/pkg/util" + "path/filepath" + "testing" +) + +func TestTufVerifyUpload(t *testing.T) { + artifactPath := filepath.Join(t.TempDir(), "timestamp.json") + rootPath := filepath.Join(t.TempDir(), "root.json") + + createTufSignedArtifact(t, artifactPath, rootPath) + + // Now upload to rekor! + out := util.RunCli(t, "upload", "--artifact", artifactPath, "--public-key", rootPath, "--type", "tuf") + util.OutputContains(t, out, "Created entry at") + + uuid := util.GetUUIDFromUploadOutput(t, out) + + out = util.RunCli(t, "verify", "--artifact", artifactPath, "--public-key", rootPath, "--type", "tuf") + util.OutputContains(t, out, "Inclusion Proof") + + out = util.RunCli(t, "search", "--public-key", rootPath, "--pki-format", "tuf") + util.OutputContains(t, out, uuid) +} diff --git a/tests/tuf.go b/pkg/pki/tuf/tuf_e2e_test.go similarity index 98% rename from tests/tuf.go rename to pkg/pki/tuf/tuf_e2e_test.go index 3714057f3..8cdf32cec 100644 --- a/tests/tuf.go +++ b/pkg/pki/tuf/tuf_e2e_test.go @@ -13,9 +13,10 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build e2e // +build e2e -package e2e +package tuf import ( "io/ioutil" diff --git a/pkg/util/util.go b/pkg/util/util.go new file mode 100644 index 000000000..bbf3ba12f --- /dev/null +++ b/pkg/util/util.go @@ -0,0 +1,177 @@ +// +// Copyright 2021 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. + +//go:build e2e +// +build e2e + +package util + +import ( + "encoding/base64" + "fmt" + "io/ioutil" + "math/rand" + "os" + "os/exec" + "strings" + "testing" + "time" + + "github.com/sigstore/rekor/pkg/generated/models" +) + +const ( + cli = "../../rekor-cli" + server = "./rekor-server" + nodeDataDir = "node" +) + +func OutputContains(t *testing.T, output, sub string) { + t.Helper() + if !strings.Contains(output, sub) { + t.Errorf("Expected [%s] in response, got %s", sub, output) + } +} + +func Run(t *testing.T, stdin, cmd string, arg ...string) string { + t.Helper() + c := exec.Command(cmd, arg...) + if stdin != "" { + c.Stdin = strings.NewReader(stdin) + } + if os.Getenv("REKORTMPDIR") != "" { + // ensure that we use a clean state.json file for each Run + c.Env = append(c.Env, "HOME="+os.Getenv("REKORTMPDIR")) + } + b, err := c.CombinedOutput() + if err != nil { + t.Log(string(b)) + t.Fatal(err) + } + + return string(b) +} + +func RunCli(t *testing.T, arg ...string) string { + t.Helper() + arg = append(arg, rekorServerFlag()) + // use a blank config file to ensure no collision + if os.Getenv("REKORTMPDIR") != "" { + arg = append(arg, "--config="+os.Getenv("REKORTMPDIR")+".rekor.yaml") + } + return Run(t, "", cli, arg...) +} + +func RunCliStdout(t *testing.T, arg ...string) string { + t.Helper() + arg = append(arg, rekorServerFlag()) + c := exec.Command(cli, arg...) + + if os.Getenv("REKORTMPDIR") != "" { + // ensure that we use a clean state.json file for each Run + c.Env = append(c.Env, "HOME="+os.Getenv("REKORTMPDIR")) + } + b, err := c.Output() + if err != nil { + t.Log(string(b)) + t.Fatal(err) + } + return string(b) +} + +func RunCliErr(t *testing.T, arg ...string) string { + t.Helper() + arg = append(arg, rekorServerFlag()) + // use a blank config file to ensure no collision + if os.Getenv("REKORTMPDIR") != "" { + arg = append(arg, "--config="+os.Getenv("REKORTMPDIR")+".rekor.yaml") + } + cmd := exec.Command(cli, arg...) + b, err := cmd.CombinedOutput() + if err == nil { + t.Log(string(b)) + t.Fatalf("expected error, got %s", string(b)) + } + return string(b) +} + +func rekorServerFlag() string { + return fmt.Sprintf("--rekor_server=%s", rekorServer()) +} + +func rekorServer() string { + if s := os.Getenv("REKOR_SERVER"); s != "" { + return s + } + return "http://localhost:3000" +} + +func readFile(t *testing.T, p string) string { + b, err := ioutil.ReadFile(p) + if err != nil { + t.Fatal(err) + } + return strings.TrimSpace(string(b)) +} + +func randomData(t *testing.T, n int) []byte { + t.Helper() + rand.Seed(time.Now().UnixNano()) + data := make([]byte, n) + if _, err := rand.Read(data[:]); err != nil { + t.Fatal(err) + } + return data +} + +func createArtifact(t *testing.T, artifactPath string) string { + t.Helper() + // First let's generate some random data so we don't have to worry about dupes. + data := randomData(t, 100) + + artifact := base64.StdEncoding.EncodeToString(data[:]) + // Write this to a file + write(t, artifact, artifactPath) + return artifact +} + +func extractLogEntry(t *testing.T, le models.LogEntry) models.LogEntryAnon { + t.Helper() + + if len(le) != 1 { + t.Fatal("expected length to be 1, is actually", len(le)) + } + for _, v := range le { + return v + } + // this should never happen + return models.LogEntryAnon{} +} + +func write(t *testing.T, data string, path string) { + t.Helper() + if err := ioutil.WriteFile(path, []byte(data), 0644); err != nil { + t.Fatal(err) + } +} + +func GetUUIDFromUploadOutput(t *testing.T, out string) string { + t.Helper() + // Output looks like "Artifact timestamped at ...\m Wrote response \n Created entry at index X, available at $URL/UUID", so grab the UUID: + urlTokens := strings.Split(strings.TrimSpace(out), " ") + url := urlTokens[len(urlTokens)-1] + splitUrl := strings.Split(url, "/") + return splitUrl[len(splitUrl)-1] +} diff --git a/tests/e2e_test.go b/tests/e2e_test.go index ff5b7f0ac..7894aada6 100644 --- a/tests/e2e_test.go +++ b/tests/e2e_test.go @@ -1063,25 +1063,6 @@ func TestEntryUpload(t *testing.T) { outputContains(t, out, "Created entry at") } -func TestTufVerifyUpload(t *testing.T) { - artifactPath := filepath.Join(t.TempDir(), "timestamp.json") - rootPath := filepath.Join(t.TempDir(), "root.json") - - createTufSignedArtifact(t, artifactPath, rootPath) - - // Now upload to rekor! - out := runCli(t, "upload", "--artifact", artifactPath, "--public-key", rootPath, "--type", "tuf") - outputContains(t, out, "Created entry at") - - uuid := getUUIDFromUploadOutput(t, out) - - out = runCli(t, "verify", "--artifact", artifactPath, "--public-key", rootPath, "--type", "tuf") - outputContains(t, out, "Inclusion Proof") - - out = runCli(t, "search", "--public-key", rootPath, "--pki-format", "tuf") - outputContains(t, out, uuid) -} - // Regression test for https://github.com/sigstore/rekor/pull/956 // Requesting an inclusion proof concurrently with an entry write triggers // a race where the inclusion proof returned does not verify because the From f61311698ea674ba1d3e3e692c864fad83ed0e48 Mon Sep 17 00:00:00 2001 From: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> Date: Fri, 16 Sep 2022 17:49:10 -0500 Subject: [PATCH 2/7] More tweaks to fix the e2e Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> --- pkg/e2e-test.sh | 6 ++++-- pkg/util/util.go | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/pkg/e2e-test.sh b/pkg/e2e-test.sh index 34e9ed450..d7eb31280 100755 --- a/pkg/e2e-test.sh +++ b/pkg/e2e-test.sh @@ -20,11 +20,12 @@ echo "starting services" docker-compose up -d echo "building CLI and server" +dir=$(dirname "$0") go build -o rekor-cli ./cmd/rekor-cli go build -o rekor-server ./cmd/rekor-server count=0 - +docker kill $(docker ps -q) || true echo -n "waiting up to 60 sec for system to start" until [ $(docker-compose ps | grep -c "(healthy)") == 3 ]; do @@ -41,9 +42,10 @@ done echo echo "running tests" REKORTMPDIR="$(mktemp -d -t rekor_test.XXXXXX)" +cp $dir/rekor-cli $REKORTMPDIR/rekor-cli touch $REKORTMPDIR.rekor.yaml trap "rm -rf $REKORTMPDIR" EXIT -if ! REKORTMPDIR=$REKORTMPDIR go test -tags=e2e ./...; then +if ! REKORTMPDIR=$REKORTMPDIR go test -tags=e2e ./pkg/...; then docker-compose logs --no-color > /tmp/docker-compose.log exit 1 fi diff --git a/pkg/util/util.go b/pkg/util/util.go index bbf3ba12f..571c0bdf7 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -25,6 +25,7 @@ import ( "math/rand" "os" "os/exec" + "path" "strings" "testing" "time" @@ -32,12 +33,21 @@ import ( "github.com/sigstore/rekor/pkg/generated/models" ) -const ( - cli = "../../rekor-cli" - server = "./rekor-server" +var ( + cli = "rekor-cli" + server = "rekor-server" nodeDataDir = "node" ) +func init() { + + p := os.Getenv("REKORTMPDIR") + if p != "" { + cli = path.Join(p, cli) + server = path.Join(p, server) + } +} + func OutputContains(t *testing.T, output, sub string) { t.Helper() if !strings.Contains(output, sub) { From 96874729b78efde2cde5dce0e4648f3cfd28ba06 Mon Sep 17 00:00:00 2001 From: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> Date: Mon, 19 Sep 2022 12:49:12 -0500 Subject: [PATCH 3/7] Increased the timeout. Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> --- pkg/e2e-test.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/e2e-test.sh b/pkg/e2e-test.sh index d7eb31280..0cf9f4e99 100755 --- a/pkg/e2e-test.sh +++ b/pkg/e2e-test.sh @@ -16,20 +16,21 @@ set -e +docker kill $(docker ps -q) || true echo "starting services" docker-compose up -d echo "building CLI and server" -dir=$(dirname "$0") +# set the path to the root of the repo +dir=$(git rev-parse --show-toplevel) go build -o rekor-cli ./cmd/rekor-cli go build -o rekor-server ./cmd/rekor-server count=0 -docker kill $(docker ps -q) || true -echo -n "waiting up to 60 sec for system to start" +echo -n "waiting up to 120 sec for system to start" until [ $(docker-compose ps | grep -c "(healthy)") == 3 ]; do - if [ $count -eq 6 ]; then + if [ $count -eq 12 ]; then echo "! timeout reached" exit 1 else From 4d54c716e3bf427aa248e950211be2b12715486f Mon Sep 17 00:00:00 2001 From: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> Date: Tue, 11 Oct 2022 19:27:58 -0500 Subject: [PATCH 4/7] Updated the code with the coverage information. Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> --- .github/workflows/main.yml | 2 +- .gitignore | 2 +- pkg/e2e-test.sh | 25 ++++++++++++++++++++++--- pkg/util/util.go | 23 ++++++++++++++++++++--- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 90ea93035..d87e7130f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -95,7 +95,7 @@ jobs: - name: Upload Coverage Report uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 with: - files: /tmp/rekor-merged.cov + files: /tmp/rekor-merged.cov,/tmp/pkg-rekor-merged.cov flags: e2etests sharding-e2e: diff --git a/.gitignore b/.gitignore index 65fdb6c0c..18d3e272c 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,4 @@ trillianServerImagerefs trillianSignerImagerefs cosign.* signature -rekor.pub +rekor.pub \ No newline at end of file diff --git a/pkg/e2e-test.sh b/pkg/e2e-test.sh index 0cf9f4e99..3f4bde4f2 100755 --- a/pkg/e2e-test.sh +++ b/pkg/e2e-test.sh @@ -15,16 +15,20 @@ # limitations under the License. set -e +testdir=$(dirname "$0") +rm -f /tmp/rekor-*.cov +echo "installing gocovmerge" +make gocovmerge docker kill $(docker ps -q) || true 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" # set the path to the root of the repo dir=$(git rev-parse --show-toplevel) -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 echo -n "waiting up to 120 sec for system to start" @@ -56,3 +60,18 @@ 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:2345/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 + +# merging coverage reports and filtering out /pkg/generated from final report +hack/tools/bin/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')" diff --git a/pkg/util/util.go b/pkg/util/util.go index 571c0bdf7..6daa036eb 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -70,8 +70,7 @@ func Run(t *testing.T, stdin, cmd string, arg ...string) string { t.Log(string(b)) t.Fatal(err) } - - return string(b) + return stripCoverageOutput(string(b)) } func RunCli(t *testing.T, arg ...string) string { @@ -98,7 +97,7 @@ func RunCliStdout(t *testing.T, arg ...string) string { t.Log(string(b)) t.Fatal(err) } - return string(b) + return stripCoverageOutput(string(b)) } func RunCliErr(t *testing.T, arg ...string) string { @@ -128,6 +127,14 @@ func rekorServer() string { return "http://localhost:3000" } +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 { @@ -136,6 +143,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 6eabd04811112dc5273ef657469ebb4114945b7b Mon Sep 17 00:00:00 2001 From: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> Date: Tue, 18 Oct 2022 09:15:28 -0500 Subject: [PATCH 5/7] Fixed the coverage issues. Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> --- pkg/e2e-test.sh | 8 ++++---- pkg/util/util.go | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/e2e-test.sh b/pkg/e2e-test.sh index 3f4bde4f2..744ad6f6d 100755 --- a/pkg/e2e-test.sh +++ b/pkg/e2e-test.sh @@ -17,7 +17,7 @@ set -e testdir=$(dirname "$0") -rm -f /tmp/rekor-*.cov +rm -f /tmp/pkg-rekor-*.cov echo "installing gocovmerge" make gocovmerge docker kill $(docker ps -q) || true @@ -65,7 +65,7 @@ echo "generating code coverage" 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 +if ! docker cp $(docker ps -aqf "name=rekor_rekor-server"):go/rekor-server.cov /tmp/pkg-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 @@ -73,5 +73,5 @@ if ! docker cp $(docker ps -aqf "name=rekor_rekor-server"):go/rekor-server.cov / fi # merging coverage reports and filtering out /pkg/generated from final report -hack/tools/bin/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')" +hack/tools/bin/gocovmerge /tmp/pkg-rekor-*.cov | grep -v "/pkg/generated/" > /tmp/pkg-rekor-merged.cov +echo "code coverage $(go tool cover -func=/tmp/pkg-rekor-merged.cov | grep -E '^total\:' | sed -E 's/\s+/ /g')" diff --git a/pkg/util/util.go b/pkg/util/util.go index 6daa036eb..e313d4304 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -40,7 +40,6 @@ var ( ) func init() { - p := os.Getenv("REKORTMPDIR") if p != "" { cli = path.Join(p, cli) @@ -57,6 +56,7 @@ func OutputContains(t *testing.T, output, sub string) { func Run(t *testing.T, stdin, cmd string, arg ...string) string { t.Helper() + arg = append([]string{coverageFlag()}, arg...) c := exec.Command(cmd, arg...) if stdin != "" { c.Stdin = strings.NewReader(stdin) @@ -75,6 +75,7 @@ func Run(t *testing.T, stdin, cmd string, arg ...string) string { func RunCli(t *testing.T, arg ...string) string { t.Helper() + arg = append([]string{coverageFlag()}, arg...) arg = append(arg, rekorServerFlag()) // use a blank config file to ensure no collision if os.Getenv("REKORTMPDIR") != "" { @@ -85,6 +86,7 @@ func RunCli(t *testing.T, arg ...string) string { func RunCliStdout(t *testing.T, arg ...string) string { t.Helper() + arg = append([]string{coverageFlag()}, arg...) arg = append(arg, rekorServerFlag()) c := exec.Command(cli, arg...) @@ -102,6 +104,7 @@ func RunCliStdout(t *testing.T, arg ...string) string { func RunCliErr(t *testing.T, arg ...string) string { t.Helper() + arg = append([]string{coverageFlag()}, arg...) arg = append(arg, rekorServerFlag()) // use a blank config file to ensure no collision if os.Getenv("REKORTMPDIR") != "" { @@ -128,7 +131,7 @@ func rekorServer() string { } func coverageFlag() string { - return "-test.coverprofile=/tmp/rekor-cli." + randomSuffix(8) + ".cov" + return "-test.coverprofile=/tmp/pkg-rekor-cli." + randomSuffix(8) + ".cov" } func stripCoverageOutput(out string) string { From 46882745a5c2e51fac1a8dcbe03294f5ea5659d0 Mon Sep 17 00:00:00 2001 From: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> Date: Thu, 20 Oct 2022 16:39:06 -0500 Subject: [PATCH 6/7] Fixed coverage flags based on comments. Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> --- pkg/util/util.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/util/util.go b/pkg/util/util.go index e313d4304..a01bbd53a 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -75,7 +75,6 @@ func Run(t *testing.T, stdin, cmd string, arg ...string) string { func RunCli(t *testing.T, arg ...string) string { t.Helper() - arg = append([]string{coverageFlag()}, arg...) arg = append(arg, rekorServerFlag()) // use a blank config file to ensure no collision if os.Getenv("REKORTMPDIR") != "" { @@ -116,7 +115,7 @@ func RunCliErr(t *testing.T, arg ...string) string { t.Log(string(b)) t.Fatalf("expected error, got %s", string(b)) } - return string(b) + return stripCoverageOutput(string(b)) } func rekorServerFlag() string { From 7dfa43b168b604fe00b6bd8b99465cbd62f0aecf Mon Sep 17 00:00:00 2001 From: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> Date: Sat, 22 Oct 2022 11:16:51 -0500 Subject: [PATCH 7/7] Removed forced-recreate option. Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> --- pkg/e2e-test.sh | 4 ++-- pkg/util/util.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/e2e-test.sh b/pkg/e2e-test.sh index 744ad6f6d..51e42b814 100755 --- a/pkg/e2e-test.sh +++ b/pkg/e2e-test.sh @@ -1,6 +1,6 @@ #!/bin/bash # -# Copyright 2021 The Sigstore Authors. +# 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. @@ -22,7 +22,7 @@ echo "installing gocovmerge" make gocovmerge docker kill $(docker ps -q) || true echo "starting services" -docker-compose -f docker-compose.yml -f docker-compose.test.yml up -d --force-recreate --build +docker-compose -f docker-compose.yml -f docker-compose.test.yml up -d --build echo "building CLI and server" # set the path to the root of the repo diff --git a/pkg/util/util.go b/pkg/util/util.go index a01bbd53a..26fb131d6 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -1,5 +1,5 @@ // -// Copyright 2021 The Sigstore Authors. +// 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.