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

Support different runtime environments out-of-the-box. #183

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
49 changes: 49 additions & 0 deletions .github/workflows/docker-repo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Get ESDB Docker repo
on:
workflow_call:
inputs:
runtime_env:
description: The runtime environment we want to run like release or staging
type: string
default: release

outputs:
docker_repo:
description: ESDB docker repository
value: ${{ jobs.provide_docker.outputs.docker_repo }}

docker_container:
description: ESDB docker container
value: ${{ jobs.provide_docker.outputs.docker_container }}

jobs:
provide_docker:
runs-on: ubuntu-latest
outputs:
docker_repo: ${{ steps.set_docker.outputs.docker_repo }}
docker_container: ${{ steps.set_docker.outputs.docker_container }}
steps:
- name: Set ESDB docker repo
id: set_docker
run: |
case ${{ inputs.runtime_env }} in
"release")
echo "docker_repo=eventstore-ce" >> $GITHUB_OUTPUT
echo "docker_container=eventstoredb-ce" >> $GITHUB_OUTPUT
;;

"staging")
echo "docker_repo=eventstore-staging-ce" >> $GITHUB_OUTPUT
echo "docker_container=eventstoredb-oss" >> $GITHUB_OUTPUT
;;

"enterprise")
echo "docker_repo=eventstore-ee" >> $GITHUB_OUTPUT
echo "docker_container=eventstoredb-commercial" >> $GITHUB_OUTPUT
;;

*)
echo "docker_repo=eventstore-ce" >> $GITHUB_OUTPUT
echo "docker_container=eventstoredb-ce" >> $GITHUB_OUTPUT
;;
esac
4 changes: 3 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ jobs:
run: make misc

tests:
needs: build
needs:
- go-version
- build
name: Tests

strategy:
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/test-dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ name: "Dispatch"
on:
workflow_dispatch:
inputs:
runtime_env:
description: The runtime environment. release, staging or enterprise
type: string
default: release

version:
description: "Version tag"
description: Docker version tag
required: true
type: string

Expand All @@ -18,4 +23,5 @@ jobs:
uses: ./.github/workflows/tests.yml
with:
esdb_version: ${{ inputs.version }}
runtime_env: ${{ inputs.runtime_env }}
go_version: ${{ needs.go-version.outputs.go_version }}
26 changes: 22 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ name: tests workflow
on:
workflow_call:
inputs:
runtime_env:
type: string
default: release

esdb_version:
required: true
type: string
Expand All @@ -12,13 +16,19 @@ on:
type: string

jobs:
provide_docker:
uses: ./.github/workflows/docker-repo.yml
with:
runtime_env: ${{ inputs.runtime_env }}

single_node:
needs: provide_docker
name: Single node

strategy:
fail-fast: false
matrix:
test: [Streams, PersistentSubscriptions, Expectations, Projections]
test: [Streams, PersistentSubscriptions, Projections]

runs-on: ubuntu-latest
steps:
Expand All @@ -33,11 +43,14 @@ jobs:
- name: Run Go Tests
run: make ci CI_TARGET=Test${{ matrix.test }}
env:
EVENTSTORE_DOCKER_TAG_ENV: ${{ inputs.esdb_version }}
ESDB_DOCKER_REPO: ${{ needs.provide_docker.outputs.docker_repo }}
ESDB_DOCKER_CONTAINER: ${{ needs.provide_docker.outputs.docker_container }}
ESDB_DOCKER_CONTAINER_VERSION: ${{ inputs.esdb_version }}
EVENTSTORE_INSECURE: true

secure:
name: Secure
needs: provide_docker

strategy:
fail-fast: false
Expand All @@ -58,11 +71,14 @@ jobs:
run: make ci CI_TARGET=Test${{ matrix.test }}

env:
EVENTSTORE_DOCKER_TAG_ENV: ${{ inputs.esdb_version }}
ESDB_DOCKER_REPO: ${{ needs.provide_docker.outputs.docker_repo }}
ESDB_DOCKER_CONTAINER: ${{ needs.provide_docker.outputs.docker_container }}
ESDB_DOCKER_CONTAINER_VERSION: ${{ inputs.esdb_version }}
EVENTSTORE_INSECURE: false

cluster:
name: Cluster
needs: provide_docker

