-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from arangodb/more-simple-tests
More simple tests
- Loading branch information
Showing
2 changed files
with
136 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file was deleted.
Oops, something went wrong.