Skip to content

Commit 8118132

Browse files
committed
begin to add tests for storage/v1alpha
1 parent 262e57d commit 8118132

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-0
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ run-unit-tests: $(GOBUILDDIR) $(SOURCES)
171171
golang:$(GOVERSION) \
172172
go test $(TESTVERBOSEOPTIONS) \
173173
$(REPOPATH)/pkg/apis/arangodb/v1alpha \
174+
$(REPOPATH)/pkg/apis/storage/v1alpha \
174175
$(REPOPATH)/pkg/deployment \
175176
$(REPOPATH)/pkg/util/k8sutil
176177

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
func Test_LocalStorageSpec_Creation(t *testing.T) {
33+
var (
34+
class StorageClassSpec
35+
local LocalStorageSpec
36+
err error
37+
)
38+
39+
class = StorageClassSpec{"SpecName", true}
40+
local = LocalStorageSpec{StorageClass: class, LocalPath: []string{""}}
41+
err = local.Validate()
42+
assert.Equal(t, errors.Cause(class.Validate()), errors.Cause(err))
43+
44+
class = StorageClassSpec{"spec-name", true}
45+
local = LocalStorageSpec{StorageClass: class, LocalPath: []string{""}} //is this allowed - should the paths be checked?
46+
err = local.Validate()
47+
assert.Equal(t, nil, errors.Cause(err))
48+
49+
class = StorageClassSpec{"spec-name", true}
50+
local = LocalStorageSpec{StorageClass: class, LocalPath: []string{}}
51+
err = local.Validate()
52+
assert.Equal(t, ValidationError, errors.Cause(err)) //path empty
53+
}
54+
55+
func Test_LocalStorageSpec_Reset(t *testing.T) {
56+
class := StorageClassSpec{"spec-name", true}
57+
source := LocalStorageSpec{StorageClass: class, LocalPath: []string{"/a/path", "/another/path"}}
58+
target := LocalStorageSpec{}
59+
resetImmutableFieldsResult := source.ResetImmutableFields(&target)
60+
expected := []string{"storageClass.name", "localPath"}
61+
assert.Equal(t, expected, resetImmutableFieldsResult)
62+
assert.Equal(t, source.LocalPath, target.LocalPath)
63+
assert.Equal(t, source.StorageClass.Name, target.StorageClass.Name)
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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/stretchr/testify/assert"
29+
)
30+
31+
func Test_ArangoLocalStorage_Creation(t *testing.T) {
32+
assert.True(t, true)
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
func Test_StorageClassSpec_Creation(t *testing.T) {
33+
storageClassSpec := StorageClassSpec{}
34+
assert.True(t, nil != storageClassSpec.Validate())
35+
36+
storageClassSpec = StorageClassSpec{Name: "TheSpecName", IsDefault: true} // no upper-case allowed
37+
assert.True(t, nil != storageClassSpec.Validate())
38+
39+
storageClassSpec = StorageClassSpec{"the-spec-name", true}
40+
assert.Equal(t, nil, storageClassSpec.Validate())
41+
42+
storageClassSpec = StorageClassSpec{} // this is invalid because it was not created with a proper name
43+
storageClassSpec.SetDefaults("foo") // here the Name is fixed
44+
assert.Equal(t, nil, storageClassSpec.Validate())
45+
}
46+
47+
func Test_StorageClassSpec_ResetImmutableFileds(t *testing.T) {
48+
specSource := StorageClassSpec{"source", true}
49+
specTarget := StorageClassSpec{"target", true}
50+
51+
assert.Equal(t, "target", specTarget.Name)
52+
rv := specSource.ResetImmutableFields("fieldPrefix-", &specTarget)
53+
assert.Equal(t, "fieldPrefix-name", strings.Join(rv[:], ", "))
54+
assert.Equal(t, "source", specTarget.Name)
55+
}

0 commit comments

Comments
 (0)