mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 03:24:26 +00:00
add github action for integration tests
This commit is contained in:
parent
a22b58f1c0
commit
79084089ea
35
.github/workflows/integration.yml
vendored
Normal file
35
.github/workflows/integration.yml
vendored
Normal file
@ -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
e2e/config/integration/docker-compose.yaml
Normal file
24
e2e/config/integration/docker-compose.yaml
Normal file
@ -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
|
@ -1,3 +1,5 @@
|
|||||||
|
//go:build !integration
|
||||||
|
|
||||||
package admin
|
package admin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
//go:build !integration
|
||||||
|
|
||||||
package admin
|
package admin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
//go:build !integration
|
||||||
|
|
||||||
package admin
|
package admin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
|
//go:build integration
|
||||||
|
|
||||||
package admin_test
|
package admin_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/zitadel/zitadel/internal/integration"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
|
||||||
|
|
||||||
const commandLine = `start-from-init --masterkey MasterkeyNeedsToHave32Characters --tlsMode disabled --config ../../e2e/config/localhost/zitadel.yaml --steps ../../e2e/config/localhost/zitadel.yaml`
|
"github.com/zitadel/zitadel/internal/integration"
|
||||||
|
"github.com/zitadel/zitadel/pkg/grpc/admin"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Tester *integration.Tester
|
Tester *integration.Tester
|
||||||
@ -21,9 +23,15 @@ func TestMain(m *testing.M) {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
Tester = integration.NewTester(ctx, strings.Split(commandLine, " "))
|
Tester = integration.NewTester(ctx)
|
||||||
defer Tester.Done()
|
defer Tester.Done()
|
||||||
|
|
||||||
return m.Run()
|
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)
|
||||||
|
}
|
@ -1,16 +0,0 @@
|
|||||||
package admin_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
"github.com/zitadel/zitadel/pkg/grpc/admin"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestServer_Healthz(t *testing.T) {
|
|
||||||
client := admin.NewAdminServiceClient(Tester.ClientConn)
|
|
||||||
_, err := client.Healthz(context.TODO(), &admin.HealthzRequest{})
|
|
||||||
require.NoError(t, err)
|
|
||||||
}
|
|
@ -1,3 +1,5 @@
|
|||||||
|
//go:build !integration
|
||||||
|
|
||||||
package errors
|
package errors
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
//go:build !integration
|
||||||
|
|
||||||
package grpc
|
package grpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
//go:build !integration
|
||||||
|
|
||||||
package management
|
package management
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
//go:build !integration
|
||||||
|
|
||||||
package middleware
|
package middleware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
//go:build !integration
|
||||||
|
|
||||||
package middleware
|
package middleware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
//go:build !integration
|
||||||
|
|
||||||
package middleware
|
package middleware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
//go:build !integration
|
||||||
|
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
//go:build !integration
|
||||||
|
|
||||||
package system_test
|
package system_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
10
internal/integration/config/cockroach.yaml
Normal file
10
internal/integration/config/cockroach.yaml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
Database:
|
||||||
|
cockroach:
|
||||||
|
Host: localhost
|
||||||
|
Port: 26257
|
||||||
|
Database: zitadel
|
||||||
|
Options: ""
|
||||||
|
User:
|
||||||
|
Username: zitadel
|
||||||
|
Admin:
|
||||||
|
Username: root
|
15
internal/integration/config/postgres.yaml
Normal file
15
internal/integration/config/postgres.yaml
Normal file
@ -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
internal/integration/config/zitadel.yaml
Normal file
38
internal/integration/config/zitadel.yaml
Normal file
@ -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"
|
||||||
|
|
@ -2,11 +2,15 @@
|
|||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
_ "embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/spf13/viper"
|
||||||
"github.com/zitadel/logging"
|
"github.com/zitadel/logging"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/credentials/insecure"
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
@ -15,6 +19,15 @@ import (
|
|||||||
"github.com/zitadel/zitadel/cmd/start"
|
"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 {
|
type Tester struct {
|
||||||
*start.Server
|
*start.Server
|
||||||
ClientConn *grpc.ClientConn
|
ClientConn *grpc.ClientConn
|
||||||
@ -22,6 +35,8 @@ type Tester struct {
|
|||||||
wg sync.WaitGroup // used for shutdown
|
wg sync.WaitGroup // used for shutdown
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const commandLine = `start-from-init --masterkey MasterkeyNeedsToHave32Characters --tlsMode disabled`
|
||||||
|
|
||||||
func (s *Tester) createClientConn(ctx context.Context) {
|
func (s *Tester) createClientConn(ctx context.Context) {
|
||||||
target := fmt.Sprintf("localhost:%d", s.Config.Port)
|
target := fmt.Sprintf("localhost:%d", s.Config.Port)
|
||||||
cc, err := grpc.DialContext(ctx, target,
|
cc, err := grpc.DialContext(ctx, target,
|
||||||
@ -45,16 +60,31 @@ func (s *Tester) Done() {
|
|||||||
s.wg.Wait()
|
s.wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTester(ctx context.Context, args []string) *Tester {
|
func NewTester(ctx context.Context) *Tester {
|
||||||
tester := new(Tester)
|
args := strings.Split(commandLine, " ")
|
||||||
|
|
||||||
sc := make(chan *start.Server)
|
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)
|
tester.wg.Add(1)
|
||||||
go func(wg *sync.WaitGroup) {
|
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()
|
logging.OnError(cmd.Execute()).Fatal()
|
||||||
|
wg.Done()
|
||||||
}(&tester.wg)
|
}(&tester.wg)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
@ -1,18 +1,17 @@
|
|||||||
|
//go:build integration
|
||||||
|
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"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) {
|
func TestNewTester(t *testing.T) {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
s := NewTester(ctx, strings.Split(commandLine, " "))
|
s := NewTester(ctx)
|
||||||
defer s.Done()
|
defer s.Done()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user