Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add initial e2e tests #239

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: E2E

on:
push:
branches:
- 'main'
paths:
- '**.go'
jobs:
e2e:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Run tests
run: |
make e2e
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,8 @@ $(ENVTEST): $(LOCALBIN)

.PHONY: embedded-resources
embedded-resources:
./hack/embedded-resources.sh
./hack/embedded-resources.sh

.PHONY: e2e
e2e: build
go test -v -p 1 --tags=e2e ./tests/e2e/...
111 changes: 111 additions & 0 deletions tests/e2e/docker/docker_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
//go:build e2e

package docker

import (
"context"
"fmt"
"log/slog"
"os"
"os/exec"
"strings"
"testing"
"time"

"github.com/cnoe-io/idpbuilder/tests/e2e"
"github.com/go-logr/logr"
"github.com/stretchr/testify/assert"
ctrl "sigs.k8s.io/controller-runtime"
)

func CleanUpDocker(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
b, err := e2e.RunCommand(ctx, `docker ps -aqf name=localdev-control-plane`, 10*time.Second)
assert.Nil(t, err, fmt.Sprintf("error while listing docker containers: %s, %s", err, b))

conts := strings.TrimSpace(string(b))
if len(conts) == 0 {
return
}
b, err = e2e.RunCommand(ctx, fmt.Sprintf("docker container rm -f %s", conts), 60*time.Second)
assert.Nil(t, err, fmt.Sprintf("error while removing docker containers: %s, %s", err, b))

b, err = e2e.RunCommand(ctx, "docker system prune -f", 60*time.Second)
assert.Nil(t, err, fmt.Sprintf("error while pruning system: %s, %s", err, b))

b, err = e2e.RunCommand(ctx, "docker volume prune -f", 60*time.Second)
assert.Nil(t, err, fmt.Sprintf("error while pruning volumes: %s, %s", err, b))
}

func Test_CreateDocker(t *testing.T) {
slogger := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelDebug}))
ctrl.SetLogger(logr.FromSlogHandler(slogger.Handler()))

testCreate(t)
testCreatePath(t)
testCreatePort(t)
}

// test idpbuilder create
func testCreate(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 8*time.Minute)
defer cancel()
defer CleanUpDocker(t)

t.Log("running idpbuilder create")
cmd := exec.CommandContext(ctx, e2e.IdpbuilderBinaryLocation, "create")
b, err := cmd.CombinedOutput()
assert.Nil(t, err, fmt.Sprintf("error while running create: %s, %s", err, b))

kubeClient, err := e2e.GetKubeClient()
assert.Nil(t, err, fmt.Sprintf("error while getting client: %s", err))

e2e.TestArgoCDApps(ctx, t, kubeClient, e2e.CorePackages)

argoBaseUrl := fmt.Sprintf("https://argocd.%s:%s", e2e.DefaultBaseDomain, e2e.DefaultPort)
giteaBaseUrl := fmt.Sprintf("https://gitea.%s:%s", e2e.DefaultBaseDomain, e2e.DefaultPort)
e2e.TestCoreEndpoints(ctx, t, argoBaseUrl, giteaBaseUrl)
}

// test idpbuilder create --use-path-routing
func testCreatePath(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 8*time.Minute)
defer cancel()
defer CleanUpDocker(t)

t.Log("running idpbuilder create --use-path-routing")
cmd := exec.CommandContext(ctx, e2e.IdpbuilderBinaryLocation, "create", "--use-path-routing")
b, err := cmd.CombinedOutput()
assert.Nil(t, err, fmt.Sprintf("error while running create: %s, %s", err, b))

kubeClient, err := e2e.GetKubeClient()
assert.Nil(t, err, fmt.Sprintf("error while getting client: %s", err))

e2e.TestArgoCDApps(ctx, t, kubeClient, e2e.CorePackages)

argoBaseUrl := fmt.Sprintf("https://%s:%s/argocd", e2e.DefaultBaseDomain, e2e.DefaultPort)
giteaBaseUrl := fmt.Sprintf("https://%s:%s/gitea", e2e.DefaultBaseDomain, e2e.DefaultPort)
e2e.TestCoreEndpoints(ctx, t, argoBaseUrl, giteaBaseUrl)
}

func testCreatePort(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 8*time.Minute)
defer cancel()
defer CleanUpDocker(t)

port := "2443"
t.Logf("running idpbuilder create --port %s", port)
cmd := exec.CommandContext(ctx, e2e.IdpbuilderBinaryLocation, "create", "--port", port)
b, err := cmd.CombinedOutput()
assert.Nil(t, err, fmt.Sprintf("error while running create: %s, %s", err, b))

kubeClient, err := e2e.GetKubeClient()
assert.Nil(t, err, fmt.Sprintf("error while getting client: %s", err))

e2e.TestArgoCDApps(ctx, t, kubeClient, e2e.CorePackages)

argoBaseUrl := fmt.Sprintf("https://argocd.%s:%s", e2e.DefaultBaseDomain, port)
giteaBaseUrl := fmt.Sprintf("https://gitea.%s:%s", e2e.DefaultBaseDomain, port)
e2e.TestCoreEndpoints(ctx, t, argoBaseUrl, giteaBaseUrl)
}
Loading
Loading