Skip to content
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

More simple tests #26

Merged
merged 5 commits into from
Mar 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.