Skip to content

Commit

Permalink
Added require statements to gameserversets pkg (googleforgames#1696)
Browse files Browse the repository at this point in the history
Tests update: Added require statements to gameserversets package

Co-authored-by: Robert Bailey <robertbailey@google.com>
  • Loading branch information
2 people authored and ilkercelikyilmaz committed Oct 23, 2020
1 parent 9b7e15a commit 3913f8a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
18 changes: 9 additions & 9 deletions pkg/gameserversets/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/heptiolabs/healthcheck"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
admv1beta1 "k8s.io/api/admission/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -303,7 +304,7 @@ func TestComputeStatus(t *testing.T) {
utilruntime.FeatureTestMutex.Lock()
defer utilruntime.FeatureTestMutex.Unlock()

assert.NoError(t, utilruntime.ParseFeatures(string(utilruntime.FeaturePlayerTracking)+"=true"))
require.NoError(t, utilruntime.ParseFeatures(string(utilruntime.FeaturePlayerTracking)+"=true"))

var list []*agonesv1.GameServer
gs1 := gsWithState(agonesv1.GameServerStateAllocated)
Expand Down Expand Up @@ -373,12 +374,12 @@ func TestControllerWatchGameServers(t *testing.T) {
}

expected, err := cache.MetaNamespaceKeyFunc(gsSet)
assert.Nil(t, err)
require.NoError(t, err)

// gsSet add
logrus.Info("adding gsSet")
gsSetWatch.Add(gsSet.DeepCopy())
assert.Nil(t, err)

assert.Equal(t, expected, f())
// gsSet update
logrus.Info("modify gsSet")
Expand Down Expand Up @@ -630,13 +631,13 @@ func TestControllerUpdateValidationHandler(t *testing.T) {
Spec: agonesv1.GameServerSetSpec{Replicas: 5},
}
raw, err := json.Marshal(fixture)
assert.Nil(t, err)
require.NoError(t, err)

t.Run("valid gameserverset update", func(t *testing.T) {
newGSS := fixture.DeepCopy()
newGSS.Spec.Replicas = 10
newRaw, err := json.Marshal(newGSS)
assert.Nil(t, err)
require.NoError(t, err)

review := admv1beta1.AdmissionReview{
Request: &admv1beta1.AdmissionRequest{
Expand All @@ -653,7 +654,7 @@ func TestControllerUpdateValidationHandler(t *testing.T) {
}

result, err := c.updateValidationHandler(review)
assert.Nil(t, err)
require.NoError(t, err)
assert.True(t, result.Response.Allowed)
})

Expand All @@ -665,7 +666,7 @@ func TestControllerUpdateValidationHandler(t *testing.T) {
},
}
newRaw, err := json.Marshal(newGSS)
assert.Nil(t, err)
require.NoError(t, err)

assert.NotEqual(t, string(raw), string(newRaw))

Expand All @@ -683,9 +684,8 @@ func TestControllerUpdateValidationHandler(t *testing.T) {
Response: &admv1beta1.AdmissionResponse{Allowed: true},
}

logrus.Info("here?")
result, err := c.updateValidationHandler(review)
assert.Nil(t, err)
require.NoError(t, err)
assert.False(t, result.Response.Allowed)
assert.Equal(t, metav1.StatusFailure, result.Response.Result.Status)
assert.Equal(t, metav1.StatusReasonInvalid, result.Response.Result.Reason)
Expand Down
3 changes: 2 additions & 1 deletion pkg/gameserversets/gameserversets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"agones.dev/agones/pkg/gameservers"
agtesting "agones.dev/agones/pkg/testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
k8stesting "k8s.io/client-go/testing"
Expand Down Expand Up @@ -98,7 +99,7 @@ func TestListGameServersByGameServerSetOwner(t *testing.T) {
defer cancel()

list, err := ListGameServersByGameServerSetOwner(gameServers.Lister(), gsSet)
assert.Nil(t, err)
require.NoError(t, err)

// sort of stable ordering
sort.SliceStable(list, func(i, j int) bool {
Expand Down

0 comments on commit 3913f8a

Please sign in to comment.