Skip to content

Commit

Permalink
e2e: use openssl deployment from kuberesource
Browse files Browse the repository at this point in the history
  • Loading branch information
burgerdev committed Apr 16, 2024
1 parent 15df7a2 commit 3f5808e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/e2e_openssl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ jobs:
just get-credentials
- name: Build and prepare deployments
run: |
just coordinator initializer openssl
just populate openssl
just coordinator initializer openssl port-forwarder
- name: Setup Summary
run: |
cat ./workspace/just.perf | tee -a "${GITHUB_STEP_SUMMARY}"
- name: E2E Test
run: |
nix shell .#contrast.e2e --command openssl.test -test.v
nix shell .#contrast.e2e --command openssl.test -test.v workspace/just.containerlookup
46 changes: 31 additions & 15 deletions e2e/openssl/openssl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import (
"context"
"crypto/tls"
"crypto/x509"
"flag"
"log"
"os"
"path/filepath"
"testing"
"time"

"github.com/edgelesssys/contrast/e2e/internal/contrasttest"
"github.com/edgelesssys/contrast/e2e/internal/kubeclient"
"github.com/edgelesssys/contrast/internal/kubeapi"
"github.com/edgelesssys/contrast/e2e/internal/kuberesource"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)
Expand All @@ -25,28 +26,28 @@ const (
opensslBackend = "openssl-backend"
)

var imageReplacements map[string]string

// TestOpenSSL runs e2e tests on the example OpenSSL deployment.
func TestOpenSSL(t *testing.T) {
c := kubeclient.NewForTest(t)
ct := contrasttest.New(t)

// TODO(burgerdev): The deployment should be generated programmatically.
resources, err := filepath.Glob("./workspace/deployment/*.yml")
resources, err := kuberesource.OpenSSL()
require.NoError(t, err)
var objects []*unstructured.Unstructured
for _, file := range resources {
yaml, err := os.ReadFile(file)
require.NoError(t, err)
fileObjects, err := kubeapi.UnmarshalUnstructuredK8SResource(yaml)
require.NoError(t, err)

resources = kuberesource.PatchImages(resources, imageReplacements)

unstructuredResources, err := kuberesource.ResourcesToUnstructured(resources)
require.NoError(t, err)

var objects []*unstructured.Unstructured
for _, obj := range unstructuredResources {
// TODO(burgerdev): remove once demo deployments don't contain namespaces anymore.
for _, obj := range fileObjects {
if obj.GetKind() == "Namespace" {
continue
}
objects = append(objects, obj)
if obj.GetKind() == "Namespace" {
continue
}
objects = append(objects, obj)
}

ct.Init(t, objects)
Expand Down Expand Up @@ -110,3 +111,18 @@ func TestOpenSSL(t *testing.T) {
require.NoError(err, "stderr: %q", stderr)
})
}

func TestMain(m *testing.M) {
flag.Parse()

f, err := os.Open(flag.Arg(0))
if err != nil {
log.Fatalf("could not open image definition file %q: %v", flag.Arg(0), err)
}
imageReplacements, err = kuberesource.ImageReplacementsFromFile(f)
if err != nil {
log.Fatalf("could not parse image definition file %q: %v", flag.Arg(0), err)
}

os.Exit(m.Run())
}

0 comments on commit 3f5808e

Please sign in to comment.