@@ -23,9 +23,13 @@ package tests
2323
2424import (
2525 "context"
26+ "fmt"
2627 "testing"
2728
2829 "github.com/dchest/uniuri"
30+ "github.com/stretchr/testify/assert"
31+
32+ driver "github.com/arangodb/go-driver"
2933
3034 api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha"
3135 kubeArangoClient "github.com/arangodb/kube-arangodb/pkg/client"
@@ -77,24 +81,17 @@ func deploymentSubTest(t *testing.T, mode api.DeploymentMode, engine api.Storage
7781 deploymentTemplate .Spec .SetDefaults (deploymentTemplate .GetName ()) // this must be last
7882
7983 // Create deployment
80- deployment , err := deploymentClient .DatabaseV1alpha ().ArangoDeployments (k8sNameSpace ).Create (deploymentTemplate )
81- if err != nil {
82- t .Fatalf ("Create deployment failed: %v" , err )
83- }
84+ _ , err := deploymentClient .DatabaseV1alpha ().ArangoDeployments (k8sNameSpace ).Create (deploymentTemplate )
85+ assert .NoError (t , err , fmt .Sprintf ("Create deployment failed: %v" , err ))
8486
8587 // Wait for deployment to be ready
86- deployment , err = waitUntilDeployment (deploymentClient , deploymentTemplate .GetName (), k8sNameSpace , deploymentIsReady ())
87- if err != nil {
88- t .Fatalf ("Deployment not running in time: %v" , err )
89- }
88+ deployment , err := waitUntilDeployment (deploymentClient , deploymentTemplate .GetName (), k8sNameSpace , deploymentIsReady ())
89+ assert .NoError (t , err , fmt .Sprintf ("Deployment not running in time: %v" , err ))
9090
9191 // Create a database client
9292 ctx := context .Background ()
9393 DBClient := mustNewArangodDatabaseClient (ctx , k8sClient , deployment , t )
94-
95- if err := waitUntilArangoDeploymentHealthy (deployment , DBClient , k8sClient , "" ); err != nil {
96- t .Fatalf ("Deployment not healthy in time: %v" , err )
97- }
94+ assert .NoError (t , waitUntilArangoDeploymentHealthy (deployment , DBClient , k8sClient , "" ), fmt .Sprintf ("Deployment not healthy in time: %v" , err ))
9895
9996 // Cleanup
10097 removeDeployment (deploymentClient , deploymentTemplate .GetName (), k8sNameSpace )
@@ -124,40 +121,57 @@ func TestMultiDeployment1(t *testing.T) {
124121 deploymentTemplate2 .Spec .SetDefaults (deploymentTemplate2 .GetName ()) // this must be last
125122
126123 // Create deployment
127- deployment1 , err := deploymentClient .DatabaseV1alpha ().ArangoDeployments (k8sNameSpace ).Create (deploymentTemplate1 )
128- if err != nil {
129- t .Fatalf ("Create deployment failed: %v" , err )
130- }
124+ _ , err := deploymentClient .DatabaseV1alpha ().ArangoDeployments (k8sNameSpace ).Create (deploymentTemplate1 )
125+ assert .NoError (t , err , fmt .Sprintf ("Deployment creation failed: %v" , err ))
131126
132- deployment2 , err := deploymentClient .DatabaseV2alpha ().ArangoDeployments (k8sNameSpace ).Create (deploymentTemplate2 )
133- if err != nil {
134- t .Fatalf ("Create deployment failed: %v" , err )
135- }
127+ _ , err = deploymentClient .DatabaseV1alpha ().ArangoDeployments (k8sNameSpace ).Create (deploymentTemplate2 )
128+ assert .NoError (t , err , fmt .Sprintf ("Deployment creation failed: %v" , err ))
136129
137130 // Wait for deployment to be ready
138- deployment1 , err = waitUntilDeployment (deploymentClient , deploymentTemplate1 .GetName (), k8sNameSpace , deploymentIsReady ())
139- if err != nil {
140- t .Fatalf ("Deployment not running in time: %v" , err )
141- }
131+ deployment1 , err := waitUntilDeployment (deploymentClient , deploymentTemplate1 .GetName (), k8sNameSpace , deploymentIsReady ())
132+ assert .NoError (t , err , fmt .Sprintf ("Deployment not running in time: %v" , err ))
142133
143- deployment2 , err = waitUntilDeployment (deploymentClient , deploymentTemplate2 .GetName (), k8sNameSpace , deploymentIsReady ())
144- if err != nil {
145- t .Fatalf ("Deployment not running in time: %v" , err )
146- }
134+ deployment2 , err := waitUntilDeployment (deploymentClient , deploymentTemplate2 .GetName (), k8sNameSpace , deploymentIsReady ())
135+ assert .NoError (t , err , fmt .Sprintf ("Deployment not running in time: %v" , err ))
147136
148137 // Create a database client
149138 ctx := context .Background ()
150-
151139 DBClient1 := mustNewArangodDatabaseClient (ctx , k8sClient , deployment1 , t )
152- if err := waitUntilArangoDeploymentHealthy (deployment1 , DBClient1 , k8sClient , "" ); err != nil {
153- t .Fatalf ("Deployment not healthy in time: %v" , err )
154- }
140+ assert .NoError (t , waitUntilArangoDeploymentHealthy (deployment1 , DBClient1 , k8sClient , "" ), fmt .Sprintf ("Deployment not healthy in time: %v" , err ))
155141 DBClient2 := mustNewArangodDatabaseClient (ctx , k8sClient , deployment2 , t )
156- if err := waitUntilArangoDeploymentHealthy (deployment2 , DBClient2 , k8sClient , "" ); err != nil {
157- t .Fatalf ("Deployment not healthy in time: %v" , err )
158- }
142+ assert .NoError (t , waitUntilArangoDeploymentHealthy (deployment1 , DBClient1 , k8sClient , "" ), fmt .Sprintf ("Deployment not healthy in time: %v" , err ))
143+
144+ db1 , err := DBClient1 .Database (ctx , "_system" )
145+ assert .NoError (t , err , "failed to get database" )
146+ _ , err = db1 .CreateCollection (ctx , "col1" , nil )
147+ assert .NoError (t , err , "failed to create collection" )
148+
149+ db2 , err := DBClient2 .Database (ctx , "_system" )
150+ assert .NoError (t , err , "failed to get database" )
151+ _ , err = db2 .CreateCollection (ctx , "col2" , nil )
152+ assert .NoError (t , err , "failed to create collection" )
153+
154+ collections1 , err := db1 .Collections (ctx )
155+ assert .NoError (t , err , "failed to get collections" )
156+ collections2 , err := db2 .Collections (ctx )
157+ assert .NoError (t , err , "failed to get collections" )
158+
159+ assert .True (t , containsCollection (collections1 , "col1" ), "collection missing" )
160+ assert .True (t , containsCollection (collections2 , "col2" ), "collection missing" )
161+ assert .False (t , containsCollection (collections1 , "col2" ), "collection must not be in this deployment" )
162+ assert .False (t , containsCollection (collections2 , "col1" ), "collection must not be in this deployment" )
159163
160164 // Cleanup
161165 removeDeployment (deploymentClient , deploymentTemplate1 .GetName (), k8sNameSpace )
162166 removeDeployment (deploymentClient , deploymentTemplate2 .GetName (), k8sNameSpace )
167+
168+ }
169+
170+ func containsCollection (colls []driver.Collection , name string ) bool {
171+ for _ , col := range colls {
172+ if name == col .Name () {
173+ return true
174+ }
175+ }
176+ return false
163177}
0 commit comments