Skip to content

Commit

Permalink
Merge pull request #26 from arangodb/more-simple-tests
Browse files Browse the repository at this point in the history
More simple tests
  • Loading branch information
ewoutp authored Mar 1, 2018
2 parents f8e1392 + 08e14ec commit 57e7c88
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 35 deletions.
136 changes: 136 additions & 0 deletions tests/simple_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package tests

import (
"context"
"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"
)

// TestSimpleSingle tests the creating of a single server deployment
// with default settings.
func TestSimpleSingle(t *testing.T) {
c := client.MustNewInCluster()
kubecli := mustNewKubeClient(t)
ns := getNamespace(t)

// Prepare deployment config
depl := newDeployment("test-sng-" + uniuri.NewLen(4))
depl.Spec.Mode = api.DeploymentModeSingle

// 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.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("ResilientSingle servers 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("Cluster 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)
}
35 changes: 0 additions & 35 deletions tests/single_test.go

This file was deleted.

0 comments on commit 57e7c88

Please sign in to comment.