Skip to content

Commit

Permalink
Merge pull request #340 from gatewayd-io/add-tests-for-multi-tenancy
Browse files Browse the repository at this point in the history
Add configuration and test for multi-tenancy
  • Loading branch information
mostafa authored Sep 27, 2023
2 parents 601d003 + 8e4a835 commit b51cdbf
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ jobs:
--health-interval 10s
--health-timeout 5s
--health-retries 5
postgres2:
image: postgres
env:
POSTGRES_HOST: postgres2
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5433:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
Expand Down
55 changes: 55 additions & 0 deletions cmd/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,61 @@ func Test_runCmd(t *testing.T) {
assert.NoError(t, os.Remove(globalTestConfigFile))
}

func Test_runCmdWithMultiTenancy(t *testing.T) {
// Create a test plugins config file.
_, err := executeCommandC(rootCmd, "plugin", "init", "--force", "-p", pluginTestConfigFile)
assert.NoError(t, err, "plugin init command should not have returned an error")
assert.FileExists(t, pluginTestConfigFile, "plugin init command should have created a config file")

stopChan = make(chan struct{})

var waitGroup sync.WaitGroup
waitGroup.Add(1)
go func(waitGroup *sync.WaitGroup) {
time.Sleep(500 * time.Millisecond)

StopGracefully(
runCmd.Context(),
runCmd.Context(),
nil,
nil,
nil,
nil,
loggers[config.Default],
servers,
stopChan,
)

waitGroup.Done()
}(&waitGroup)

waitGroup.Add(1)
go func(waitGroup *sync.WaitGroup) {
// Test run command.
output := capturer.CaptureOutput(func() {
_, err := executeCommandC(
rootCmd, "run", "-c", "testdata/gatewayd.yaml", "-p", pluginTestConfigFile)
assert.NoError(t, err, "run command should not have returned an error")
})
// Print the output for debugging purposes.
runCmd.Print(output)
// Check if GatewayD started and stopped correctly.
assert.Contains(t, output, "GatewayD is running")
assert.Contains(t, output, "There are clients available in the pool count=10 name=default")
assert.Contains(t, output, "There are clients available in the pool count=10 name=test")
assert.Contains(t, output, "GatewayD is listening address=0.0.0.0:15432")
assert.Contains(t, output, "GatewayD is listening address=0.0.0.0:15433")
assert.Contains(t, output, "Stopped all servers\n")

waitGroup.Done()
}(&waitGroup)

waitGroup.Wait()

// Clean up.
assert.NoError(t, os.Remove(pluginTestConfigFile))
}

func Test_runCmdWithCachePlugin(t *testing.T) {
// TODO: Remove this once these global variables are removed from cmd/run.go.
// https://github.com/gatewayd-io/gatewayd/issues/324
Expand Down
44 changes: 44 additions & 0 deletions cmd/testdata/gatewayd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# GatewayD Global Configuration

loggers:
default:
level: info
output: ["console"]
noColor: True
test:
level: info
output: ["console"]
noColor: True

metrics:
default:
enabled: True
test:
enabled: True

clients:
default:
address: localhost:5432
test:
address: localhost:5433

pools:
default:
size: 10
test:
size: 10

proxies:
default:
elastic: False
test:
elastic: False

servers:
default:
address: 0.0.0.0:15432
test:
address: 0.0.0.0:15433

api:
enabled: True

0 comments on commit b51cdbf

Please sign in to comment.