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

Improved gameserver unit tests #1485

Merged
merged 4 commits into from
Apr 28, 2020

Conversation

akremsa
Copy link
Contributor

@akremsa akremsa commented Apr 22, 2020

What type of PR is this?

/kind cleanup

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:
Screenshot 2020-04-22 at 15 46 07
Screenshot 2020-04-22 at 15 45 39

After:
Screenshot 2020-04-22 at 15 47 12
Screenshot 2020-04-22 at 15 47 37

@@ -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
Copy link
Contributor Author

@akremsa akremsa Apr 22, 2020

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.

Copy link
Collaborator

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.

@agones-bot
Copy link
Collaborator

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:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1485/head:pr_1485 && git checkout pr_1485
  • helm install ./install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.6.0-250ec0c

})
}
}

if !runtime.FeatureEnabled(runtime.FeatureContainerPortAllocation) {
Copy link
Collaborator

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) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@aLekSer aLekSer added area/tests Unit tests, e2e tests, anything to make sure things don't break kind/cleanup Refactoring code, fixing up documentation, etc labels Apr 22, 2020
Copy link
Member

@markmandel markmandel left a 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
Copy link
Member

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?

Copy link
Contributor Author

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.

pkg/apis/agones/v1/common.go Outdated Show resolved Hide resolved
@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: 8e9091d4-442d-4f6c-becd-a3599093cdb2

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

@akremsa
Copy link
Contributor Author

akremsa commented Apr 25, 2020

@markmandel I've refactored Validate method and extracted tests which test features functionality to a separate function. Please check.

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: af34469b-a2de-4e47-89f3-ec7d1fbb7429

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

@agones-bot
Copy link
Collaborator

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
@agones-bot
Copy link
Collaborator

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:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1485/head:pr_1485 && git checkout pr_1485
  • helm install ./install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.6.0-e9acbf5

pkg/apis/agones/v1/common.go Outdated Show resolved Hide resolved
pkg/apis/agones/v1/gameserver_test.go Outdated Show resolved Hide resolved
pkg/apis/agones/v1/gameserver_test.go Outdated Show resolved Hide resolved
var testCases = []struct {
description string
gs *GameServer
errExpected string
Copy link
Member

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.

Copy link
Contributor Author

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.

@agones-bot
Copy link
Collaborator

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
@agones-bot
Copy link
Collaborator

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:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1485/head:pr_1485 && git checkout pr_1485
  • helm install ./install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.6.0-ddf8d83

@google-oss-robot
Copy link

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@markmandel markmandel merged commit 233d0ff into googleforgames:master Apr 28, 2020
@markmandel markmandel added this to the 1.6.0 milestone Apr 28, 2020
ilkercelikyilmaz pushed a commit to ilkercelikyilmaz/agones that referenced this pull request Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved area/tests Unit tests, e2e tests, anything to make sure things don't break kind/cleanup Refactoring code, fixing up documentation, etc lgtm size/XXL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants