From 0b8072fc9c44a40aceddecbc41704ef77db05902 Mon Sep 17 00:00:00 2001 From: Ewout Prangsma Date: Thu, 1 Mar 2018 11:27:12 +0100 Subject: [PATCH 1/3] Adding simple tests for all deployment modes --- tests/{single_test.go => simple_test.go} | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) rename tests/{single_test.go => simple_test.go} (58%) diff --git a/tests/single_test.go b/tests/simple_test.go similarity index 58% rename from tests/single_test.go rename to tests/simple_test.go index b9fa7363d..d24426444 100644 --- a/tests/single_test.go +++ b/tests/simple_test.go @@ -1,6 +1,7 @@ package tests import ( + "context" "testing" "github.com/dchest/uniuri" @@ -13,6 +14,7 @@ import ( // with default settings. func TestSimpleSingle(t *testing.T) { c := client.MustNewInCluster() + kubecli := mustNewKubeClient(t) ns := getNamespace(t) // Prepare deployment config @@ -24,12 +26,21 @@ func TestSimpleSingle(t *testing.T) { if err != nil { t.Fatalf("Create deployment failed: %v", err) } + // Prepare cleanup + defer removeDeployment(c, depl.GetName(), ns) // Wait for deployment to be ready - if _, err := waitUntilDeployment(c, depl.GetName(), ns, deploymentHasState(api.DeploymentStateRunning)); err != nil { + apiObject, err := waitUntilDeployment(c, depl.GetName(), ns, deploymentHasState(api.DeploymentStateRunning)) + if err != nil { t.Errorf("Deployment not running in time: %v", err) } - // Cleanup - removeDeployment(c, depl.GetName(), ns) + // Create a database client + ctx := context.Background() + client := mustNewArangodDatabaseClient(ctx, kubecli, apiObject, t) + + // Wait for single server available + if err := waitUntilVersionUp(client); err != nil { + t.Fatalf("Single server not running returning version in time: %v", err) + } } From 8b42d38677646cdfd6877abe078efcc26d4c877d Mon Sep 17 00:00:00 2001 From: Ewout Prangsma Date: Thu, 1 Mar 2018 11:43:25 +0100 Subject: [PATCH 2/3] Added tests for resilientsingle & cluster mode --- tests/simple_test.go | 92 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/tests/simple_test.go b/tests/simple_test.go index d24426444..87b46f242 100644 --- a/tests/simple_test.go +++ b/tests/simple_test.go @@ -5,7 +5,9 @@ import ( "testing" "github.com/dchest/uniuri" + "github.com/stretchr/testify/assert" + driver "github.com/arangodb/go-driver" api "github.com/arangodb/k8s-operator/pkg/apis/arangodb/v1alpha" "github.com/arangodb/k8s-operator/pkg/client" ) @@ -18,7 +20,7 @@ func TestSimpleSingle(t *testing.T) { ns := getNamespace(t) // Prepare deployment config - depl := newDeployment("test-single-" + uniuri.NewLen(4)) + depl := newDeployment("test-sng-" + uniuri.NewLen(4)) depl.Spec.Mode = api.DeploymentModeSingle // Create deployment @@ -43,4 +45,92 @@ func TestSimpleSingle(t *testing.T) { if err := waitUntilVersionUp(client); err != nil { t.Fatalf("Single server not running returning version in time: %v", err) } + + // Check server role + assert.NoError(t, client.SynchronizeEndpoints(ctx)) + role, err := client.ServerRole(ctx) + assert.NoError(t, err) + assert.Equal(t, driver.ServerRoleSingle, role) +} + +// TestSimpleResilientSingle tests the creating of a resilientsingle server deployment +// with default settings. +func TestSimpleResilientSingle(t *testing.T) { + c := client.MustNewInCluster() + kubecli := mustNewKubeClient(t) + ns := getNamespace(t) + + // Prepare deployment config + depl := newDeployment("test-rs-" + uniuri.NewLen(4)) + depl.Spec.Mode = api.DeploymentModeResilientSingle + + // Create deployment + _, err := c.DatabaseV1alpha().ArangoDeployments(ns).Create(depl) + if err != nil { + t.Fatalf("Create deployment failed: %v", err) + } + // Prepare cleanup + defer removeDeployment(c, depl.GetName(), ns) + + // Wait for deployment to be ready + apiObject, err := waitUntilDeployment(c, depl.GetName(), ns, deploymentHasState(api.DeploymentStateRunning)) + if err != nil { + t.Errorf("Deployment not running in time: %v", err) + } + + // Create a database client + ctx := context.Background() + client := mustNewArangodDatabaseClient(ctx, kubecli, apiObject, t) + + // Wait for single server available + if err := waitUntilVersionUp(client); err != nil { + t.Fatalf("Single server not running returning version in time: %v", err) + } + + // Check server role + assert.NoError(t, client.SynchronizeEndpoints(ctx)) + role, err := client.ServerRole(ctx) + assert.NoError(t, err) + assert.Equal(t, driver.ServerRoleSingleActive, role) +} + +// TestSimpleCluster tests the creating of a cluster deployment +// with default settings. +func TestSimpleCluster(t *testing.T) { + c := client.MustNewInCluster() + kubecli := mustNewKubeClient(t) + ns := getNamespace(t) + + // Prepare deployment config + depl := newDeployment("test-cls-" + uniuri.NewLen(4)) + depl.Spec.Mode = api.DeploymentModeCluster + + // Create deployment + _, err := c.DatabaseV1alpha().ArangoDeployments(ns).Create(depl) + if err != nil { + t.Fatalf("Create deployment failed: %v", err) + } + // Prepare cleanup + defer removeDeployment(c, depl.GetName(), ns) + + // Wait for deployment to be ready + apiObject, err := waitUntilDeployment(c, depl.GetName(), ns, deploymentHasState(api.DeploymentStateRunning)) + if err != nil { + t.Errorf("Deployment not running in time: %v", err) + } + + // Create a database client + ctx := context.Background() + client := mustNewArangodDatabaseClient(ctx, kubecli, apiObject, t) + + // Wait for single server available + if err := waitUntilVersionUp(client); err != nil { + t.Fatalf("Single server not running returning version in time: %v", err) + } + + // Check server role + assert.NoError(t, client.SynchronizeEndpoints(ctx)) + role, err := client.ServerRole(ctx) + assert.NoError(t, err) + assert.Equal(t, driver.ServerRoleCoordinator, role) } From 08e14ec391c5f1851e0d753e4fa49d333b5cb672 Mon Sep 17 00:00:00 2001 From: Ewout Prangsma Date: Thu, 1 Mar 2018 11:45:31 +0100 Subject: [PATCH 3/3] Typos --- tests/simple_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/simple_test.go b/tests/simple_test.go index 87b46f242..7feff8a7b 100644 --- a/tests/simple_test.go +++ b/tests/simple_test.go @@ -84,7 +84,7 @@ func TestSimpleResilientSingle(t *testing.T) { // Wait for single server available if err := waitUntilVersionUp(client); err != nil { - t.Fatalf("Single server not running returning version in time: %v", err) + t.Fatalf("ResilientSingle servers not running returning version in time: %v", err) } // Check server role @@ -125,7 +125,7 @@ func TestSimpleCluster(t *testing.T) { // Wait for single server available if err := waitUntilVersionUp(client); err != nil { - t.Fatalf("Single server not running returning version in time: %v", err) + t.Fatalf("Cluster not running returning version in time: %v", err) } // Check server role