diff --git a/Makefile b/Makefile index 014d42039..f24305540 100644 --- a/Makefile +++ b/Makefile @@ -216,6 +216,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 \ diff --git a/pkg/apis/storage/v1alpha/local_storage_spec_test.go b/pkg/apis/storage/v1alpha/local_storage_spec_test.go new file mode 100644 index 000000000..e315f2e6f --- /dev/null +++ b/pkg/apis/storage/v1alpha/local_storage_spec_test.go @@ -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) +} diff --git a/pkg/apis/storage/v1alpha/storage_class_spec_test.go b/pkg/apis/storage/v1alpha/storage_class_spec_test.go new file mode 100644 index 000000000..8285122cf --- /dev/null +++ b/pkg/apis/storage/v1alpha/storage_class_spec_test.go @@ -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) +}