-
Notifications
You must be signed in to change notification settings - Fork 817
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
Improved gameserver unit tests #1485
Conversation
@@ -572,22 +584,13 @@ func (gs *GameServer) FindGameServerContainer() (int, corev1.Container, error) { | |||
// ApplyToPodContainer applies func(v1.Container) to the specified container in the pod. | |||
// Returns an error if the container is not found. | |||
func (gs *GameServer) ApplyToPodContainer(pod *corev1.Pod, containerName string, f func(corev1.Container) corev1.Container) error { | |||
var container corev1.Container |
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.
Just decided to make this code a bit easier. In the previous implementation, containerIndex was the last match of container names. But in general, having 2 containers with the same name is not valid, so it's ok to return the first occurrence.
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.
There is a Pod
validation which prohibit having two containers in one Pod
with the same name.
Build Succeeded 👏 Build Id: a1e6b383-b2e3-4054-b670-c759b69fcb9a The following development artifacts have been built, and will exist for the next 30 days:
A preview of the website (the last 30 builds are retained): To install this version:
|
}) | ||
} | ||
} | ||
|
||
if !runtime.FeatureEnabled(runtime.FeatureContainerPortAllocation) { |
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.
That's a great way to separate this Feature logic.
@@ -439,7 +451,7 @@ func (gss *GameServerSpec) Validate(devAddress string) ([]metav1.StatusCause, bo | |||
}) | |||
} | |||
|
|||
if p.Container != nil && gss.Container != "" { | |||
if p.Container != nil && gss.Container != "" && runtime.FeatureEnabled(runtime.FeatureContainerPortAllocation) { |
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.
👍
250ec0c
to
2847dd4
Compare
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.
One question on one test, but otherwise looks good.
@@ -358,17 +427,22 @@ func TestGameServerApplyDefaults(t *testing.T) { | |||
} | |||
|
|||
func TestGameServerValidate(t *testing.T) { | |||
gs := GameServer{ | |||
t.Parallel() | |||
var fields []string |
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.
Should this be turned into a table based test, since it's grown so large?
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.
I thought about it... but wasn't sure if it is worth spending extra time on that. But once you mentioned it - let's do that.
added more gameserver unit tests Added new tests
2847dd4
to
a3ebea4
Compare
Build Failed 😱 Build Id: 8e9091d4-442d-4f6c-becd-a3599093cdb2 To get permission to view the Cloud Build view, join the agones-discuss Google Group. |
a3ebea4
to
9d41a42
Compare
@markmandel I've refactored Validate method and extracted tests which test features functionality to a separate function. Please check. |
Build Failed 😱 Build Id: af34469b-a2de-4e47-89f3-ec7d1fbb7429 To get permission to view the Cloud Build view, join the agones-discuss Google Group. |
9d41a42
to
674d80a
Compare
Build Failed 😱 Build Id: 1a9c330e-57c0-4f99-bb27-79d56c2cb823 To get permission to view the Cloud Build view, join the agones-discuss Google Group. |
valdiate refactoring valdiate method refactoring removed redundant file linter fix
674d80a
to
e9acbf5
Compare
Build Succeeded 👏 Build Id: 9feaa4cc-b710-4c11-b5ac-af5eaf226be5 The following development artifacts have been built, and will exist for the next 30 days:
A preview of the website (the last 30 builds are retained): To install this version:
|
var testCases = []struct { | ||
description string | ||
gs *GameServer | ||
errExpected string |
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.
Something to consider: Could pull the expected items into their own struct definition. I find it's a bit easier to read when there are > 1 expected items.
Don't have to do this, but thought I'd suggest it and see if it resonated for you.
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.
I like this idea - nice way to separate expected values. Applied all your suggestions, thanks for the review.
Build Failed 😱 Build Id: 9a7861ba-a754-4816-8d6c-f71a852d04f2 To get permission to view the Cloud Build view, join the agones-discuss Google Group. |
applied review notes
c308919
to
ddf8d83
Compare
Build Succeeded 👏 Build Id: a3751db7-b5d5-4e48-aa9b-f20fbb5a9cef The following development artifacts have been built, and will exist for the next 30 days:
A preview of the website (the last 30 builds are retained): To install this version:
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: akremsa, markmandel The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
* added some gameserver unit tests
What type of PR is this?
What this PR does / Why we need it:
Added missing unit tests, refactored some old ones. During working on tests I've found a missing check in Validate method, which is related to #1396
Before:
After: