Skip to content

Commit 9b5cd31

Browse files
authored
Merge pull request #119 from arangodb/various-test-fixes
Various renamings in tests such that common names are used.
2 parents b3b6e7b + c3a7cfb commit 9b5cd31

File tree

4 files changed

+82
-82
lines changed

4 files changed

+82
-82
lines changed

tests/auth_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestAuthenticationSingleDefaultSecret(t *testing.T) {
4242

4343
// Secret must now exist
4444
if _, err := waitUntilSecret(kubecli, depl.Spec.Authentication.GetJWTSecretName(), ns, nil, time.Second); err != nil {
45-
t.Fatalf("JWT secret '%s' not found: %v", depl.Spec.Authentication.JWTSecretName, err)
45+
t.Fatalf("JWT secret '%s' not found: %v", depl.Spec.Authentication.GetJWTSecretName(), err)
4646
}
4747

4848
// Create a database client
@@ -59,7 +59,7 @@ func TestAuthenticationSingleDefaultSecret(t *testing.T) {
5959

6060
// Secret must no longer exist
6161
if err := waitUntilSecretNotFound(kubecli, depl.Spec.Authentication.GetJWTSecretName(), ns, time.Minute); err != nil {
62-
t.Fatalf("JWT secret '%s' still found: %v", depl.Spec.Authentication.JWTSecretName, err)
62+
t.Fatalf("JWT secret '%s' still found: %v", depl.Spec.Authentication.GetJWTSecretName(), err)
6363
}
6464
}
6565

@@ -181,7 +181,7 @@ func TestAuthenticationClusterDefaultSecret(t *testing.T) {
181181

182182
// Secret must now exist
183183
if _, err := waitUntilSecret(kubecli, depl.Spec.Authentication.GetJWTSecretName(), ns, nil, time.Second); err != nil {
184-
t.Fatalf("JWT secret '%s' not found: %v", depl.Spec.Authentication.JWTSecretName, err)
184+
t.Fatalf("JWT secret '%s' not found: %v", depl.Spec.Authentication.GetJWTSecretName(), err)
185185
}
186186

187187
// Create a database client
@@ -198,7 +198,7 @@ func TestAuthenticationClusterDefaultSecret(t *testing.T) {
198198

199199
// Secret must no longer exist
200200
if err := waitUntilSecretNotFound(kubecli, depl.Spec.Authentication.GetJWTSecretName(), ns, time.Minute); err != nil {
201-
t.Fatalf("JWT secret '%s' still found: %v", depl.Spec.Authentication.JWTSecretName, err)
201+
t.Fatalf("JWT secret '%s' still found: %v", depl.Spec.Authentication.GetJWTSecretName(), err)
202202
}
203203
}
204204

tests/deployments_test.go

+40-40
Original file line numberDiff line numberDiff line change
@@ -70,33 +70,33 @@ func deploymentSubTest(t *testing.T, mode api.DeploymentMode, engine api.Storage
7070
// check environment
7171
longOrSkip(t)
7272

73-
k8sNameSpace := getNamespace(t)
74-
k8sClient := mustNewKubeClient(t)
75-
deploymentClient := kubeArangoClient.MustNewInCluster()
73+
ns := getNamespace(t)
74+
kubecli := mustNewKubeClient(t)
75+
c := kubeArangoClient.MustNewInCluster()
7676

7777
// Prepare deployment config
78-
deploymentTemplate := newDeployment("test-1-deployment-" + string(mode) + "-" + string(engine) + "-" + uniuri.NewLen(4))
79-
deploymentTemplate.Spec.Mode = api.NewMode(mode)
80-
deploymentTemplate.Spec.StorageEngine = api.NewStorageEngine(engine)
81-
deploymentTemplate.Spec.TLS = api.TLSSpec{} // should auto-generate cert
82-
deploymentTemplate.Spec.SetDefaults(deploymentTemplate.GetName()) // this must be last
78+
depl := newDeployment("test-deployment-" + string(mode) + "-" + string(engine) + "-" + uniuri.NewLen(4))
79+
depl.Spec.Mode = api.NewMode(mode)
80+
depl.Spec.StorageEngine = api.NewStorageEngine(engine)
81+
depl.Spec.TLS = api.TLSSpec{} // should auto-generate cert
82+
depl.Spec.SetDefaults(depl.GetName()) // this must be last
8383

8484
// Create deployment
85-
_, err := deploymentClient.DatabaseV1alpha().ArangoDeployments(k8sNameSpace).Create(deploymentTemplate)
85+
_, err := c.DatabaseV1alpha().ArangoDeployments(ns).Create(depl)
8686
require.NoError(t, err, fmt.Sprintf("Create deployment failed: %v", err))
87-
defer deferedCleanupDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace)
87+
defer deferedCleanupDeployment(c, depl.GetName(), ns)
8888

8989
// Wait for deployment to be ready
90-
deployment, err := waitUntilDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace, deploymentIsReady())
90+
deployment, err := waitUntilDeployment(c, depl.GetName(), ns, deploymentIsReady())
9191
require.NoError(t, err, fmt.Sprintf("Deployment not running in time: %v", err))
9292

9393
// Create a database client
9494
ctx := context.Background()
95-
DBClient := mustNewArangodDatabaseClient(ctx, k8sClient, deployment, t)
96-
require.NoError(t, waitUntilArangoDeploymentHealthy(deployment, DBClient, k8sClient, ""), fmt.Sprintf("Deployment not healthy in time: %v", err))
95+
DBClient := mustNewArangodDatabaseClient(ctx, kubecli, deployment, t)
96+
require.NoError(t, waitUntilArangoDeploymentHealthy(deployment, DBClient, kubecli, ""), fmt.Sprintf("Deployment not healthy in time: %v", err))
9797

9898
// Cleanup
99-
removeDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace)
99+
removeDeployment(c, depl.GetName(), ns)
100100

