Skip to content

Commit

Permalink
e2e: call contrast set from Go
Browse files Browse the repository at this point in the history
  • Loading branch information
burgerdev committed Mar 12, 2024
1 parent 255f2c0 commit f695d44
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/e2e_openssl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ jobs:
just get-credentials
- name: Build, deploy, contrast generate, contrast set, contrast verify
run: |
just default openssl contrast.cli
just coordinator initializer openssl
just deploy openssl contrast.cli
- name: Setup Summary
run: |
cat ./workspace/just.namespace | tee -a "${GITHUB_STEP_SUMMARY}"
Expand Down
35 changes: 34 additions & 1 deletion e2e/openssl/openssl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"io"
"os"
"path"
"path/filepath"
"testing"
"time"

Expand All @@ -35,6 +36,38 @@ func TestOpenSSL(t *testing.T) {
namespace := os.Getenv(namespaceEnv)
require.NotEmpty(t, namespace, "environment variable %q must be set", namespaceEnv)

require.True(t, t.Run("set", func(t *testing.T) {
require := require.New(t)

ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancel()

require.NoError(c.WaitForDeployment(ctx, namespace, "coordinator"))

coordinator, cancelPortForward, err := c.PortForwardPod(ctx, namespace, "port-forwarder-coordinator", "1313")
require.NoError(err)
defer cancelPortForward()

resources, err := filepath.Glob("./workspace/deployment/*.yml")
require.NoError(err)

args := []string{
"--coordinator-policy-hash=", // TODO(burgerdev): enable policy checking
"--coordinator", coordinator,
"--workspace-dir", "./workspace",
}
args = append(args, resources...)

set := cmd.NewSetCmd()
set.Flags().String("workspace-dir", "", "") // Make set aware of root flags
set.SetArgs(args)
set.SetOut(io.Discard)
errBuf := &bytes.Buffer{}
set.SetErr(errBuf)

require.NoError(set.Execute(), "could not set manifest at coordinator: %s", errBuf)
}), "contrast set needs to succeed for subsequent tests")

certs := make(map[string][]byte)

require.True(t, t.Run("contrast verify", func(t *testing.T) {
Expand All @@ -49,7 +82,7 @@ func TestOpenSSL(t *testing.T) {
require.NoError(err)
defer cancelPortForward()

workspaceDir, err := os.MkdirTemp("", "nunki-verify.*")
workspaceDir, err := os.MkdirTemp("", "contrast-verify.*")
require.NoError(err)

verify := cmd.NewVerifyCmd()
Expand Down

0 comments on commit f695d44

Please sign in to comment.