Skip to content

Commit

Permalink
Merge pull request #36 from arangodb/tests/apis-storage-v1alpha
Browse files Browse the repository at this point in the history
begin to add tests for `apis/storage/v1alpha`
  • Loading branch information
ObiWahn authored Mar 29, 2018
2 parents 5cf25ee + 486163b commit d2f685f
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ run-unit-tests: $(GOBUILDDIR) $(SOURCES)
golang:$(GOVERSION) \
go test $(TESTVERBOSEOPTIONS) \
$(REPOPATH)/pkg/apis/deployment/v1alpha \
$(REPOPATH)/pkg/apis/storage/v1alpha \
$(REPOPATH)/pkg/deployment/reconcile \
$(REPOPATH)/pkg/deployment/resources \
$(REPOPATH)/pkg/util/k8sutil \
Expand Down
58 changes: 58 additions & 0 deletions pkg/apis/storage/v1alpha/local_storage_spec_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// 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 Jan Christoph Uhde
//

package v1alpha

import (
"testing"

//"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)

// Test creation of local storage spec
func TestLocalStorageSpecCreation(t *testing.T) {

class := StorageClassSpec{"SpecName", true}
local := LocalStorageSpec{StorageClass: class, LocalPath: []string{""}}
assert.Error(t, local.Validate())

class = StorageClassSpec{"spec-name", true}
local = LocalStorageSpec{StorageClass: class, LocalPath: []string{""}}
assert.Error(t, local.Validate(), "should fail as the empty sting is not a valid path")

class = StorageClassSpec{"spec-name", true}
local = LocalStorageSpec{StorageClass: class, LocalPath: []string{}}
assert.True(t, IsValidation(local.Validate()))
}

// Test reset of local storage spec
func TestLocalStorageSpecReset(t *testing.T) {
class := StorageClassSpec{"spec-name", true}
source := LocalStorageSpec{StorageClass: class, LocalPath: []string{"/a/path", "/another/path"}}
target := LocalStorageSpec{}
resetImmutableFieldsResult := source.ResetImmutableFields(&target)
expected := []string{"storageClass.name", "localPath"}
assert.Equal(t, expected, resetImmutableFieldsResult)
assert.Equal(t, source.LocalPath, target.LocalPath)
assert.Equal(t, source.StorageClass.Name, target.StorageClass.Name)
}
57 changes: 57 additions & 0 deletions pkg/apis/storage/v1alpha/storage_class_spec_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// 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 Jan Christoph Uhde
//

package v1alpha

import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
)

// test creation of storage class spec
func TestStorageClassSpecCreation(t *testing.T) {
storageClassSpec := StorageClassSpec{}
assert.Error(t, storageClassSpec.Validate(), "empty name name is not allowed")

storageClassSpec = StorageClassSpec{Name: "TheSpecName", IsDefault: true}
assert.Error(t, storageClassSpec.Validate(), "upper case letters are not allowed in resources")

storageClassSpec = StorageClassSpec{"the-spec-name", true}
assert.NoError(t, storageClassSpec.Validate())

storageClassSpec = StorageClassSpec{} // no proper name -> invalid
storageClassSpec.SetDefaults("foo") // name is fixed -> vaild
assert.NoError(t, storageClassSpec.Validate())
}

// test reset of storage class spec
func TestStorageClassSpecResetImmutableFileds(t *testing.T) {
specSource := StorageClassSpec{"source", true}
specTarget := StorageClassSpec{"target", true}

assert.Equal(t, "target", specTarget.Name)
rv := specSource.ResetImmutableFields("fieldPrefix-", &specTarget)
assert.Equal(t, "fieldPrefix-name", strings.Join(rv, ", "))
assert.Equal(t, "source", specTarget.Name)
}

0 comments on commit d2f685f

Please sign in to comment.