101101
return nil
102102
}
@@ -105,47 +105,47 @@ func deploymentSubTest(t *testing.T, mode api.DeploymentMode, engine api.Storage
105105
func TestMultiDeployment(t *testing.T) {
106106
longOrSkip(t)
107107

108-
k8sNameSpace := getNamespace(t)
109-
k8sClient := mustNewKubeClient(t)
110-
deploymentClient := kubeArangoClient.MustNewInCluster()
108+
ns := getNamespace(t)
109+
kubecli := mustNewKubeClient(t)
110+
c := kubeArangoClient.MustNewInCluster()
111111

112112
// Prepare deployment configurations
113-
deploymentTemplate1 := newDeployment("test-multidep1-1-" + uniuri.NewLen(4))
114-
deploymentTemplate1.Spec.Mode = api.NewMode(api.DeploymentModeCluster)
115-
deploymentTemplate1.Spec.StorageEngine = api.NewStorageEngine(api.StorageEngineRocksDB)
116-
deploymentTemplate1.Spec.TLS = api.TLSSpec{} // should auto-generate cert
117-
deploymentTemplate1.Spec.SetDefaults(deploymentTemplate1.GetName()) // this must be last
118-
119-
deploymentTemplate2 := newDeployment("test-multidep1-2-" + uniuri.NewLen(4))
120-
deploymentTemplate2.Spec.Mode = api.NewMode(api.DeploymentModeSingle)
121-
deploymentTemplate2.Spec.StorageEngine = api.NewStorageEngine(api.StorageEngineMMFiles)
122-
deploymentTemplate2.Spec.TLS = api.TLSSpec{} // should auto-generate cert
123-
deploymentTemplate2.Spec.SetDefaults(deploymentTemplate2.GetName()) // this must be last
113+
depl1 := newDeployment("test-multidep-1-" + uniuri.NewLen(4))
114+
depl1.Spec.Mode = api.NewMode(api.DeploymentModeCluster)
115+
depl1.Spec.StorageEngine = api.NewStorageEngine(api.StorageEngineRocksDB)
116+
depl1.Spec.TLS = api.TLSSpec{} // should auto-generate cert
117+
depl1.Spec.SetDefaults(depl1.GetName()) // this must be last
118+
119+
depl2 := newDeployment("test-multidep-2-" + uniuri.NewLen(4))
120+
depl2.Spec.Mode = api.NewMode(api.DeploymentModeSingle)
121+
depl2.Spec.StorageEngine = api.NewStorageEngine(api.StorageEngineMMFiles)
122+
depl2.Spec.TLS = api.TLSSpec{} // should auto-generate cert
123+
depl2.Spec.SetDefaults(depl2.GetName()) // this must be last
124124

125125
// Create deployments
126-
_, err := deploymentClient.DatabaseV1alpha().ArangoDeployments(k8sNameSpace).Create(deploymentTemplate1)
126+
_, err := c.DatabaseV1alpha().ArangoDeployments(ns).Create(depl1)
127127
require.NoError(t, err, fmt.Sprintf("Deployment creation failed: %v", err))
128-
defer deferedCleanupDeployment(deploymentClient, deploymentTemplate1.GetName(), k8sNameSpace)
128+
defer deferedCleanupDeployment(c, depl1.GetName(), ns)
129129

130-
_, err = deploymentClient.DatabaseV1alpha().ArangoDeployments(k8sNameSpace).Create(deploymentTemplate2)
130+
_, err = c.DatabaseV1alpha().ArangoDeployments(ns).Create(depl2)
131131
require.NoError(t, err, fmt.Sprintf("Deployment creation failed: %v", err))
132-
defer deferedCleanupDeployment(deploymentClient, deploymentTemplate2.GetName(), k8sNameSpace)
132+
defer deferedCleanupDeployment(c, depl2.GetName(), ns)
133133

134134
// Wait for deployments to be ready
135-
deployment1, err := waitUntilDeployment(deploymentClient, deploymentTemplate1.GetName(), k8sNameSpace, deploymentIsReady())
135+
deployment1, err := waitUntilDeployment(c, depl1.GetName(), ns, deploymentIsReady())
136136
require.NoError(t, err, fmt.Sprintf("Deployment not running in time: %v", err))
137137

138-
deployment2, err := waitUntilDeployment(deploymentClient, deploymentTemplate2.GetName(), k8sNameSpace, deploymentIsReady())
138+
deployment2, err := waitUntilDeployment(c, depl2.GetName(), ns, deploymentIsReady())
139139
require.NoError(t, err, fmt.Sprintf("Deployment not running in time: %v", err))
140140

141141
require.True(t, deployment1 != nil && deployment2 != nil, "deployment is nil")
142142

143143
// Create a database clients
144144
ctx := context.Background()
145-
DBClient1 := mustNewArangodDatabaseClient(ctx, k8sClient, deployment1, t)
146-
require.NoError(t, waitUntilArangoDeploymentHealthy(deployment1, DBClient1, k8sClient, ""), fmt.Sprintf("Deployment not healthy in time: %v", err))
147-
DBClient2 := mustNewArangodDatabaseClient(ctx, k8sClient, deployment2, t)
148-
require.NoError(t, waitUntilArangoDeploymentHealthy(deployment1, DBClient1, k8sClient, ""), fmt.Sprintf("Deployment not healthy in time: %v", err))
145+
DBClient1 := mustNewArangodDatabaseClient(ctx, kubecli, deployment1, t)
146+
require.NoError(t, waitUntilArangoDeploymentHealthy(deployment1, DBClient1, kubecli, ""), fmt.Sprintf("Deployment not healthy in time: %v", err))
147+
DBClient2 := mustNewArangodDatabaseClient(ctx, kubecli, deployment2, t)
148+
require.NoError(t, waitUntilArangoDeploymentHealthy(deployment1, DBClient1, kubecli, ""), fmt.Sprintf("Deployment not healthy in time: %v", err))
149149

150150
// Test if we are able to create a collections in both deployments.
151151
db1, err := DBClient1.Database(ctx, "_system")
@@ -171,8 +171,8 @@ func TestMultiDeployment(t *testing.T) {
171171
assert.False(t, containsCollection(collections2, "col1"), "collection must not be in this deployment")
172172

173173
// Cleanup
174-
removeDeployment(deploymentClient, deploymentTemplate1.GetName(), k8sNameSpace)
175-
removeDeployment(deploymentClient, deploymentTemplate2.GetName(), k8sNameSpace)
174+
removeDeployment(c, depl1.GetName(), ns)
175+
removeDeployment(c, depl2.GetName(), ns)
176176

177177
}
178178

tests/environments_test.go

+20-20
Original file line numberDiff line numberDiff line change
@@ -36,50 +36,50 @@ import (
3636
"github.com/arangodb/kube-arangodb/pkg/util"
3737
)
3838

39-
// Test if deployment comes up in production environment.
39+
// TestEnvironmentProduction tests if deployment comes up in production environment.
4040
// LONG: The test ensures that the deployment fails if there are
4141
// less nodes available than servers required.
42-
func TestProduction(t *testing.T) {
42+
func TestEnvironmentProduction(t *testing.T) {
4343
longOrSkip(t)
4444

4545
mode := api.DeploymentModeCluster
4646
engine := api.StorageEngineRocksDB
4747

48-
k8sNameSpace := getNamespace(t)
49-
k8sClient := mustNewKubeClient(t)
48+
ns := getNamespace(t)
49+
kubecli := mustNewKubeClient(t)
5050

51-
nodeList, err := k8sClient.CoreV1().Nodes().List(metav1.ListOptions{})
51+
nodeList, err := kubecli.CoreV1().Nodes().List(metav1.ListOptions{})
5252
if err != nil {
5353
t.Fatalf("Unable to receive node list: %v", err)
5454
}
5555
numNodes := len(nodeList.Items)
5656

57-
deploymentClient := kubeArangoClient.MustNewInCluster()
58-
deploymentTemplate := newDeployment(strings.Replace(fmt.Sprintf("tprod-%s-%s-%s", mode[:2], engine[:2], uniuri.NewLen(4)), ".", "", -1))
59-
deploymentTemplate.Spec.Mode = api.NewMode(mode)
60-
deploymentTemplate.Spec.StorageEngine = api.NewStorageEngine(engine)
61-
deploymentTemplate.Spec.TLS = api.TLSSpec{}
62-
deploymentTemplate.Spec.Environment = api.NewEnvironment(api.EnvironmentProduction)
63-
deploymentTemplate.Spec.Image = util.NewString("arangodb/arangodb:3.3.4")
64-
deploymentTemplate.Spec.DBServers.Count = util.NewInt(numNodes + 1)
65-
deploymentTemplate.Spec.SetDefaults(deploymentTemplate.GetName()) // this must be last
66-
assert.NoError(t, deploymentTemplate.Spec.Validate())
57+
c := kubeArangoClient.MustNewInCluster()
58+
depl := newDeployment(strings.Replace(fmt.Sprintf("tprod-%s-%s-%s", mode[:2], engine[:2], uniuri.NewLen(4)), ".", "", -1))
59+
depl.Spec.Mode = api.NewMode(mode)
60+
depl.Spec.StorageEngine = api.NewStorageEngine(engine)
61+
depl.Spec.TLS = api.TLSSpec{}
62+
depl.Spec.Environment = api.NewEnvironment(api.EnvironmentProduction)
63+
depl.Spec.Image = util.NewString("arangodb/arangodb:3.3.4")
64+
depl.Spec.DBServers.Count = util.NewInt(numNodes + 1)
65+
depl.Spec.SetDefaults(depl.GetName()) // this must be last
66+
assert.NoError(t, depl.Spec.Validate())
6767

68-
dbserverCount := deploymentTemplate.Spec.DBServers.GetCount()
68+
dbserverCount := depl.Spec.DBServers.GetCount()
6969
if dbserverCount < 3 {
7070
t.Skipf("Not enough DBServers to run this test: server count %d", dbserverCount)
7171
}
7272

7373
// Create deployment
74-
if _, err := deploymentClient.DatabaseV1alpha().ArangoDeployments(k8sNameSpace).Create(deploymentTemplate); err != nil {
74+
if _, err := c.DatabaseV1alpha().ArangoDeployments(ns).Create(depl); err != nil {
7575
// REVIEW - should the test already fail here
7676
t.Fatalf("Create deployment failed: %v", err)
7777
}
78-
defer deferedCleanupDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace)
78+
defer deferedCleanupDeployment(c, depl.GetName(), ns)
7979

80-
_, err = waitUntilDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace, deploymentIsReady())
80+
_, err = waitUntilDeployment(c, depl.GetName(), ns, deploymentIsReady())
8181
assert.Error(t, err, fmt.Sprintf("Deployment is up and running when it should not! There are not enough nodes(%d) for all DBServers(%d) in production modes.", numNodes, dbserverCount))
8282

8383
// Cleanup
84-
removeDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace)
84+
removeDeployment(c, depl.GetName(), ns)
8585
}

tests/upgrade_test.go

+18-18
Original file line numberDiff line numberDiff line change
@@ -83,58 +83,58 @@ func upgradeSubTest(t *testing.T, mode api.DeploymentMode, engine api.StorageEng
8383
// check environment
8484
longOrSkip(t)
8585

86-
k8sNameSpace := getNamespace(t)
87-
k8sClient := mustNewKubeClient(t)
88-
deploymentClient := kubeArangoClient.MustNewInCluster()
86+
ns := getNamespace(t)
87+
kubecli := mustNewKubeClient(t)
88+
c := kubeArangoClient.MustNewInCluster()
8989

90-
deploymentTemplate := newDeployment(strings.Replace(fmt.Sprintf("tu-%s-%s-%st%s-%s", mode[:2], engine[:2], fromVersion, toVersion, uniuri.NewLen(4)), ".", "", -1))
91-
deploymentTemplate.Spec.Mode = api.NewMode(mode)
92-
deploymentTemplate.Spec.StorageEngine = api.NewStorageEngine(engine)
93-
deploymentTemplate.Spec.TLS = api.TLSSpec{} // should auto-generate cert
94-
deploymentTemplate.Spec.Image = util.NewString("arangodb/arangodb:" + fromVersion)
95-
deploymentTemplate.Spec.SetDefaults(deploymentTemplate.GetName()) // this must be last
90+
depl := newDeployment(strings.Replace(fmt.Sprintf("tu-%s-%s-%st%s-%s", mode[:2], engine[:2], fromVersion, toVersion, uniuri.NewLen(4)), ".", "", -1))
91+
depl.Spec.Mode = api.NewMode(mode)
92+
depl.Spec.StorageEngine = api.NewStorageEngine(engine)
93+
depl.Spec.TLS = api.TLSSpec{} // should auto-generate cert
94+
depl.Spec.Image = util.NewString("arangodb/arangodb:" + fromVersion)
95+
depl.Spec.SetDefaults(depl.GetName()) // this must be last
9696

9797
// Create deployment
98-
deployment, err := deploymentClient.DatabaseV1alpha().ArangoDeployments(k8sNameSpace).Create(deploymentTemplate)
98+
deployment, err := c.DatabaseV1alpha().ArangoDeployments(ns).Create(depl)
9999
if err != nil {
100100
t.Fatalf("Create deployment failed: %v", err)
101101
}
102-
defer deferedCleanupDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace)
102+
defer deferedCleanupDeployment(c, depl.GetName(), ns)
103103

104104
// Wait for deployment to be ready
105-
deployment, err = waitUntilDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace, deploymentIsReady())
105+
deployment, err = waitUntilDeployment(c, depl.GetName(), ns, deploymentIsReady())
106106
if err != nil {
107107
t.Fatalf("Deployment not running in time: %v", err)
108108
}
109109

