-
Notifications
You must be signed in to change notification settings - Fork 73
Tests/multi deployment #89
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
Changes from 3 commits
f94a65b
d23ad1e
71e7e61
73a3ff9
2745ef9
9225509
d9f0570
529b997
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,6 @@ package v1alpha | |
import ( | ||
"testing" | ||
|
||
//"github.com/pkg/errors" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,9 +23,13 @@ package tests | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/dchest/uniuri" | ||
"github.com/stretchr/testify/assert" | ||
|
||
driver "github.com/arangodb/go-driver" | ||
|
||
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha" | ||
kubeArangoClient "github.com/arangodb/kube-arangodb/pkg/client" | ||
|
@@ -77,27 +81,97 @@ func deploymentSubTest(t *testing.T, mode api.DeploymentMode, engine api.Storage | |
deploymentTemplate.Spec.SetDefaults(deploymentTemplate.GetName()) // this must be last | ||
|
||
// Create deployment | ||
deployment, err := deploymentClient.DatabaseV1alpha().ArangoDeployments(k8sNameSpace).Create(deploymentTemplate) | ||
if err != nil { | ||
t.Fatalf("Create deployment failed: %v", err) | ||
} | ||
_, err := deploymentClient.DatabaseV1alpha().ArangoDeployments(k8sNameSpace).Create(deploymentTemplate) | ||
assert.NoError(t, err, fmt.Sprintf("Create deployment failed: %v", err)) | ||
|
||
// Wait for deployment to be ready | ||
deployment, err = waitUntilDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace, deploymentIsReady()) | ||
if err != nil { | ||
t.Fatalf("Deployment not running in time: %v", err) | ||
} | ||
deployment, err := waitUntilDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace, deploymentIsReady()) | ||
assert.NoError(t, err, fmt.Sprintf("Deployment not running in time: %v", err)) | ||
|
||
// Create a database client | ||
ctx := context.Background() | ||
DBClient := mustNewArangodDatabaseClient(ctx, k8sClient, deployment, t) | ||
|
||
if err := waitUntilArangoDeploymentHealthy(deployment, DBClient, k8sClient, ""); err != nil { | ||
t.Fatalf("Deployment not healthy in time: %v", err) | ||
} | ||
assert.NoError(t, waitUntilArangoDeploymentHealthy(deployment, DBClient, k8sClient, ""), fmt.Sprintf("Deployment not healthy in time: %v", err)) | ||
|
||
// Cleanup | ||
removeDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace) | ||
|
||
return nil | ||
} | ||
|
||
// test setup containing multiple deployments | ||
func TestMultiDeployment1(t *testing.T) { | ||
longOrSkip(t) | ||
|
||
k8sNameSpace := getNamespace(t) | ||
k8sClient := mustNewKubeClient(t) | ||
deploymentClient := kubeArangoClient.MustNewInCluster() | ||
|
||
// Prepare deployment config | ||
deploymentTemplate1 := newDeployment("test-multidep1-1-" + uniuri.NewLen(4)) | ||
deploymentTemplate1.Spec.Mode = api.NewMode(api.DeploymentModeCluster) | ||
deploymentTemplate1.Spec.StorageEngine = api.NewStorageEngine(api.StorageEngineRocksDB) | ||
deploymentTemplate1.Spec.TLS = api.TLSSpec{} // should auto-generate cert | ||
deploymentTemplate1.Spec.SetDefaults(deploymentTemplate1.GetName()) // this must be last | ||
|
||
deploymentTemplate2 := newDeployment("test-multidep1-2-" + uniuri.NewLen(4)) | ||
deploymentTemplate2.Spec.Mode = api.NewMode(api.DeploymentModeSingle) | ||
deploymentTemplate2.Spec.StorageEngine = api.NewStorageEngine(api.StorageEngineMMFiles) | ||
deploymentTemplate2.Spec.TLS = api.TLSSpec{} // should auto-generate cert | ||
deploymentTemplate2.Spec.SetDefaults(deploymentTemplate2.GetName()) // this must be last | ||
|
||
// Create deployment | ||
_, err := deploymentClient.DatabaseV1alpha().ArangoDeployments(k8sNameSpace).Create(deploymentTemplate1) | ||
assert.NoError(t, err, fmt.Sprintf("Deployment creation failed: %v", err)) | ||
|
||
_, err = deploymentClient.DatabaseV1alpha().ArangoDeployments(k8sNameSpace).Create(deploymentTemplate2) | ||
assert.NoError(t, err, fmt.Sprintf("Deployment creation failed: %v", err)) | ||
|
||
// Wait for deployment to be ready | ||
deployment1, err := waitUntilDeployment(deploymentClient, deploymentTemplate1.GetName(), k8sNameSpace, deploymentIsReady()) | ||
assert.NoError(t, err, fmt.Sprintf("Deployment not running in time: %v", err)) | ||
|
||
deployment2, err := waitUntilDeployment(deploymentClient, deploymentTemplate2.GetName(), k8sNameSpace, deploymentIsReady()) | ||
assert.NoError(t, err, fmt.Sprintf("Deployment not running in time: %v", err)) | ||
|
||
// Create a database client | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. client -> clients |
||
ctx := context.Background() | ||
DBClient1 := mustNewArangodDatabaseClient(ctx, k8sClient, deployment1, t) | ||
assert.NoError(t, waitUntilArangoDeploymentHealthy(deployment1, DBClient1, k8sClient, ""), fmt.Sprintf("Deployment not healthy in time: %v", err)) | ||
DBClient2 := mustNewArangodDatabaseClient(ctx, k8sClient, deployment2, t) | ||
assert.NoError(t, waitUntilArangoDeploymentHealthy(deployment1, DBClient1, k8sClient, ""), fmt.Sprintf("Deployment not healthy in time: %v", err)) | ||
|
||
db1, err := DBClient1.Database(ctx, "_system") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a comment here to explain what the intent of line 144 - 152 is |
||
assert.NoError(t, err, "failed to get database") | ||
_, err = db1.CreateCollection(ctx, "col1", nil) | ||
assert.NoError(t, err, "failed to create collection") | ||
|
||
db2, err := DBClient2.Database(ctx, "_system") | ||
assert.NoError(t, err, "failed to get database") | ||
_, err = db2.CreateCollection(ctx, "col2", nil) | ||
assert.NoError(t, err, "failed to create collection") | ||
|
||
collections1, err := db1.Collections(ctx) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where the "real test" starts, please add a comment explaining what is being checked |
||
assert.NoError(t, err, "failed to get collections") | ||
collections2, err := db2.Collections(ctx) | ||
assert.NoError(t, err, "failed to get collections") | ||
|
||
assert.True(t, containsCollection(collections1, "col1"), "collection missing") | ||
assert.True(t, containsCollection(collections2, "col2"), "collection missing") | ||
assert.False(t, containsCollection(collections1, "col2"), "collection must not be in this deployment") | ||
assert.False(t, containsCollection(collections2, "col1"), "collection must not be in this deployment") | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To make sure that we can talk to individual deployments, I'll like to see an additional test here.
|
||
// Cleanup | ||
removeDeployment(deploymentClient, deploymentTemplate1.GetName(), k8sNameSpace) | ||
removeDeployment(deploymentClient, deploymentTemplate2.GetName(), k8sNameSpace) | ||
|
||
} | ||
|
||
func containsCollection(colls []driver.Collection, name string) bool { | ||
for _, col := range colls { | ||
if name == col.Name() { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deployment -> deployments