Skip to content

Commit

Permalink
Adds gameserver e2e test for Lists (#3507)
Browse files Browse the repository at this point in the history
  • Loading branch information
igooch committed Nov 15, 2023
1 parent 25e0c4a commit 065052a
Showing 1 changed file with 138 additions and 2 deletions.
140 changes: 138 additions & 2 deletions test/e2e/gameserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ func TestPlayerConnectAndDisconnect(t *testing.T) {
assert.ElementsMatch(t, []string{"1", "3"}, gs.Status.Players.IDs)
}

func TestCountsAndLists(t *testing.T) {
func TestCounters(t *testing.T) {
if !runtime.FeatureEnabled(runtime.FeatureCountsAndLists) {
t.SkipNow()
}
Expand Down Expand Up @@ -1453,7 +1453,7 @@ func TestCountsAndLists(t *testing.T) {
wantCount: "1",
},
}

// nolint:dupl // Linter errors on lines are duplicate of TestLists
for name, testCase := range testCases {
t.Run(name, func(t *testing.T) {
logrus.WithField("msg", testCase.msg).Info(name)
Expand All @@ -1480,6 +1480,142 @@ func TestCountsAndLists(t *testing.T) {
}
}

func TestLists(t *testing.T) {
if !runtime.FeatureEnabled(runtime.FeatureCountsAndLists) {
t.SkipNow()
}
t.Parallel()
ctx := context.Background()
gs := framework.DefaultGameServer(framework.Namespace)

gs.Spec.Lists = make(map[string]agonesv1.ListStatus)
gs.Spec.Lists["games"] = agonesv1.ListStatus{
Values: []string{"game1", "game2"},
Capacity: 50,
}
gs.Spec.Lists["foo"] = agonesv1.ListStatus{
Values: []string{},
Capacity: 1,
}
gs.Spec.Lists["bar"] = agonesv1.ListStatus{
Values: []string{"bar1", "bar2"},
Capacity: 10,
}
gs.Spec.Lists["baz"] = agonesv1.ListStatus{
Values: []string{"baz1"},
Capacity: 1,
}
gs.Spec.Lists["qux"] = agonesv1.ListStatus{
Values: []string{"qux1", "qux2", "qux3", "qux4"},
Capacity: 5,
}

gs, err := framework.CreateGameServerAndWaitUntilReady(t, framework.Namespace, gs)
require.NoError(t, err)
defer framework.AgonesClient.AgonesV1().GameServers(framework.Namespace).Delete(ctx, gs.ObjectMeta.Name, metav1.DeleteOptions{}) // nolint: errcheck
assert.Equal(t, agonesv1.GameServerStateReady, gs.Status.State)

testCases := map[string]struct {
msg string
want string
listName string
wantLength string
wantCapacity string
}{
"GetListCapacity": {
msg: "GET_LIST_CAPACITY games",
want: "50",
},
"SetListCapacity": {
msg: "SET_LIST_CAPACITY foo 1000",
want: "true",
listName: "foo",
wantCapacity: "1000",
},
"SetListCapacity past 1000": {
msg: "SET_LIST_CAPACITY games 1001",
want: "ERROR: false\n",
listName: "games",
wantCapacity: "50",
},
"SetListCapacity negative": {
msg: "SET_LIST_CAPACITY games -1",
want: "ERROR: false\n",
listName: "games",
wantCapacity: "50",
},
"ListContains": {
msg: "LIST_CONTAINS games game2",
want: "true",
},
"ListContains false": {
msg: "LIST_CONTAINS games game0",
want: "false",
},
"GetListLength": {
msg: "GET_LIST_LENGTH games",
want: "2",
},
"GetListValues": {
msg: "GET_LIST_VALUES games",
want: "game1,game2\n",
},
"GetListValues empty": {
msg: "GET_LIST_VALUES foo",
want: "\n",
},
"AppendListValue": {
msg: "APPEND_LIST_VALUE bar bar3",
want: "true",
listName: "bar",
wantLength: "3",
},
"AppendListValue past capacity": {
msg: "APPEND_LIST_VALUE baz baz2",
want: "ERROR: false\n",
listName: "baz",
wantLength: "1",
},
"DeleteListValue": {
msg: "DELETE_LIST_VALUE qux qux3",
want: "true",
listName: "qux",
wantLength: "3",
},
"DeleteListValue value does not exist": {
msg: "DELETE_LIST_VALUE games game4",
want: "ERROR: false\n",
listName: "games",
wantLength: "2",
},
}
// nolint:dupl // Linter errors on lines are duplicate of TestCounters
for name, testCase := range testCases {
t.Run(name, func(t *testing.T) {
logrus.WithField("msg", testCase.msg).Info(name)
reply, err := framework.SendGameServerUDP(t, gs, testCase.msg)
require.NoError(t, err)
assert.Equal(t, testCase.want, reply)

if testCase.wantLength != "" {
msg := "GET_LIST_LENGTH " + testCase.listName
logrus.WithField("msg", msg).Info("Sending GetListLength")
reply, err = framework.SendGameServerUDP(t, gs, msg)
require.NoError(t, err)
assert.Equal(t, testCase.wantLength, reply)
}

if testCase.wantCapacity != "" {
msg := "GET_LIST_CAPACITY " + testCase.listName
logrus.WithField("msg", msg).Info("Sending GetListCapacity")
reply, err = framework.SendGameServerUDP(t, gs, msg)
require.NoError(t, err)
assert.Equal(t, testCase.wantCapacity, reply)
}
})
}
}

func TestGracefulShutdown(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 065052a

Please sign in to comment.