agones.dev/agones@v1.54.0/test/e2e/examples_test.go (about) 1 // Copyright 2023 Google LLC All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package e2e 16 17 import ( 18 "context" 19 "testing" 20 21 e2eframework "agones.dev/agones/test/e2e/framework" 22 "github.com/stretchr/testify/assert" 23 "github.com/stretchr/testify/require" 24 corev1 "k8s.io/api/core/v1" 25 "k8s.io/apimachinery/pkg/api/resource" 26 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 27 28 agonesv1 "agones.dev/agones/pkg/apis/agones/v1" 29 ) 30 31 func TestSuperTuxKartGameServerReady(t *testing.T) { 32 t.Parallel() 33 34 log := e2eframework.TestLogger(t) 35 36 gs := &agonesv1.GameServer{ 37 ObjectMeta: metav1.ObjectMeta{ 38 GenerateName: "supertuxkart-", 39 }, 40 Spec: agonesv1.GameServerSpec{ 41 Container: "supertuxkart", 42 Ports: []agonesv1.GameServerPort{{ 43 ContainerPort: 8080, 44 Name: "default", 45 PortPolicy: agonesv1.Dynamic, 46 Protocol: corev1.ProtocolUDP, 47 }}, 48 Health: agonesv1.Health{ 49 InitialDelaySeconds: 120, 50 PeriodSeconds: 10, 51 }, 52 Template: corev1.PodTemplateSpec{ 53 Spec: corev1.PodSpec{ 54 Containers: []corev1.Container{ 55 { 56 Name: "supertuxkart", 57 Image: "us-docker.pkg.dev/agones-images/examples/supertuxkart-example:0.21", 58 Resources: corev1.ResourceRequirements{ 59 Requests: corev1.ResourceList{ 60 corev1.ResourceMemory: resource.MustParse("1Gi"), 61 corev1.ResourceCPU: resource.MustParse("500m"), 62 }, 63 }, 64 Env: []corev1.EnvVar{ 65 { 66 Name: "ENABLE_PLAYER_TRACKING", 67 Value: "false", 68 }, 69 }, 70 }, 71 }, 72 }, 73 }, 74 }, 75 } 76 77 // Use the e2e framework's function to create the GameServer and wait until it's ready 78 readyGs, err := framework.CreateGameServerAndWaitUntilReady(t, framework.Namespace, gs) 79 if err != nil { 80 log.Info("Game Server Events:") 81 framework.LogEvents(t, log, readyGs.ObjectMeta.Namespace, readyGs) 82 83 // Get pod and log events 84 log.Info("Game Server Pod Events:") 85 pod, err := framework.KubeClient.CoreV1().Pods(framework.Namespace).Get(context.Background(), readyGs.ObjectMeta.Name, metav1.GetOptions{}) 86 require.NoError(t, err) 87 framework.LogEvents(t, log, pod.ObjectMeta.Namespace, pod) 88 89 // Get container logs 90 log.Info("Game Server Container Logs:") 91 framework.LogPodContainers(t, pod) 92 } 93 require.NoError(t, err, "Ready game server timed out") 94 95 // Assert that the GameServer is in the expected state 96 require.Equal(t, agonesv1.GameServerStateReady, readyGs.Status.State) 97 } 98 99 func TestRustGameServerReady(t *testing.T) { 100 t.Parallel() 101 gs := &agonesv1.GameServer{ 102 ObjectMeta: metav1.ObjectMeta{ 103 GenerateName: "rust-simple-", 104 }, 105 Spec: agonesv1.GameServerSpec{ 106 Ports: []agonesv1.GameServerPort{{ 107 Name: "default", 108 PortPolicy: agonesv1.Dynamic, 109 ContainerPort: 7654, 110 Protocol: corev1.ProtocolUDP, 111 }}, 112 Template: corev1.PodTemplateSpec{ 113 Spec: corev1.PodSpec{ 114 Containers: []corev1.Container{ 115 { 116 Name: "rust-simple", 117 Image: "us-docker.pkg.dev/agones-images/examples/rust-simple-server:0.13", 118 }, 119 }, 120 }, 121 }, 122 }, 123 } 124 125 // Use the e2e framework's function to create the GameServer and wait until it's ready 126 readyGs, err := framework.CreateGameServerAndWaitUntilReady(t, framework.Namespace, gs) 127 require.NoError(t, err) 128 129 // Assert that the GameServer is in the expected state 130 assert.Equal(t, agonesv1.GameServerStateReady, readyGs.Status.State) 131 } 132 133 func TestCppSimpleGameServerReady(t *testing.T) { 134 t.Parallel() 135 gs := &agonesv1.GameServer{ 136 ObjectMeta: metav1.ObjectMeta{ 137 GenerateName: "cpp-simple-", 138 }, 139 Spec: agonesv1.GameServerSpec{ 140 Ports: []agonesv1.GameServerPort{{ 141 Name: "default", 142 PortPolicy: agonesv1.Dynamic, 143 ContainerPort: 7654, 144 Protocol: corev1.ProtocolUDP, 145 }}, 146 Template: corev1.PodTemplateSpec{ 147 Spec: corev1.PodSpec{ 148 Containers: []corev1.Container{ 149 { 150 Name: "cpp-simple", 151 Image: "us-docker.pkg.dev/agones-images/examples/cpp-simple-server:0.23", 152 }, 153 }, 154 }, 155 }, 156 }, 157 } 158 159 // Use the e2e framework's function to create the GameServer and wait until it's ready 160 readyGs, err := framework.CreateGameServerAndWaitUntilReady(t, framework.Namespace, gs) 161 require.NoError(t, err) 162 163 // Assert that the GameServer is in the expected state 164 assert.Equal(t, agonesv1.GameServerStateReady, readyGs.Status.State) 165 } 166 167 func TestNodeJSGameServerReady(t *testing.T) { 168 t.Parallel() 169 gs := &agonesv1.GameServer{ 170 ObjectMeta: metav1.ObjectMeta{ 171 GenerateName: "nodejs-simple-", 172 }, 173 Spec: agonesv1.GameServerSpec{ 174 Ports: []agonesv1.GameServerPort{{ 175 Name: "default", 176 PortPolicy: agonesv1.Dynamic, 177 ContainerPort: 7654, 178 Protocol: corev1.ProtocolUDP, 179 }}, 180 Health: agonesv1.Health{ 181 InitialDelaySeconds: 30, 182 PeriodSeconds: 30, 183 }, 184 Template: corev1.PodTemplateSpec{ 185 Spec: corev1.PodSpec{ 186 Containers: []corev1.Container{ 187 { 188 Name: "nodejs-simple", 189 Image: "us-docker.pkg.dev/agones-images/examples/nodejs-simple-server:0.10", 190 Resources: corev1.ResourceRequirements{ 191 Requests: corev1.ResourceList{ 192 corev1.ResourceMemory: resource.MustParse("100Mi"), 193 corev1.ResourceCPU: resource.MustParse("100m"), 194 }, 195 }, 196 }, 197 }, 198 }, 199 }, 200 }, 201 } 202 203 // Use the e2e framework's function to create the GameServer and wait until it's ready 204 readyGs, err := framework.CreateGameServerAndWaitUntilReady(t, framework.Namespace, gs) 205 require.NoError(t, err) 206 207 // Assert that the GameServer is in the expected state 208 assert.Equal(t, agonesv1.GameServerStateReady, readyGs.Status.State) 209 } 210 211 func TestXonoticGameServerReady(t *testing.T) { 212 t.Parallel() 213 gs := &agonesv1.GameServer{ 214 ObjectMeta: metav1.ObjectMeta{ 215 GenerateName: "xonotic-", 216 }, 217 218 Spec: agonesv1.GameServerSpec{ 219 Container: "xonotic", 220 Ports: []agonesv1.GameServerPort{{ 221 ContainerPort: 26000, 222 Name: "default", 223 PortPolicy: agonesv1.Dynamic, 224 Protocol: corev1.ProtocolUDP, 225 }}, 226 Health: agonesv1.Health{ 227 InitialDelaySeconds: 60, 228 PeriodSeconds: 5, 229 }, 230 Template: corev1.PodTemplateSpec{ 231 Spec: corev1.PodSpec{ 232 Containers: []corev1.Container{ 233 { 234 Name: "xonotic", 235 Image: "us-docker.pkg.dev/agones-images/examples/xonotic-example:2.5", 236 Resources: corev1.ResourceRequirements{ 237 Requests: corev1.ResourceList{ 238 corev1.ResourceMemory: resource.MustParse("700Mi"), 239 corev1.ResourceCPU: resource.MustParse("200m"), 240 }, 241 }, 242 }, 243 }, 244 }, 245 }, 246 }, 247 } 248 249 // Use the e2e framework's function to create the GameServer and wait until it's ready 250 readyGs, err := framework.CreateGameServerAndWaitUntilReady(t, framework.Namespace, gs) 251 require.NoError(t, err) 252 253 // Assert that the GameServer is in the expected state 254 assert.Equal(t, agonesv1.GameServerStateReady, readyGs.Status.State) 255 }