@@ -23,9 +23,13 @@ package tests
23
23
24
24
import (
25
25
"context"
26
+ "fmt"
26
27
"testing"
27
28
28
29
"github.com/dchest/uniuri"
30
+ "github.com/stretchr/testify/assert"
31
+
32
+ driver "github.com/arangodb/go-driver"
29
33
30
34
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha"
31
35
kubeArangoClient "github.com/arangodb/kube-arangodb/pkg/client"
@@ -77,24 +81,17 @@ func deploymentSubTest(t *testing.T, mode api.DeploymentMode, engine api.Storage
77
81
deploymentTemplate .Spec .SetDefaults (deploymentTemplate .GetName ()) // this must be last
78
82
79
83
// 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 ))
84
86
85
87
// 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 ))
90
90
91
91
// Create a database client
92
92
ctx := context .Background ()
93
93
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 ))
98
95
99
96
// Cleanup
100
97
removeDeployment (deploymentClient , deploymentTemplate .GetName (), k8sNameSpace )
@@ -124,40 +121,57 @@ func TestMultiDeployment1(t *testing.T) {
124
121
deploymentTemplate2 .Spec .SetDefaults (deploymentTemplate2 .GetName ()) // this must be last
125
122
126
123
// 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 ))
131
126
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 ))
136
129
137
130
// 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 ))
142
133
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 ))
147
136
148
137
// Create a database client
149
138
ctx := context .Background ()
150
-
151
139
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 ))
155
141
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" )
159
163
160
164
// Cleanup
161
165
removeDeployment (deploymentClient , deploymentTemplate1 .GetName (), k8sNameSpace )
162
166
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
163
177
}
0 commit comments