Skip to content

Commit

Permalink
add github action for integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
muhlemmer committed Apr 25, 2023
1 parent a22b58f commit 7908408
Show file tree
Hide file tree
Showing 20 changed files with 195 additions and 30 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
on:
push:

jobs:
integration-tests:
strategy:
matrix:
db: [cockroach, postgres]
runs-on: ubuntu-20.04
env:
DOCKER_BUILDKIT: 1
steps:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Source checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver: docker
install: true
- name: Generate gRPC definitions
run: docker build -f build/grpc/Dockerfile -t zitadel-base:local .
- name: Copy gRPC definitions
run: docker build -f build/zitadel/Dockerfile . -t zitadel-go-base --target go-copy -o .
- name: Download Go modules
run: go mod download
- name: Start ${{ matrix.db }} database
run: docker compose -f e2e/config/integration/docker-compose.yaml up --wait ${{ matrix.db }}
- name: Run integration test
env:
INTEGRATION_DB_FLAVOR: ${{ matrix.db }}
run: go test -tags=integration -v ./internal/integration ./internal/api/grpc/...
24 changes: 24 additions & 0 deletions e2e/config/integration/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '3.8'

services:
cockroach:
extends:
file: '../localhost/docker-compose.yaml'
service: 'db'

postgres:
restart: 'always'
image: 'postgres:15'
environment:
- POSTGRES_USER=zitadel
- PGUSER=zitadel
- POSTGRES_DB=zitadel
- POSTGRES_HOST_AUTH_METHOD=trust
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: '10s'
timeout: '30s'
retries: 5
start_period: '20s'
ports:
- 5432:5432
2 changes: 2 additions & 0 deletions internal/api/grpc/admin/failed_event_converter_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !integration

package admin

import (
Expand Down
2 changes: 2 additions & 0 deletions internal/api/grpc/admin/iam_member_converter_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !integration

package admin

import (
Expand Down
2 changes: 2 additions & 0 deletions internal/api/grpc/admin/idp_converter_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !integration

package admin

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
//go:build integration

package admin_test

import (
"context"
"os"
"strings"
"testing"
"time"

"github.com/stretchr/testify/require"

"github.com/zitadel/zitadel/internal/integration"
"github.com/zitadel/zitadel/pkg/grpc/admin"
)

const commandLine = `start-from-init --masterkey MasterkeyNeedsToHave32Characters --tlsMode disabled --config ../../e2e/config/localhost/zitadel.yaml --steps ../../e2e/config/localhost/zitadel.yaml`

var (
Tester *integration.Tester
)
Expand All @@ -21,9 +23,15 @@ func TestMain(m *testing.M) {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()

Tester = integration.NewTester(ctx, strings.Split(commandLine, " "))
Tester = integration.NewTester(ctx)
defer Tester.Done()

return m.Run()
}())
}

func TestServer_Healthz(t *testing.T) {
client := admin.NewAdminServiceClient(Tester.ClientConn)
_, err := client.Healthz(context.TODO(), &admin.HealthzRequest{})
require.NoError(t, err)
}
16 changes: 0 additions & 16 deletions internal/api/grpc/admin/information_test.go

This file was deleted.

2 changes: 2 additions & 0 deletions internal/api/grpc/errors/caos_errors_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !integration

package errors

