diff --git a/cmd/e2e/gameserverapi_test.go b/cmd/e2e/gameserverapi_test.go index 94c8b3b5..f032fd81 100644 --- a/cmd/e2e/gameserverapi_test.go +++ b/cmd/e2e/gameserverapi_test.go @@ -10,7 +10,7 @@ import ( "time" "github.com/google/uuid" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" mpsv1alpha1 "github.com/playfab/thundernetes/pkg/operator/api/v1alpha1" corev1 "k8s.io/api/core/v1" @@ -29,89 +29,125 @@ const ( var imgName string var _ = Describe("GameServerAPI tests", func() { - Context("GameServerAPI tests", func() { - imgName = os.Getenv("IMG") - Expect(imgName).NotTo(BeEmpty()) + imgName = os.Getenv("IMG") + Expect(imgName).NotTo(BeEmpty()) - client := http.Client{ - Timeout: 5 * time.Second, - } - - testNamespace := "gameserverapi" - url := fmt.Sprintf("http://%s:%d/api/v1", host, port) + client := http.Client{ + Timeout: 5 * time.Second, + } - buildName := "test-build-gameserverapi" - buildNameNoImage := "test-build-gameserverapi-no-image" + testNamespace := "gameserverapi" + url := fmt.Sprintf("http://%s:%d/api/v1", host, port) - It("should return an error when creating a GameServerBuild that does not have a name", func() { - build := createGameServerBuild(buildNameNoImage, testNamespace) - build.Name = "" - b, err := json.Marshal(build) - Expect(err).ToNot(HaveOccurred()) - req, err := client.Post(url+"/gameserverbuilds", contentType, bytes.NewReader(b)) - Expect(err).ToNot(HaveOccurred()) - Expect(req.StatusCode).To(Equal(http.StatusInternalServerError)) - }) + buildName := "test-build-gameserverapi" + buildNameNoImage := "test-build-gameserverapi-no-image" - It("should return an error when deleting a non-existent GameServerBuild", func() { - req, err := http.NewRequest("DELETE", url+"/gameserverbuilds/nonexistentbuild", nil) - Expect(err).ToNot(HaveOccurred()) - res, err := client.Do(req) - Expect(err).ToNot(HaveOccurred()) - Expect(res.StatusCode).To(Equal(http.StatusNotFound)) - }) + It("should return an error when creating a GameServerBuild that does not have a name", func() { + build := createGameServerBuild(buildNameNoImage, testNamespace) + build.Name = "" + b, err := json.Marshal(build) + Expect(err).ToNot(HaveOccurred()) + req, err := client.Post(url+"/gameserverbuilds", contentType, bytes.NewReader(b)) + Expect(err).ToNot(HaveOccurred()) + Expect(req.StatusCode).To(Equal(http.StatusInternalServerError)) + }) - It("should return an error when getting an non-existing GameServerBuild", func() { - r, err := client.Get(fmt.Sprintf("%s/gameserverbuilds/%s/%s", url, testNamespace, "nonexistentbuild")) - Expect(err).ToNot(HaveOccurred()) - Expect(r.StatusCode).To(Equal(http.StatusNotFound)) - }) + It("should return an error when deleting a non-existent GameServerBuild", func() { + req, err := http.NewRequest("DELETE", url+"/gameserverbuilds/nonexistentbuild", nil) + Expect(err).ToNot(HaveOccurred()) + res, err := client.Do(req) + Expect(err).ToNot(HaveOccurred()) + Expect(res.StatusCode).To(Equal(http.StatusNotFound)) + }) - It("should return an error when getting an non-existing GameServer", func() { - r, err := client.Get(fmt.Sprintf("%s/gameservers/%s/%s", url, testNamespace, "nonexistentgameserver")) - Expect(err).ToNot(HaveOccurred()) - Expect(r.StatusCode).To(Equal(http.StatusNotFound)) - }) + It("should return an error when getting an non-existing GameServerBuild", func() { + r, err := client.Get(fmt.Sprintf("%s/gameserverbuilds/%s/%s", url, testNamespace, "nonexistentbuild")) + Expect(err).ToNot(HaveOccurred()) + Expect(r.StatusCode).To(Equal(http.StatusNotFound)) + }) - It("should create a new GameServerBuild, list it and then delete it", func() { - build := createGameServerBuild(buildName, testNamespace) - b, err := json.Marshal(build) - Expect(err).ToNot(HaveOccurred()) - req, err := client.Post(url+"/gameserverbuilds", contentType, bytes.NewReader(b)) - Expect(err).ToNot(HaveOccurred()) - Expect(req.StatusCode).To(Equal(http.StatusCreated)) + It("should return an error when getting an non-existing GameServer", func() { + r, err := client.Get(fmt.Sprintf("%s/gameservers/%s/%s", url, testNamespace, "nonexistentgameserver")) + Expect(err).ToNot(HaveOccurred()) + Expect(r.StatusCode).To(Equal(http.StatusNotFound)) + }) - // list all the GameServerBuilds and see if the one we created is there - r, err := client.Get(url + "/gameserverbuilds") - Expect(err).ToNot(HaveOccurred()) - Expect(r.StatusCode).To(Equal(http.StatusOK)) - defer r.Body.Close() - var l mpsv1alpha1.GameServerBuildList - body, err := ioutil.ReadAll(r.Body) - Expect(err).ToNot(HaveOccurred()) - err = json.Unmarshal(body, &l) - Expect(err).ToNot(HaveOccurred()) - var found bool - for _, b := range l.Items { - if b.Name == buildName { - found = true - break - } + It("should create a new GameServerBuild, list it and then delete it", func() { + build := createGameServerBuild(buildName, testNamespace) + b, err := json.Marshal(build) + Expect(err).ToNot(HaveOccurred()) + req, err := client.Post(url+"/gameserverbuilds", contentType, bytes.NewReader(b)) + Expect(err).ToNot(HaveOccurred()) + Expect(req.StatusCode).To(Equal(http.StatusCreated)) + + // list all the GameServerBuilds and see if the one we created is there + r, err := client.Get(url + "/gameserverbuilds") + Expect(err).ToNot(HaveOccurred()) + Expect(r.StatusCode).To(Equal(http.StatusOK)) + defer r.Body.Close() + var l mpsv1alpha1.GameServerBuildList + body, err := ioutil.ReadAll(r.Body) + Expect(err).ToNot(HaveOccurred()) + err = json.Unmarshal(body, &l) + Expect(err).ToNot(HaveOccurred()) + var found bool + for _, b := range l.Items { + if b.Name == buildName { + found = true + break } - Expect(found).To(BeTrue()) - - // get the specific GameServerBuild - r, err = client.Get(fmt.Sprintf("%s/gameserverbuilds/%s/%s", url, testNamespace, buildName)) - Expect(err).ToNot(HaveOccurred()) - Expect(r.StatusCode).To(Equal(http.StatusOK)) - var bu mpsv1alpha1.GameServerBuild - body, err = ioutil.ReadAll(r.Body) - Expect(err).ToNot(HaveOccurred()) - err = json.Unmarshal(body, &bu) + } + Expect(found).To(BeTrue()) + + // get the specific GameServerBuild + r, err = client.Get(fmt.Sprintf("%s/gameserverbuilds/%s/%s", url, testNamespace, buildName)) + Expect(err).ToNot(HaveOccurred()) + Expect(r.StatusCode).To(Equal(http.StatusOK)) + var bu mpsv1alpha1.GameServerBuild + body, err = ioutil.ReadAll(r.Body) + Expect(err).ToNot(HaveOccurred()) + err = json.Unmarshal(body, &bu) + Expect(err).ToNot(HaveOccurred()) + Expect(bu.Name).To(Equal(buildName)) + + // list GameServers for GameServerBuild + r, err = client.Get(fmt.Sprintf("%s/gameserverbuilds/%s/%s/gameservers", url, testNamespace, buildName)) + Expect(err).ToNot(HaveOccurred()) + var gsList mpsv1alpha1.GameServerList + body, err = ioutil.ReadAll(r.Body) + Expect(err).ToNot(HaveOccurred()) + err = json.Unmarshal(body, &gsList) + Expect(err).ToNot(HaveOccurred()) + Expect(len(gsList.Items)).To(Equal(2)) + + gsName := gsList.Items[0].Name + // get a GameServer + r, err = client.Get(fmt.Sprintf("%s/gameservers/%s/%s", url, testNamespace, gsName)) + Expect(err).ToNot(HaveOccurred()) + var gs mpsv1alpha1.GameServer + body, err = ioutil.ReadAll(r.Body) + Expect(err).ToNot(HaveOccurred()) + err = json.Unmarshal(body, &gs) + Expect(err).ToNot(HaveOccurred()) + Expect(gs.Name).To(Equal(gsName)) + + // delete this GameServer + req1, err := http.NewRequest("DELETE", fmt.Sprintf("%s/gameservers/%s/%s", url, testNamespace, gsName), nil) + Expect(err).ToNot(HaveOccurred()) + res, err := client.Do(req1) + Expect(err).ToNot(HaveOccurred()) + Expect(res.StatusCode).To(Equal(http.StatusOK)) + + // make sure this GameServer is not returned any more + // a finalizer runs so it will not disappear at once + Eventually(func() int { + r, err = client.Get(fmt.Sprintf("%s/gameservers/%s/%s", url, testNamespace, gsName)) Expect(err).ToNot(HaveOccurred()) - Expect(bu.Name).To(Equal(buildName)) + return r.StatusCode + }, timeout, interval).Should(Equal(http.StatusNotFound)) - // list GameServers for GameServerBuild + // make sure controller creates an extra GameServer + Eventually(func() int { r, err = client.Get(fmt.Sprintf("%s/gameserverbuilds/%s/%s/gameservers", url, testNamespace, buildName)) Expect(err).ToNot(HaveOccurred()) var gsList mpsv1alpha1.GameServerList @@ -119,86 +155,48 @@ var _ = Describe("GameServerAPI tests", func() { Expect(err).ToNot(HaveOccurred()) err = json.Unmarshal(body, &gsList) Expect(err).ToNot(HaveOccurred()) - Expect(len(gsList.Items)).To(Equal(2)) + return len(gsList.Items) + }, time.Second*5, time.Millisecond*500).Should(Equal(2)) - gsName := gsList.Items[0].Name - // get a GameServer - r, err = client.Get(fmt.Sprintf("%s/gameservers/%s/%s", url, testNamespace, gsName)) - Expect(err).ToNot(HaveOccurred()) - var gs mpsv1alpha1.GameServer - body, err = ioutil.ReadAll(r.Body) - Expect(err).ToNot(HaveOccurred()) - err = json.Unmarshal(body, &gs) - Expect(err).ToNot(HaveOccurred()) - Expect(gs.Name).To(Equal(gsName)) + // TODO: allocate so GameServerDetails can be created + // TODO: list GameServerDetails for GameServerBuild + // TODO: get a GameServerDetail - // delete this GameServer - req1, err := http.NewRequest("DELETE", fmt.Sprintf("%s/gameservers/%s/%s", url, testNamespace, gsName), nil) - Expect(err).ToNot(HaveOccurred()) - res, err := client.Do(req1) - Expect(err).ToNot(HaveOccurred()) - Expect(res.StatusCode).To(Equal(http.StatusOK)) - - // make sure this GameServer is not returned any more - // a finalizer runs so it will not disappear at once - Eventually(func() int { - r, err = client.Get(fmt.Sprintf("%s/gameservers/%s/%s", url, testNamespace, gsName)) - Expect(err).ToNot(HaveOccurred()) - return r.StatusCode - }, timeout, interval).Should(Equal(http.StatusNotFound)) - - // make sure controller creates an extra GameServer - Eventually(func() int { - r, err = client.Get(fmt.Sprintf("%s/gameserverbuilds/%s/%s/gameservers", url, testNamespace, buildName)) - Expect(err).ToNot(HaveOccurred()) - var gsList mpsv1alpha1.GameServerList - body, err = ioutil.ReadAll(r.Body) - Expect(err).ToNot(HaveOccurred()) - err = json.Unmarshal(body, &gsList) - Expect(err).ToNot(HaveOccurred()) - return len(gsList.Items) - }, time.Second*5, time.Millisecond*500).Should(Equal(2)) - - // TODO: allocate so GameServerDetails can be created - // TODO: list GameServerDetails for GameServerBuild - // TODO: get a GameServerDetail - - // update the GameServerBuild to 3 standingBy and 6 max - patchBody := map[string]interface{}{ - "standingBy": 3, - "max": 6, - } - pb, err := json.Marshal(patchBody) - Expect(err).ToNot(HaveOccurred()) - req2, err := http.NewRequest("PATCH", fmt.Sprintf("%s/gameserverbuilds/%s/%s", url, testNamespace, buildName), bytes.NewReader(pb)) - Expect(err).ToNot(HaveOccurred()) - res, err = client.Do(req2) - Expect(err).ToNot(HaveOccurred()) - Expect(res.StatusCode).To(Equal(http.StatusOK)) - - // get the specific GameServerBuild again and make sure the values were updated - r, err = client.Get(fmt.Sprintf("%s/gameserverbuilds/%s/%s", url, testNamespace, buildName)) - Expect(err).ToNot(HaveOccurred()) - Expect(r.StatusCode).To(Equal(http.StatusOK)) - body, err = ioutil.ReadAll(r.Body) - Expect(err).ToNot(HaveOccurred()) - err = json.Unmarshal(body, &bu) - Expect(err).ToNot(HaveOccurred()) - Expect(bu.Spec.StandingBy).To(Equal(3)) - Expect(bu.Spec.Max).To(Equal(6)) - - // delete the GameServerBuild - req3, err := http.NewRequest("DELETE", fmt.Sprintf("%s/gameserverbuilds/%s/%s", url, testNamespace, buildName), nil) - Expect(err).ToNot(HaveOccurred()) - res, err = client.Do(req3) - Expect(err).ToNot(HaveOccurred()) - Expect(res.StatusCode).To(Equal(http.StatusOK)) - - // make sure the GameServerBuild is gone - r, err = client.Get(fmt.Sprintf("%s/gameserverbuilds/%s/%s", url, testNamespace, buildName)) - Expect(err).ToNot(HaveOccurred()) - Expect(r.StatusCode).To(Equal(http.StatusNotFound)) - }) + // update the GameServerBuild to 3 standingBy and 6 max + patchBody := map[string]interface{}{ + "standingBy": 3, + "max": 6, + } + pb, err := json.Marshal(patchBody) + Expect(err).ToNot(HaveOccurred()) + req2, err := http.NewRequest("PATCH", fmt.Sprintf("%s/gameserverbuilds/%s/%s", url, testNamespace, buildName), bytes.NewReader(pb)) + Expect(err).ToNot(HaveOccurred()) + res, err = client.Do(req2) + Expect(err).ToNot(HaveOccurred()) + Expect(res.StatusCode).To(Equal(http.StatusOK)) + + // get the specific GameServerBuild again and make sure the values were updated + r, err = client.Get(fmt.Sprintf("%s/gameserverbuilds/%s/%s", url, testNamespace, buildName)) + Expect(err).ToNot(HaveOccurred()) + Expect(r.StatusCode).To(Equal(http.StatusOK)) + body, err = ioutil.ReadAll(r.Body) + Expect(err).ToNot(HaveOccurred()) + err = json.Unmarshal(body, &bu) + Expect(err).ToNot(HaveOccurred()) + Expect(bu.Spec.StandingBy).To(Equal(3)) + Expect(bu.Spec.Max).To(Equal(6)) + + // delete the GameServerBuild + req3, err := http.NewRequest("DELETE", fmt.Sprintf("%s/gameserverbuilds/%s/%s", url, testNamespace, buildName), nil) + Expect(err).ToNot(HaveOccurred()) + res, err = client.Do(req3) + Expect(err).ToNot(HaveOccurred()) + Expect(res.StatusCode).To(Equal(http.StatusOK)) + + // make sure the GameServerBuild is gone + r, err = client.Get(fmt.Sprintf("%s/gameserverbuilds/%s/%s", url, testNamespace, buildName)) + Expect(err).ToNot(HaveOccurred()) + Expect(r.StatusCode).To(Equal(http.StatusNotFound)) }) }) diff --git a/cmd/e2e/suite_test.go b/cmd/e2e/suite_test.go index 8bc51d4f..abf587bd 100644 --- a/cmd/e2e/suite_test.go +++ b/cmd/e2e/suite_test.go @@ -3,7 +3,7 @@ package main import ( "testing" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/cmd/e2e/tools.go b/cmd/e2e/tools.go new file mode 100644 index 00000000..162844f2 --- /dev/null +++ b/cmd/e2e/tools.go @@ -0,0 +1,10 @@ +//go:build tools +// +build tools + +package main + +import ( + _ "github.com/onsi/ginkgo/v2/ginkgo" +) + +// https://onsi.github.io/ginkgo/#recommended-continuous-integration-configuration diff --git a/cmd/gameserverapi/main_test.go b/cmd/gameserverapi/main_test.go index ef01adad..1d887155 100644 --- a/cmd/gameserverapi/main_test.go +++ b/cmd/gameserverapi/main_test.go @@ -9,7 +9,7 @@ import ( "net/http/httptest" "testing" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" mpsv1alpha1 "github.com/playfab/thundernetes/pkg/operator/api/v1alpha1" "k8s.io/client-go/kubernetes/scheme" @@ -267,7 +267,7 @@ var _ = BeforeSuite(func() { kubeClient = clientBuilder.Build() Expect(kubeClient).NotTo(BeNil()) -}, 60) +}) var _ = AfterSuite(func() { By("tearing down the test environment") diff --git a/cmd/nodeagent/nodeagentmanager_test.go b/cmd/nodeagent/nodeagentmanager_test.go index bfb1dc30..68ea2ce8 100644 --- a/cmd/nodeagent/nodeagentmanager_test.go +++ b/cmd/nodeagent/nodeagentmanager_test.go @@ -13,7 +13,7 @@ import ( "testing" "time" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" diff --git a/e2e/run.sh b/e2e/run.sh index b1381ad0..783e6e3e 100755 --- a/e2e/run.sh +++ b/e2e/run.sh @@ -44,9 +44,11 @@ kubectl wait --for=condition=ready --timeout=300s pod -n thundernetes-system -l echo "-----Running end to end tests-----" cd cmd/e2e -go mod tidy && go run $(ls -1 *.go | grep -v _test.go) ${IMAGE_NAME_NETCORE_SAMPLE}:${IMAGE_TAG} +go build && ./e2e ${IMAGE_NAME_NETCORE_SAMPLE}:${IMAGE_TAG} && rm e2e echo "-----Running GameServer API tests-----" # create the gameserverapi namespace for the GameServer API tests kubectl create namespace gameserverapi -IMG=${IMAGE_NAME_NETCORE_SAMPLE}:${IMAGE_TAG} go test -count=1 ./... \ No newline at end of file +go get github.com/onsi/ginkgo/v2 +# https://onsi.github.io/ginkgo/#recommended-continuous-integration-configuration +IMG=${IMAGE_NAME_NETCORE_SAMPLE}:${IMAGE_TAG} go run github.com/onsi/ginkgo/v2/ginkgo -r --procs=2 --compilers=2 --randomize-all --randomize-suites --fail-on-pending --keep-going --cover --race --trace \ No newline at end of file diff --git a/go.mod b/go.mod index d633bcb8..96df5b20 100644 --- a/go.mod +++ b/go.mod @@ -6,8 +6,8 @@ require ( github.com/gin-gonic/gin v1.7.4 github.com/go-logr/logr v1.2.0 github.com/google/uuid v1.2.0 - github.com/onsi/ginkgo v1.16.5 - github.com/onsi/gomega v1.17.0 + github.com/onsi/ginkgo/v2 v2.1.1 + github.com/onsi/gomega v1.18.1 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.11.0 github.com/sirupsen/logrus v1.8.1 @@ -37,11 +37,13 @@ require ( github.com/go-playground/locales v0.13.0 // indirect github.com/go-playground/universal-translator v0.17.0 // indirect github.com/go-playground/validator/v10 v10.4.1 // indirect + github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/google/go-cmp v0.5.5 // indirect github.com/google/gofuzz v1.1.0 // indirect + github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect github.com/googleapis/gnostic v0.5.5 // indirect github.com/imdario/mergo v0.3.12 // indirect github.com/json-iterator/go v1.1.12 // indirect @@ -51,7 +53,6 @@ require ( github.com/moby/spdystream v0.2.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/nxadm/tail v1.4.8 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_model v0.2.0 // indirect github.com/prometheus/common v0.28.0 // indirect @@ -64,15 +65,15 @@ require ( golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect golang.org/x/net v0.0.0-20210825183410-e898025ed96a // indirect golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect - golang.org/x/sys v0.0.0-20211029165221-6e7872819dc8 // indirect + golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect golang.org/x/text v0.3.7 // indirect golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect + golang.org/x/tools v0.1.6-0.20210820212750-d4cc65f0b2ff // indirect gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.27.1 // indirect gopkg.in/inf.v0 v0.9.1 // indirect - gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect k8s.io/apiextensions-apiserver v0.23.0 // indirect diff --git a/go.sum b/go.sum index 0e6ddc7e..0e210270 100644 --- a/go.sum +++ b/go.sum @@ -179,6 +179,7 @@ github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+ github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE= github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= @@ -254,6 +255,8 @@ github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE= +github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs= @@ -381,11 +384,15 @@ github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9k github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= +github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= +github.com/onsi/ginkgo/v2 v2.1.1 h1:LCnPB85AvFNr91s0B2aDzEiiIg6MUwLYbryC1NSlWi8= +github.com/onsi/ginkgo/v2 v2.1.1/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.17.0 h1:9Luw4uT5HTjHTN8+aNcSThgH1vdXnmdJ8xIfZ4wyTRE= github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= +github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE= +github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= @@ -709,8 +716,9 @@ golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211029165221-6e7872819dc8 h1:M69LAlWZCshgp0QSzyDcSsSIejIEeuaCVpmwcKwyLMk= golang.org/x/sys v0.0.0-20211029165221-6e7872819dc8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b h1:9zKuko04nR4gjZ4+DNjHqRlAJqbJETHwiNKDqTfOjfE= golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -788,6 +796,7 @@ golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.6-0.20210820212750-d4cc65f0b2ff h1:VX/uD7MK0AHXGiScH3fsieUQUcpmRERPDYtqZdJnA+Q= golang.org/x/tools v0.1.6-0.20210820212750-d4cc65f0b2ff/go.mod h1:YD9qOF0M9xpSpdWTBbzEl5e/RnCefISl8E5Noe10jFM= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/pkg/operator/controllers/gameserver_controller_test.go b/pkg/operator/controllers/gameserver_controller_test.go index 81178a92..2a03f37c 100644 --- a/pkg/operator/controllers/gameserver_controller_test.go +++ b/pkg/operator/controllers/gameserver_controller_test.go @@ -4,7 +4,7 @@ import ( "context" "os" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" mpsv1alpha1 "github.com/playfab/thundernetes/pkg/operator/api/v1alpha1" corev1 "k8s.io/api/core/v1" diff --git a/pkg/operator/controllers/gameserverbuild_controller.go b/pkg/operator/controllers/gameserverbuild_controller.go index d871cc6d..3959dc68 100644 --- a/pkg/operator/controllers/gameserverbuild_controller.go +++ b/pkg/operator/controllers/gameserverbuild_controller.go @@ -24,7 +24,6 @@ import ( mpsv1alpha1 "github.com/playfab/thundernetes/pkg/operator/api/v1alpha1" corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/errors" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -182,7 +181,7 @@ func (r *GameServerBuildReconciler) Reconcile(ctx context.Context, req ctrl.Requ ResourceVersion: &gs.ResourceVersion, }, }); err != nil { - if errors.IsConflict(err) { // this GameServer has been updated, skip it + if apierrors.IsConflict(err) { // this GameServer has been updated, skip it continue } return ctrl.Result{}, err @@ -208,7 +207,7 @@ func (r *GameServerBuildReconciler) Reconcile(ctx context.Context, req ctrl.Requ ResourceVersion: &gs.ResourceVersion, }, }); err != nil { - if errors.IsConflict(err) { // this GameServer has been updated, skip it + if apierrors.IsConflict(err) { // this GameServer has been updated, skip it continue } return ctrl.Result{}, err diff --git a/pkg/operator/controllers/gameserverbuild_controller_test.go b/pkg/operator/controllers/gameserverbuild_controller_test.go index 15b08e92..377aa850 100644 --- a/pkg/operator/controllers/gameserverbuild_controller_test.go +++ b/pkg/operator/controllers/gameserverbuild_controller_test.go @@ -5,7 +5,7 @@ import ( "os" "time" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" mpsv1alpha1 "github.com/playfab/thundernetes/pkg/operator/api/v1alpha1" corev1 "k8s.io/api/core/v1" diff --git a/pkg/operator/controllers/port_registry_test.go b/pkg/operator/controllers/port_registry_test.go index c1fa35d8..e1857fd0 100644 --- a/pkg/operator/controllers/port_registry_test.go +++ b/pkg/operator/controllers/port_registry_test.go @@ -7,7 +7,7 @@ import ( "time" "github.com/go-logr/logr" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" mpsv1alpha1 "github.com/playfab/thundernetes/pkg/operator/api/v1alpha1" @@ -22,105 +22,99 @@ const ( ) var _ = Describe("Port registry tests", func() { - Context("testing allocating and deleting ports", func() { - - log, err := logr.FromContext(context.Background()) - Expect(err).ToNot(HaveOccurred()) - // context variables - portRegistry, err := NewPortRegistry(mpsv1alpha1.GameServerList{}, 20000, 20010, log) - Expect(err).ToNot(HaveOccurred()) - registeredPorts := make([]int32, 7) - assignedPorts := make(map[int32]bool) - - It("should allocate hostPorts when creating game servers", func() { - - // get 4 ports - for i := 0; i < 4; i++ { - port, err := portRegistry.GetNewPort() - Expect(err).ToNot(HaveOccurred()) - if _, ok := assignedPorts[port]; ok { - Fail(fmt.Sprintf("Port %d should not be in the assignedPorts map", port)) - } - assignedPorts[port] = true + log := logr.FromContextOrDiscard(context.Background()) + portRegistry, err := NewPortRegistry(mpsv1alpha1.GameServerList{}, 20000, 20010, log) + Expect(err).ToNot(HaveOccurred()) + registeredPorts := make([]int32, 7) + assignedPorts := make(map[int32]bool) + + It("should allocate hostPorts when creating game servers", func() { + // get 4 ports + for i := 0; i < 4; i++ { + port, err := portRegistry.GetNewPort() + Expect(err).ToNot(HaveOccurred()) + if _, ok := assignedPorts[port]; ok { + Fail(fmt.Sprintf("Port %d should not be in the assignedPorts map", port)) } + assignedPorts[port] = true + } - verifyAssignedHostPorts(portRegistry, assignedPorts) - verifyUnassignedHostPorts(portRegistry, assignedPorts) + verifyAssignedHostPorts(portRegistry, assignedPorts) + verifyUnassignedHostPorts(portRegistry, assignedPorts) - if displayPortRegistryVariablesDuringTesting { - portRegistry.displayRegistry() - } + if displayPortRegistryVariablesDuringTesting { + portRegistry.displayRegistry() + } - go portRegistry.portProducer() - // end of initialization - }) - It("should allocate more ports", func() { - for i := 0; i < 7; i++ { - peekPort, err := peekNextPort(portRegistry) - actualPort, _ := portRegistry.GetNewPort() - Expect(actualPort).To(BeIdenticalTo(peekPort), fmt.Sprintf("Wrong port returned, peekPort:%d, actualPort:%d", peekPort, actualPort)) - Expect(err).ToNot(HaveOccurred()) + go portRegistry.portProducer() + // end of initialization + }) + It("should allocate more ports", func() { + for i := 0; i < 7; i++ { + peekPort, err := peekNextPort(portRegistry) + actualPort, _ := portRegistry.GetNewPort() + Expect(actualPort).To(BeIdenticalTo(peekPort), fmt.Sprintf("Wrong port returned, peekPort:%d, actualPort:%d", peekPort, actualPort)) + Expect(err).ToNot(HaveOccurred()) - registeredPorts[i] = actualPort + registeredPorts[i] = actualPort - assignedPorts[actualPort] = true + assignedPorts[actualPort] = true - verifyAssignedHostPorts(portRegistry, assignedPorts) - verifyUnassignedHostPorts(portRegistry, assignedPorts) - } + verifyAssignedHostPorts(portRegistry, assignedPorts) + verifyUnassignedHostPorts(portRegistry, assignedPorts) + } - if displayPortRegistryVariablesDuringTesting { - portRegistry.displayRegistry() - } - }) + if displayPortRegistryVariablesDuringTesting { + portRegistry.displayRegistry() + } + }) - It("should return an error when we have exceeded the number of allocated ports", func() { - _, err = peekNextPort(portRegistry) - if err == nil { - Expect(err).To(HaveOccurred()) - } + It("should return an error when we have exceeded the number of allocated ports", func() { + _, err := peekNextPort(portRegistry) + if err == nil { + Expect(err).To(HaveOccurred()) + } - _, err = portRegistry.GetNewPort() - if err == nil { - Expect(err).To(HaveOccurred()) - } + _, err = portRegistry.GetNewPort() + if err == nil { + Expect(err).To(HaveOccurred()) + } - if displayPortRegistryVariablesDuringTesting { - portRegistry.displayRegistry() - } - }) - It("should successfully deallocate ports", func() { - portRegistry.DeregisterServerPorts(registeredPorts) + if displayPortRegistryVariablesDuringTesting { + portRegistry.displayRegistry() + } + }) + It("should successfully deallocate ports", func() { + portRegistry.DeregisterServerPorts(registeredPorts) - for _, val := range registeredPorts { - delete(assignedPorts, val) - } + for _, val := range registeredPorts { + delete(assignedPorts, val) + } - if displayPortRegistryVariablesDuringTesting { - portRegistry.displayRegistry() - } + if displayPortRegistryVariablesDuringTesting { + portRegistry.displayRegistry() + } - verifyAssignedHostPorts(portRegistry, assignedPorts) - verifyUnassignedHostPorts(portRegistry, assignedPorts) - }) - It("should return another port", func() { + verifyAssignedHostPorts(portRegistry, assignedPorts) + verifyUnassignedHostPorts(portRegistry, assignedPorts) + }) + It("should return another port", func() { - peekPort, err := peekNextPort(portRegistry) - actualPort, _ := portRegistry.GetNewPort() - Expect(actualPort).To(BeNumerically("==", peekPort), fmt.Sprintf("Wrong port returned, peekPort:%d,actualPort:%d", peekPort, actualPort)) - Expect(err).ToNot(HaveOccurred()) + peekPort, err := peekNextPort(portRegistry) + actualPort, _ := portRegistry.GetNewPort() + Expect(actualPort).To(BeNumerically("==", peekPort), fmt.Sprintf("Wrong port returned, peekPort:%d,actualPort:%d", peekPort, actualPort)) + Expect(err).ToNot(HaveOccurred()) - assignedPorts[actualPort] = true + assignedPorts[actualPort] = true - verifyAssignedHostPorts(portRegistry, assignedPorts) - verifyUnassignedHostPorts(portRegistry, assignedPorts) + verifyAssignedHostPorts(portRegistry, assignedPorts) + verifyUnassignedHostPorts(portRegistry, assignedPorts) - if displayPortRegistryVariablesDuringTesting { - portRegistry.displayRegistry() - } + if displayPortRegistryVariablesDuringTesting { + portRegistry.displayRegistry() + } - portRegistry.Stop() - }) + portRegistry.Stop() }) }) diff --git a/pkg/operator/controllers/suite_test.go b/pkg/operator/controllers/suite_test.go index 8e849a87..caeb2e46 100644 --- a/pkg/operator/controllers/suite_test.go +++ b/pkg/operator/controllers/suite_test.go @@ -21,7 +21,7 @@ import ( "path/filepath" "testing" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "k8s.io/client-go/kubernetes/scheme" ctrl "sigs.k8s.io/controller-runtime" @@ -94,7 +94,7 @@ var _ = BeforeSuite(func() { Expect(err).ToNot(HaveOccurred()) }() -}, 60) +}) var _ = AfterSuite(func() { By("tearing down the test environment") diff --git a/pkg/operator/controllers/utilities_test.go b/pkg/operator/controllers/utilities_test.go index c01c4165..fdc4c3bc 100644 --- a/pkg/operator/controllers/utilities_test.go +++ b/pkg/operator/controllers/utilities_test.go @@ -7,7 +7,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/pkg/operator/http/allocate_test.go b/pkg/operator/http/allocate_test.go index dfe1749b..ce87b2e4 100644 --- a/pkg/operator/http/allocate_test.go +++ b/pkg/operator/http/allocate_test.go @@ -10,7 +10,7 @@ import ( "net/http/httptest" "testing" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" mpsv1alpha1 "github.com/playfab/thundernetes/pkg/operator/api/v1alpha1" "github.com/playfab/thundernetes/pkg/operator/controllers" diff --git a/pkg/operator/http/types_test.go b/pkg/operator/http/types_test.go index a8235179..423706e9 100644 --- a/pkg/operator/http/types_test.go +++ b/pkg/operator/http/types_test.go @@ -1,7 +1,7 @@ package http import ( - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" )