Skip to content

Commit d2f685f

Browse files
authored
Merge pull request #36 from arangodb/tests/apis-storage-v1alpha
begin to add tests for `apis/storage/v1alpha`
2 parents 5cf25ee + 486163b commit d2f685f

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ run-unit-tests: $(GOBUILDDIR) $(SOURCES)
217217
golang:$(GOVERSION) \
218218
go test $(TESTVERBOSEOPTIONS) \
219219
$(REPOPATH)/pkg/apis/deployment/v1alpha \
220+
$(REPOPATH)/pkg/apis/storage/v1alpha \
220221
$(REPOPATH)/pkg/deployment/reconcile \
221222
$(REPOPATH)/pkg/deployment/resources \
222223
$(REPOPATH)/pkg/util/k8sutil \
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2018 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
// Author Jan Christoph Uhde
21+
//
22+
23+
package v1alpha
24+
25+
import (
26+
"testing"
27+
28+
//"github.com/pkg/errors"
29+
"github.com/stretchr/testify/assert"
30+
)
31+
32+
// Test creation of local storage spec
33+
func TestLocalStorageSpecCreation(t *testing.T) {
34+
35+
class := StorageClassSpec{"SpecName", true}
36+
local := LocalStorageSpec{StorageClass: class, LocalPath: []string{""}}
37+
assert.Error(t, local.Validate())
38+
39+
class = StorageClassSpec{"spec-name", true}
40+
local = LocalStorageSpec{StorageClass: class, LocalPath: []string{""}}
41+
assert.Error(t, local.Validate(), "should fail as the empty sting is not a valid path")
42+
43+
class = StorageClassSpec{"spec-name", true}
44+
local = LocalStorageSpec{StorageClass: class, LocalPath: []string{}}
45+
assert.True(t, IsValidation(local.Validate()))
46+
}
47+
48+
// Test reset of local storage spec
49+
func TestLocalStorageSpecReset(t *testing.T) {
50+
class := StorageClassSpec{"spec-name", true}
51+
source := LocalStorageSpec{StorageClass: class, LocalPath: []string{"/a/path", "/another/path"}}
52+
target := LocalStorageSpec{}
53+
resetImmutableFieldsResult := source.ResetImmutableFields(&target)
54+
expected := []string{"storageClass.name", "localPath"}
55+
assert.Equal(t, expected, resetImmutableFieldsResult)
56+
assert.Equal(t, source.LocalPath, target.LocalPath)
57+
assert.Equal(t, source.StorageClass.Name, target.StorageClass.Name)
58+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2018 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
// Author Jan Christoph Uhde
21+
//
22+
23+
package v1alpha
24+
25+
import (
26+
"strings"
27+
"testing"
28+
29+
"github.com/stretchr/testify/assert"
30+
)
31+
32+
// test creation of storage class spec
33+
func TestStorageClassSpecCreation(t *testing.T) {
34+
storageClassSpec := StorageClassSpec{}
35+
assert.Error(t, storageClassSpec.Validate(), "empty name name is not allowed")
36+
37+
storageClassSpec = StorageClassSpec{Name: "TheSpecName", IsDefault: true}
38+
assert.Error(t, storageClassSpec.Validate(), "upper case letters are not allowed in resources")
39+
40+
storageClassSpec = StorageClassSpec{"the-spec-name", true}
41+
assert.NoError(t, storageClassSpec.Validate())
42+
43+
storageClassSpec = StorageClassSpec{} // no proper name -> invalid
44+
storageClassSpec.SetDefaults("foo") // name is fixed -> vaild
45+
assert.NoError(t, storageClassSpec.Validate())
46+
}
47+
48+
// test reset of storage class spec
49+
func TestStorageClassSpecResetImmutableFileds(t *testing.T) {
50+
specSource := StorageClassSpec{"source", true}
51+
specTarget := StorageClassSpec{"target", true}
52+
53+
assert.Equal(t, "target", specTarget.Name)
54+
rv := specSource.ResetImmutableFields("fieldPrefix-", &specTarget)
55+
assert.Equal(t, "fieldPrefix-name", strings.Join(rv, ", "))
56+
assert.Equal(t, "source", specTarget.Name)
57+
}

0 commit comments

Comments
 (0)