Skip to content
Snippets Groups Projects
Unverified Commit 956c8958 authored by dlorenc's avatar dlorenc Committed by GitHub
Browse files

Merge pull request #88 from dlorenc/e2ego

Rewrite the e2e tests in go from bash.
parents 50b18373 0a6001d9
No related branches found
No related tags found
No related merge requests found
......@@ -4,21 +4,6 @@ testdir=$(dirname "$0")
docker-compose up -d
# Node
nodedir=${testdir}/node
go build -o rekor-cli ./cmd/cli
# First time we should get "Created entry"
out=$(go run ./cmd/cli/ upload \
--artifact $(< ${nodedir}/url) --sha $(< ${nodedir}/sha) \
--signature=${nodedir}/sig --public-key=${nodedir}/key)
if [[ $out != *"Created entry at"* ]]; then
echo "Expected 'Created entry at', got $out"
fi
# Second time we should get "Entry already exists"
out=$(go run ./cmd/cli/ upload \
--artifact $(< ${nodedir}/url) --sha $(< ${nodedir}/sha) \
--signature=${nodedir}/sig --public-key=${nodedir}/key)
if [[ $out != *"Entry already exists"* ]]; then
echo "Expected 'Created entry at', got $out"
fi
go test -tags=e2e ./tests/
// +build e2e
package e2e
import (
"io/ioutil"
"os/exec"
"strings"
"testing"
)
const (
cli = "../rekor-cli"
nodeDataDir = "node"
)
func runCli(t *testing.T, arg ...string) string {
cmd := exec.Command(cli, arg...)
b, err := cmd.CombinedOutput()
if err != nil {
t.Log(string(b))
t.Fatal(err)
}
return string(b)
}
func runCliErr(t *testing.T, arg ...string) {
cmd := exec.Command(cli, arg...)
b, err := cmd.CombinedOutput()
if err == nil {
t.Log(string(b))
t.Fatalf("expected error, got %s", string(b))
}
}
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 TestDuplicates(t *testing.T) {
// Start with uploading the node data once
out := runCli(t, "upload", "--artifact", readFile(t, "node/url"), "--sha", readFile(t, "node/sha"),
"--signature=node/sig", "--public-key=node/key")
if !strings.Contains(out, "Created entry at") {
t.Errorf("Expected [Created entry at], got %s", out)
}
t.Log(out)
// Now do it again, there should be a duplicate message
out = runCli(t, "upload", "--artifact", readFile(t, "node/url"), "--sha", readFile(t, "node/sha"),
"--signature=node/sig", "--public-key=node/key")
if !strings.Contains(out, "Entry already exists") {
t.Errorf("Expected [Entry already exists], got %s", out)
}
t.Log(out)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment