Skip to content

Commit

Permalink
Fix missing cluster env in test workflow
Browse files Browse the repository at this point in the history
- Add workflow dispatch trigger
  • Loading branch information
w1am committed Oct 16, 2023
1 parent 3a0f7af commit bbfc4ae
Show file tree
Hide file tree
Showing 25 changed files with 292 additions and 141 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
name: Build and Run Tests
on:
pull_request:
push:
branches:
- master
on: [pull_request]
jobs:
build:
name: Build
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-2019, macos-latest]

Expand All @@ -25,6 +22,9 @@ jobs:
if: ${{ matrix.os != 'windows-2019' }}
run: ./build.sh --generate-protos

- name: Misc tests
run: go test -v ./esdb -run TestMisc

tests:
needs: build
name: Tests
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/test-dispatch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "Dispatch"

on:
workflow_dispatch:
inputs:
version:
description: "Version tag"
required: true
type: string

jobs:
test:
name: Test
uses: ./.github/workflows/tests.yml
with:
esdb_version: ${{ inputs.version }}
16 changes: 9 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ jobs:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Generate certificates
run: docker-compose --file docker-compose.yml up

- name: Run Go Tests
run: go test -v ./esdb -run Test${{ matrix.test }}
env:
EVENTSTORE_DOCKER_TAG_ENV: ${{ inputs.esdb_version }}
EVENTSTORE_INSECURE: true

secure:
name: Secure
Expand All @@ -35,6 +39,8 @@ jobs:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Generate certificates
run: docker-compose --file docker-compose.yml up

Expand All @@ -43,11 +49,7 @@ jobs:

env:
EVENTSTORE_DOCKER_TAG_ENV: ${{ inputs.esdb_version }}
SECURE: true

- name: Shutdown secure
run: docker-compose -f docker-compose.yml down
if: always()
EVENTSTORE_INSECURE: false

cluster:
name: Cluster
Expand All @@ -70,8 +72,8 @@ jobs:

env:
EVENTSTORE_DOCKER_TAG_ENV: ${{ inputs.esdb_version }}
EVENTSTORE_INSECURE: false
CLUSTER: true
SECURE: true

- name: Shutdown cluster
run: docker-compose -f cluster-docker-compose.yml down
Expand Down
50 changes: 42 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,58 @@
.DEFAULT_GOAL := help

help:
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

OS := $(shell uname)

GENERATE_PROTOS_FLAG :=

.PHONY: build
build: ## Build based on the OS.
ifeq ($(OS),Linux)
./build.sh $(GENERATE_PROTOS_FLAG)
else ifeq ($(OS),Darwin)
./build.sh $(GENERATE_PROTOS_FLAG)
else
.\build.ps1 $(GENERATE_PROTOS_FLAG)
endif

.PHONY: generate-protos
generate-protos: ## Regenerate protobuf and gRPC files while building.
ifeq ($(OS),Linux)
$(eval GENERATE_PROTOS_FLAG := --generate-protos)
else
$(eval GENERATE_PROTOS_FLAG := -generateProtos)
endif
build


DOCKER_COMPOSE_CMD := $(shell command -v docker-compose 2> /dev/null)
ifeq ($(DOCKER_COMPOSE_CMD),)
DOCKER_COMPOSE_CMD := docker compose
endif

.PHONY: singleNode
singleNode:
@go test -v ./esdb -run 'TestStreams|TestPersistentSubscriptions|TestExpectations'
singleNode: ## Run tests against a single node.
@EVENTSTORE_INSECURE=true go test -count=1 -v ./esdb -run 'TestStreams|TestPersistentSubscriptions|Expectations'

.PHONY: secureNode
secureNode:
secureNode: ## Run tests against a secure node.
@$(DOCKER_COMPOSE_CMD) down -v
@$(DOCKER_COMPOSE_CMD) pull
@$(DOCKER_COMPOSE_CMD) up -d
@EVENTSTORE_INSECURE=FALSE go test -v ./esdb -run 'TestStreams|TestPersistentSubscriptions'
@EVENTSTORE_INSECURE=false go test -v ./esdb -run 'TestStreams|TestPersistentSubscriptions'
@$(DOCKER_COMPOSE_CMD) down

.PHONY: clusterNode
clusterNode:
@$(DOCKER_COMPOSE_CMD) -f cluster-docker-compose.yml down -v
clusterNode: ## Run tests against a cluster node.
@$(DOCKER_COMPOSE_CMD) -f cluster-docker-compose.yml down --remove-orphans -v
@$(DOCKER_COMPOSE_CMD) -f cluster-docker-compose.yml pull
@$(DOCKER_COMPOSE_CMD) -f cluster-docker-compose.yml up -d
@EVENTSTORE_INSECURE=FALSE go test -v ./esdb -run 'TestStreams|TestPersistentSubscriptions'
@$(DOCKER_COMPOSE_CMD) -f cluster-docker-compose.yml down
@echo "Waiting for services to be fully ready..."
@sleep 5
@EVENTSTORE_INSECURE=false CLUSTER=true go test -count=1 -v ./esdb -run 'TestStreams|TestPersistentSubscriptions'
@$(DOCKER_COMPOSE_CMD) -f cluster-docker-compose.yml down --remove-orphans

.PHONY: test
test: singleNode secureNode clusterNode ## Run all tests.
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,8 @@ To also regenerate protobuf and gRPC files while building

## Run tests

Run docker compose for generating certificates:

```shell
docker-compose up
docker-compose down
```

```shell
docker-compose -f cluster-docker-compose.yml up -d
go test ./esdb
docker-compose -f cluster-docker-compose.yml down
make test
```

By default the tests use `ghcr.io/eventstore/eventstore:ci`. To override this, set the `EVENTSTORE_DOCKER_TAG_ENV` environment variable to the tag you wish to use:
Expand Down
4 changes: 3 additions & 1 deletion esdb/append_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ func appendWithInvalidStreamRevision(db *esdb.Client) TestCall {

func appendToSystemStreamWithIncorrectCredentials(container *Container) TestCall {
return func(t *testing.T) {
if container == nil {
isInsecure := GetEnvOrDefault("EVENTSTORE_INSECURE", "true") == "true"

if container == nil || isInsecure {
t.Skip()
}

Expand Down
91 changes: 57 additions & 34 deletions esdb/client_test.go
Original file line number Diff line number Diff line change
@@ -1,69 +1,92 @@
package esdb_test

import (
"os"
"testing"
)

type DatabaseType int

const (
Empty DatabaseType = iota
Prepopulated
Insecure
Cluster
)

func TestStreams(t *testing.T) {
emptyContainer, emptyClient := CreateEmptyDatabase(t)
defer emptyContainer.Close()
defer emptyClient.Close()

if emptyContainer != nil {
defer emptyContainer.Close()
}

if emptyClient != nil {
defer emptyClient.Close()
}

populatedContainer, populatedClient := CreatePopulatedDatabase(t)
defer populatedContainer.Close()
defer populatedClient.Close()

if populatedContainer != nil {
defer populatedContainer.Close()
}

if populatedClient != nil {
defer populatedClient.Close()
}

isCluster := GetEnvOrDefault("CLUSTER", "false") == "true"
isInsecure := GetEnvOrDefault("EVENTSTORE_INSECURE", "true") == "true"

if isCluster {
ClusterTests(t)
}

AppendTests(t, emptyContainer, emptyClient)
ReadStreamTests(t, emptyClient, populatedClient)
SubscriptionTests(t, emptyClient, populatedClient)
DeleteTests(t, emptyClient)
ConnectionTests(t, emptyContainer)

if !isCluster {
if !isInsecure {
TLSTests(t, emptyContainer)
SecureAuthenticationTests(t, emptyClient)
} else {
InsecureAuthenticationTests(t, emptyClient)
}
}
}

func TestPersistentSubscriptions(t *testing.T) {
emptyContainer, emptyClient := CreateEmptyDatabase(t)
defer emptyContainer.Close()
defer emptyClient.Close()

if emptyContainer != nil {
defer emptyContainer.Close()
}

if emptyClient != nil {
defer emptyClient.Close()
}

populatedContainer, populatedClient := CreatePopulatedDatabase(t)
defer populatedContainer.Close()
defer populatedClient.Close()

if populatedContainer != nil {
defer populatedContainer.Close()
}

if populatedClient != nil {
defer populatedClient.Close()
}

PersistentSubReadTests(t, emptyClient)
PersistentSubTests(t, emptyClient, populatedClient)
}

func TestExpectations(t *testing.T) {
populatedContainer, populatedClient := CreatePopulatedDatabase(t)
defer populatedContainer.Close()
defer populatedClient.Close()

if populatedContainer != nil {
defer populatedContainer.Close()
}

if populatedClient != nil {
defer populatedClient.Close()
}

ReadAllTests(t, populatedClient)
}

func TestMisc(t *testing.T) {
os.Setenv("EVENTSTORE_INSECURE", "false")
emptyContainer, emptyClient := CreateEmptyDatabase(t)
defer emptyContainer.Close()
defer emptyClient.Close()

TLSTests(t, emptyContainer)
SecureAuthenticationTests(t, emptyClient)

os.Setenv("EVENTSTORE_INSECURE", "true")
insecureContainer, insecureClient := CreateEmptyDatabase(t)
defer insecureContainer.Close()
defer insecureClient.Close()

InsecureAuthenticationTests(t, insecureClient)
// tests that don't require a database
}
2 changes: 1 addition & 1 deletion esdb/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func ConnectionTests(t *testing.T, emptyDB *Container) {

func closeConnection(container *Container) TestCall {
return func(t *testing.T) {
db := CreateTestClient(container, t)
db := GetClient(t, container)

testEvent := createTestEvent()
testEvent.EventID = uuid.FromStringOrNil("38fffbc2-339e-11ea-8c7b-784f43837872")
Expand Down
Loading

0 comments on commit bbfc4ae

Please sign in to comment.