1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

DeploymentMode tests

This commit is contained in:
Ewout Prangsma 2018-02-27 13:33:50 +01:00
parent 88f7ca5722
commit 6416e7856a
No known key found for this signature in database
GPG key ID: 4DBAD380D93D0698
3 changed files with 143 additions and 48 deletions

View file

@ -0,0 +1,75 @@
//
// DISCLAIMER
//
// Copyright 2018 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// Author Ewout Prangsma
//
package v1alpha
import (
"github.com/pkg/errors"
)
// DeploymentMode specifies the type of ArangoDB deployment to create.
type DeploymentMode string
const (
// DeploymentModeSingle yields a single server
DeploymentModeSingle DeploymentMode = "single"
// DeploymentModeResilientSingle yields an agency and a resilient-single server pair
DeploymentModeResilientSingle DeploymentMode = "resilientsingle"
// DeploymentModeCluster yields an full cluster (agency, dbservers & coordinators)
DeploymentModeCluster DeploymentMode = "cluster"
)
// Validate the mode.
// Return errors when validation fails, nil on success.
func (m DeploymentMode) Validate() error {
switch m {
case DeploymentModeSingle, DeploymentModeResilientSingle, DeploymentModeCluster:
return nil
default:
return maskAny(errors.Wrapf(ValidationError, "Unknown deployment mode: '%s'", string(m)))
}
}
// HasSingleServers returns true when the given mode is "single" or "resilientsingle".
func (m DeploymentMode) HasSingleServers() bool {
return m == DeploymentModeSingle || m == DeploymentModeResilientSingle
}
// HasAgents returns true when the given mode is "resilientsingle" or "cluster".
func (m DeploymentMode) HasAgents() bool {
return m == DeploymentModeResilientSingle || m == DeploymentModeCluster
}
// HasDBServers returns true when the given mode is "cluster".
func (m DeploymentMode) HasDBServers() bool {
return m == DeploymentModeCluster
}
// HasCoordinators returns true when the given mode is "cluster".
func (m DeploymentMode) HasCoordinators() bool {
return m == DeploymentModeCluster
}
// SupportsSync returns true when the given mode supports dc2dc replication.
func (m DeploymentMode) SupportsSync() bool {
return m == DeploymentModeCluster
}

View file

@ -0,0 +1,68 @@
//
// DISCLAIMER
//
// Copyright 2018 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// Author Ewout Prangsma
//
package v1alpha
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestDeploymentModeValidate(t *testing.T) {
// Valid
assert.Nil(t, DeploymentMode("single").Validate())
assert.Nil(t, DeploymentMode("resilientsingle").Validate())
assert.Nil(t, DeploymentMode("cluster").Validate())
// Not valid
assert.Error(t, DeploymentMode("").Validate())
assert.Error(t, DeploymentMode(" cluster").Validate())
assert.Error(t, DeploymentMode("singles").Validate())
assert.Error(t, DeploymentMode("Single").Validate())
assert.Error(t, DeploymentMode("Resilientsingle").Validate())
assert.Error(t, DeploymentMode("Cluster").Validate())
}
func TestDeploymentModeHasX(t *testing.T) {
assert.True(t, DeploymentModeSingle.HasSingleServers())
assert.True(t, DeploymentModeResilientSingle.HasSingleServers())
assert.False(t, DeploymentModeCluster.HasSingleServers())
assert.False(t, DeploymentModeSingle.HasAgents())
assert.True(t, DeploymentModeResilientSingle.HasAgents())
assert.True(t, DeploymentModeCluster.HasAgents())
assert.False(t, DeploymentModeSingle.HasDBServers())
assert.False(t, DeploymentModeResilientSingle.HasDBServers())
assert.True(t, DeploymentModeCluster.HasDBServers())
assert.False(t, DeploymentModeSingle.HasCoordinators())
assert.False(t, DeploymentModeResilientSingle.HasCoordinators())
assert.True(t, DeploymentModeCluster.HasCoordinators())
}
func TestDeploymentModeSupportsSync(t *testing.T) {
assert.False(t, DeploymentModeSingle.SupportsSync())
assert.False(t, DeploymentModeResilientSingle.SupportsSync())
assert.True(t, DeploymentModeCluster.SupportsSync())
}

View file

@ -33,54 +33,6 @@ const (
defaultImage = "arangodb/arangodb:latest"
)
// DeploymentMode specifies the type of ArangoDB deployment to create.
type DeploymentMode string
const (
// DeploymentModeSingle yields a single server
DeploymentModeSingle DeploymentMode = "single"
// DeploymentModeResilientSingle yields an agency and a resilient-single server pair
DeploymentModeResilientSingle DeploymentMode = "resilientsingle"
// DeploymentModeCluster yields an full cluster (agency, dbservers & coordinators)
DeploymentModeCluster DeploymentMode = "cluster"
)
// Validate the mode.
// Return errors when validation fails, nil on success.
func (m DeploymentMode) Validate() error {
switch m {
case DeploymentModeSingle, DeploymentModeResilientSingle, DeploymentModeCluster:
return nil
default:
return maskAny(errors.Wrapf(ValidationError, "Unknown deployment mode: '%s'", string(m)))
}
}
// HasSingleServers returns true when the given mode is "single" or "resilientsingle".
func (m DeploymentMode) HasSingleServers() bool {
return m == DeploymentModeSingle || m == DeploymentModeResilientSingle
}
// HasAgents returns true when the given mode is "resilientsingle" or "cluster".
func (m DeploymentMode) HasAgents() bool {
return m == DeploymentModeResilientSingle || m == DeploymentModeCluster
}
// HasDBServers returns true when the given mode is "cluster".
func (m DeploymentMode) HasDBServers() bool {
return m == DeploymentModeCluster
}
// HasCoordinators returns true when the given mode is "cluster".
func (m DeploymentMode) HasCoordinators() bool {
return m == DeploymentModeCluster
}
// SupportsSync returns true when the given mode supports dc2dc replication.
func (m DeploymentMode) SupportsSync() bool {
return m == DeploymentModeCluster
}
// Environment in which to run the cluster
type Environment string