110110
// Create a database client
111111
ctx := context.Background()
112-
DBClient := mustNewArangodDatabaseClient(ctx, k8sClient, deployment, t)
112+
DBClient := mustNewArangodDatabaseClient(ctx, kubecli, deployment, t)
113113

114-
if err := waitUntilArangoDeploymentHealthy(deployment, DBClient, k8sClient, ""); err != nil {
114+
if err := waitUntilArangoDeploymentHealthy(deployment, DBClient, kubecli, ""); err != nil {
115115
t.Fatalf("Deployment not healthy in time: %v", err)
116116
}
117117

118118
// Try to change image version
119-
deployment, err = updateDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace,
119+
deployment, err = updateDeployment(c, depl.GetName(), ns,
120120
func(spec *api.DeploymentSpec) {
121121
spec.Image = util.NewString("arangodb/arangodb:" + toVersion)
122122
})
123123
if err != nil {
124124
t.Fatalf("Failed to upgrade the Image from version : " + fromVersion + " to version: " + toVersion)
125125
}
126126

127-
deployment, err = waitUntilDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace, deploymentIsReady())
127+
deployment, err = waitUntilDeployment(c, depl.GetName(), ns, deploymentIsReady())
128128
if err != nil {
129129
t.Fatalf("Deployment not running in time: %v", err)
130130
}
131131

132-
if err := waitUntilArangoDeploymentHealthy(deployment, DBClient, k8sClient, toVersion); err != nil {
132+
if err := waitUntilArangoDeploymentHealthy(deployment, DBClient, kubecli, toVersion); err != nil {
133133
t.Fatalf("Deployment not healthy in time: %v", err)
134134
}
135135

136136
// Cleanup
137-
removeDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace)
137+
removeDeployment(c, depl.GetName(), ns)
138138

139139
return nil
140140
}

0 commit comments

Comments
 (0)