import (
Expand Down
2 changes: 2 additions & 0 deletions internal/api/grpc/header_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !integration

package grpc

import (
Expand Down
2 changes: 2 additions & 0 deletions internal/api/grpc/management/idp_converter_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !integration

package management

import (
Expand Down
2 changes: 2 additions & 0 deletions internal/api/grpc/server/middleware/auth_interceptor_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !integration

package middleware

import (
Expand Down
2 changes: 2 additions & 0 deletions internal/api/grpc/server/middleware/error_interceptor_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !integration

package middleware

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !integration

package middleware

import (
Expand Down
2 changes: 2 additions & 0 deletions internal/api/grpc/server/probes_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !integration

package server

import (
Expand Down
2 changes: 2 additions & 0 deletions internal/api/grpc/system/failed_event_converter_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !integration

package system_test

import (
Expand Down
10 changes: 10 additions & 0 deletions internal/integration/config/cockroach.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Database:
cockroach:
Host: localhost
Port: 26257
Database: zitadel
Options: ""
User:
Username: zitadel
Admin:
Username: root
15 changes: 15 additions & 0 deletions internal/integration/config/postgres.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Database:
postgres:
Host: localhost
Port: 5432
Database: zitadel
MaxOpenConns: 20
MaxIdleConns: 10
User:
Username: zitadel
SSL:
Mode: disable
Admin:
Username: zitadel
SSL:
Mode: disable
38 changes: 38 additions & 0 deletions internal/integration/config/zitadel.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Log:
Level: debug

TLS:
Enabled: false

FirstInstance:
Org:
Human:
PasswordChangeRequired: false

LogStore:
Access:
Database:
Enabled: true
Debounce:
MinFrequency: 0s
MaxBulkSize: 0
Execution:
Database:
Enabled: true
Stdout:
Enabled: true

Quotas:
Access:
ExhaustedCookieKey: "zitadel.quota.limiting"
ExhaustedCookieMaxAge: "60s"

Projections:
Customizations:
NotificationsQuotas:
RequeueEvery: 1s

DefaultInstance:
LoginPolicy:
MfaInitSkipLifetime: "0"

42 changes: 36 additions & 6 deletions internal/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
package integration

import (
"bytes"
"context"
_ "embed"
"fmt"
"os"
"strings"
"sync"

"github.com/spf13/viper"
"github.com/zitadel/logging"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
Expand All @@ -15,13 +19,24 @@ import (
"github.com/zitadel/zitadel/cmd/start"
)

var (
//go:embed config/zitadel.yaml
zitadelYAML []byte
//go:embed config/cockroach.yaml
cockroachYAML []byte
//go:embed config/postgres.yaml
postgresYAML []byte
)

type Tester struct {
*start.Server
ClientConn *grpc.ClientConn

wg sync.WaitGroup // used for shutdown
}

const commandLine = `start-from-init --masterkey MasterkeyNeedsToHave32Characters --tlsMode disabled`

func (s *Tester) createClientConn(ctx context.Context) {
target := fmt.Sprintf("localhost:%d", s.Config.Port)
cc, err := grpc.DialContext(ctx, target,
Expand All @@ -45,16 +60,31 @@ func (s *Tester) Done() {
s.wg.Wait()
}

func NewTester(ctx context.Context, args []string) *Tester {
tester := new(Tester)
func NewTester(ctx context.Context) *Tester {
args := strings.Split(commandLine, " ")

sc := make(chan *start.Server)
cmd := cmd.New(os.Stdout, os.Stdin, args, sc)
cmd.SetArgs(args)
err := viper.MergeConfig(bytes.NewBuffer(zitadelYAML))
logging.OnError(err).Fatal()

flavor := os.Getenv("INTEGRATION_DB_FLAVOR")
switch flavor {
case "cockroach":
err = viper.MergeConfig(bytes.NewBuffer(cockroachYAML))
case "postgres":
err = viper.MergeConfig(bytes.NewBuffer(postgresYAML))
default:
logging.New().WithField("flavor", flavor).Fatal("unknown db flavor set in INTEGRATION_DB_FLAVOR")
}
logging.OnError(err).Fatal()

tester := new(Tester)
tester.wg.Add(1)
go func(wg *sync.WaitGroup) {
defer wg.Done()

cmd := cmd.New(os.Stdout, os.Stdin, args, sc)
cmd.SetArgs(args)
logging.OnError(cmd.Execute()).Fatal()
wg.Done()
}(&tester.wg)

select {
Expand Down
7 changes: 3 additions & 4 deletions internal/integration/integration_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
//go:build integration

package integration

import (
"context"
"strings"
"testing"
"time"
)

const commandLine = `start-from-init --masterkey MasterkeyNeedsToHave32Characters --tlsMode disabled --config ../../e2e/config/localhost/zitadel.yaml --steps ../../e2e/config/localhost/zitadel.yaml`

func TestNewTester(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

s := NewTester(ctx, strings.Split(commandLine, " "))
s := NewTester(ctx)
defer s.Done()
}

0 comments on commit 7908408

Please sign in to comment.