-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
begin to add tests for apis/storage/v1alpha
#36
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// 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" | ||
) | ||
|
||
func Test_LocalStorageSpec_Creation(t *testing.T) { | ||
var ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Drop this and do something like |
||
class StorageClassSpec | ||
local LocalStorageSpec | ||
err error | ||
) | ||
|
||
class = StorageClassSpec{"SpecName", true} | ||
local = LocalStorageSpec{StorageClass: class, LocalPath: []string{""}} | ||
err = local.Validate() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't understand this and the next line. |
||
assert.Equal(t, errors.Cause(class.Validate()), errors.Cause(err)) | ||
|
||
class = StorageClassSpec{"spec-name", true} | ||
local = LocalStorageSpec{StorageClass: class, LocalPath: []string{""}} //is this allowed - should the paths be checked? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably indicates a bug. |
||
err = local.Validate() | ||
assert.Equal(t, nil, errors.Cause(err)) | ||
|
||
class = StorageClassSpec{"spec-name", true} | ||
local = LocalStorageSpec{StorageClass: class, LocalPath: []string{}} | ||
err = local.Validate() | ||
assert.Equal(t, ValidationError, errors.Cause(err)) //path empty | ||
} | ||
|
||
func Test_LocalStorageSpec_Reset(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) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// 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/stretchr/testify/assert" | ||
) | ||
|
||
func Test_ArangoLocalStorage_Creation(t *testing.T) { | ||
assert.True(t, true) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// 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" | ||
) | ||
|
||
func Test_StorageClassSpec_Creation(t *testing.T) { | ||
storageClassSpec := StorageClassSpec{} | ||
assert.True(t, nil != storageClassSpec.Validate()) | ||
|
||
storageClassSpec = StorageClassSpec{Name: "TheSpecName", IsDefault: true} // no upper-case allowed | ||
assert.True(t, nil != storageClassSpec.Validate()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
storageClassSpec = StorageClassSpec{"the-spec-name", true} | ||
assert.Equal(t, nil, storageClassSpec.Validate()) | ||
|
||
storageClassSpec = StorageClassSpec{} // this is invalid because it was not created with a proper name | ||
storageClassSpec.SetDefaults("foo") // here the Name is fixed | ||
assert.Equal(t, nil, storageClassSpec.Validate()) | ||
} | ||
|
||
func Test_StorageClassSpec_ResetImmutableFileds(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[:], ", ")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. go: no need for |
||
assert.Equal(t, "source", specTarget.Name) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid the use of underscore in member names.