Skip to content
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

add some tests for util/k8sutil/erros.go #32

Merged
merged 5 commits into from
Mar 9, 2018
Merged

add some tests for util/k8sutil/erros.go #32

merged 5 commits into from
Mar 9, 2018

Conversation

ObiWahn
Copy link
Contributor

@ObiWahn ObiWahn commented Mar 6, 2018

first ridiculous commits

"k8s.io/apimachinery/pkg/util/validation/field"
)

var conflict = apierrors.NewConflict(schema.GroupResource{"fist", "second"}, "something", os.ErrInvalid)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Group variable in single var block:

var( 
   conflict = ...
  other = ...
)

Copy link
Contributor

@kvahed kvahed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine

"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/validation/field"
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add tests for masked errors. (assert.X(t, maskAny(...)))

@@ -0,0 +1,64 @@
package k8sutil_test
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this package name ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where should I state the reason (cyclic import) that led to package creation?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Package name should be test since the folder is named that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a doc.go with only a header, package test followed by a comment describing about the cycle import.


func TestPodGoneEvent(t *testing.T) {
event := k8sutil.NewPodGoneEvent("name", "role", &apiObjectForTest)
assert.Equal(t, event.Reason, "Pod Of Role Gone")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

role is uppercase in reason but not in message

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of strings.Title seems to be a bit inconsistent.

In the following snipped it is used in the middle of the string in one case and in the other case it is not:

 62 // NewPodGoneEvent creates an event indicating that a pod is missing
 63 func NewPodGoneEvent(podName, role string, apiObject APIObject) *v1.Event {
 64     event := newDeploymentEvent(apiObject)
 65     event.Type = v1.EventTypeNormal
 66     event.Reason = fmt.Sprintf("Pod Of %s Gone", strings.Title(role))
 67     event.Message = fmt.Sprintf("Pod %s of member %s is gone", podName, role)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm following the etcd-operator on this

Copy link
Contributor

@ewoutp ewoutp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All new files need a copyright header.
Copy from one of the existing files.


func TestIsAlreadyExists(t *testing.T) {
assert.False(t, IsAlreadyExists(conflictError))
assert.False(t, IsConflict(maskAny(invalidError)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsConflict -> IsAlreadyExists


func TestIsNotFound(t *testing.T) {
assert.False(t, IsNotFound(invalidError))
assert.False(t, IsConflict(maskAny(invalidError)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsConflict -> IsNotFound

Copy link
Contributor

@ewoutp ewoutp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ObiWahn ObiWahn merged commit dd3f574 into master Mar 9, 2018
@ObiWahn ObiWahn deleted the test/errors branch March 9, 2018 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants