This repository was archived by the owner on Jul 30, 2021. It is now read-only.
generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 65
Use CAPI utils to reduce boilerplate #106
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,42 @@ import ( | |
) | ||
|
||
func TestControlPlaneInitLockerAcquire(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
getError error | ||
}{ | ||
{ | ||
name: "create succeeds", | ||
getError: apierrors.NewNotFound(schema.GroupResource{Group: "", Resource: "configmaps"}, "uid1-configmap"), | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
l := &controlPlaneInitLocker{ | ||
log: log.ZapLogger(true), | ||
configMapClient: &configMapsGetter{ | ||
getError: tc.getError, | ||
}, | ||
} | ||
|
||
cluster := &clusterv2.Cluster{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: "ns1", | ||
Name: "name1", | ||
UID: types.UID("uid1"), | ||
}, | ||
} | ||
|
||
acquired := l.Acquire(cluster) | ||
if !acquired { | ||
t.Fatal("acquired was false but it should have been true") | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestControlPlaneInitLockerAcquireErrors(t *testing.T) { | ||
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. [1] 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. This one has 3 table tests, I don't think we should get rid of subtests. 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. time to take a break... |
||
tests := []struct { | ||
name string | ||
configMap *v1.ConfigMap | ||
|
@@ -49,11 +85,6 @@ func TestControlPlaneInitLockerAcquire(t *testing.T) { | |
getError: errors.New("get error"), | ||
expectAcquire: false, | ||
}, | ||
{ | ||
name: "create succeeds", | ||
getError: apierrors.NewNotFound(schema.GroupResource{Group: "", Resource: "configmaps"}, "uid1-configmap"), | ||
expectAcquire: true, | ||
}, | ||
{ | ||
name: "create fails", | ||
getError: apierrors.NewNotFound(schema.GroupResource{Group: "", Resource: "configmaps"}, "uid1-configmap"), | ||
|
@@ -82,8 +113,8 @@ func TestControlPlaneInitLockerAcquire(t *testing.T) { | |
} | ||
|
||
acquired := l.Acquire(cluster) | ||
if tc.expectAcquire != acquired { | ||
t.Errorf("expected %t, got %t", tc.expectAcquire, acquired) | ||
if acquired { | ||
t.Fatal("expected acquired to be false but it is true") | ||
} | ||
}) | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
[1] Are you expecting more test case should be added? otherwise, we can get rid of subtests...
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.
some context:
I took a test that was testing too many things (error case + non error case) and split it into these two test functions. I kept the structure identical to make sure the tests didn't actually change.
I think it's ok to leave the table structure even with only one test.
My general approach here is to: Write a test that does not use table testing. If I need a second or third case I will add table tests if it makes sense, but overall I prefer the look and readability of table tests.
Are you ok leaving this one as is?
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.
ok!