strategy:
fail-fast: false
Expand All @@ -80,7 +96,9 @@ jobs:
run: |
docker compose -f cluster-docker-compose.yml up -d
env:
EVENTSTORE_DOCKER_TAG_ENV: ${{ inputs.esdb_version }}
ESDB_DOCKER_REPO: ${{ needs.provide_docker.outputs.docker_repo }}
ESDB_DOCKER_CONTAINER: ${{ needs.provide_docker.outputs.docker_container }}
ESDB_DOCKER_CONTAINER_VERSION: ${{ inputs.esdb_version }}

- name: Run Go Tests
run: make ci CI_TARGET=Test${{ matrix.test }}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ endif

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

.PHONY: secureNode
secureNode: ## Run tests against a secure node.
Expand Down
24 changes: 4 additions & 20 deletions cluster-docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.5"

services:
volumes-provisioner:
image: hasnat/volumes-provisioner
Expand All @@ -25,8 +23,8 @@ services:
depends_on:
- volumes-provisioner

esdb-node1:
image: docker.eventstore.com/eventstore-ce/eventstoredb-ce:${EVENTSTORE_DOCKER_TAG_ENV:-latest}
esdb-node1: &template
image: docker.eventstore.com/${ESDB_DOCKER_REPO:-eventstore-ce}/${ESDB_DOCKER_CONTAINER:-eventstoredb-ce}:${ESDB_DOCKER_CONTAINER_VERSION:-latest}
env_file:
- shared.env
environment:
Expand All @@ -47,9 +45,7 @@ services:
- cert-gen

esdb-node2:
image: docker.eventstore.com/eventstore-ce/eventstoredb-ce:${EVENTSTORE_DOCKER_TAG_ENV:-latest}
env_file:
- shared.env
<<: *template
environment:
- EVENTSTORE_GOSSIP_SEED=172.30.240.11:2113,172.30.240.13:2113
- EVENTSTORE_INT_IP=172.30.240.12
Expand All @@ -61,16 +57,9 @@ services:
networks:
clusternetwork:
ipv4_address: 172.30.240.12
volumes:
- ./certs:/etc/eventstore/certs
restart: unless-stopped
depends_on:
- cert-gen

esdb-node3:
image: docker.eventstore.com/eventstore-ce/eventstoredb-ce:${EVENTSTORE_DOCKER_TAG_ENV:-latest}
env_file:
- shared.env
<<: *template
environment:
- EVENTSTORE_GOSSIP_SEED=172.30.240.11:2113,172.30.240.12:2113
- EVENTSTORE_INT_IP=172.30.240.13
Expand All @@ -82,11 +71,6 @@ services:
networks:
clusternetwork:
ipv4_address: 172.30.240.13
volumes:
- ./certs:/etc/eventstore/certs
restart: unless-stopped
depends_on:
- cert-gen

networks:
clusternetwork:
Expand Down
10 changes: 10 additions & 0 deletions esdb/append_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ func createTestEvent() esdb.EventData {
return event
}

func createTestEvents(count int) []esdb.EventData {
var events []esdb.EventData

for i := 0; i < count; i++ {
events = append(events, createTestEvent())
}

return events
}

func collectStreamEvents(stream *esdb.ReadStream) ([]*esdb.ResolvedEvent, error) {
events := []*esdb.ResolvedEvent{}

Expand Down
5 changes: 5 additions & 0 deletions esdb/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ func NewClient(configuration *Configuration) (*Client, error) {
}, nil
}

// Config Returns client's current configuration.
func (client *Client) Config() *Configuration {
return client.config
}

// Close Closes a connection and cleans all its allocated resources.
func (client *Client) Close() error {
client.grpcClient.close()
Expand Down
40 changes: 3 additions & 37 deletions esdb/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@ func TestStreams(t *testing.T) {
defer emptyClient.Close()
}

populatedContainer, populatedClient := CreatePopulatedDatabase(t)

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

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

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

Expand All @@ -33,8 +23,8 @@ func TestStreams(t *testing.T) {
}

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

Expand All @@ -59,18 +49,8 @@ func TestPersistentSubscriptions(t *testing.T) {
defer emptyClient.Close()
}

populatedContainer, populatedClient := CreatePopulatedDatabase(t)

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

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

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

func TestProjections(t *testing.T) {
Expand All @@ -87,20 +67,6 @@ func TestProjections(t *testing.T) {
ProjectionTests(t, emptyClient)
}

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

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

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

ReadAllTests(t, populatedClient)
}

func TestMisc(t *testing.T) {
ConnectionStringTests(t)
TestPositionParsing(t)
Expand Down
Loading