diff --git a/build/build-sdk-images/restapi/Dockerfile b/build/build-sdk-images/restapi/Dockerfile new file mode 100644 index 0000000000..2264434eeb --- /dev/null +++ b/build/build-sdk-images/restapi/Dockerfile @@ -0,0 +1,39 @@ +# Copyright 2019 Google LLC All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +ARG BASE_IMAGE=agones-build-sdk-base:latest +FROM $BASE_IMAGE + +RUN apt-get update && \ + apt-get install -y wget jq && \ + apt-get clean + +# install go +WORKDIR /usr/local +ENV GO_VERSION=1.12 +ENV GO111MODULE=on +ENV GOPATH /go +RUN wget -q https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz && \ + tar -xzf go${GO_VERSION}.linux-amd64.tar.gz && rm go${GO_VERSION}.linux-amd64.tar.gz && mkdir -p ${GOPATH} + +RUN curl -sL https://deb.nodesource.com/setup_11.x | bash - && \ + apt-get install -y nodejs + +RUN apt-get install -y openjdk-8-jre + +ENV PATH /usr/local/go/bin:/go/bin:$PATH + + +# code generation scripts +COPY *.sh /root/ +RUN chmod +x /root/*.sh \ No newline at end of file diff --git a/build/build-sdk-images/restapi/build-sdk-test.sh b/build/build-sdk-images/restapi/build-sdk-test.sh new file mode 100644 index 0000000000..60ae31154a --- /dev/null +++ b/build/build-sdk-images/restapi/build-sdk-test.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# Copyright 2019 Google LLC All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +mkdir /go/src/agones.dev/agones/swagger +wget -q http://central.maven.org/maven2/io/swagger/swagger-codegen-cli/2.4.8/swagger-codegen-cli-2.4.8.jar -O /tmp/swagger-codegen-cli.jar +java -jar /tmp/swagger-codegen-cli.jar generate -i /go/src/agones.dev/agones/sdk.swagger.json -l go -o /go/src/agones.dev/agones/test/sdk/restapi/swagger \ No newline at end of file diff --git a/build/build-sdk-images/restapi/clean.sh b/build/build-sdk-images/restapi/clean.sh new file mode 100644 index 0000000000..a9f326579c --- /dev/null +++ b/build/build-sdk-images/restapi/clean.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +# Copyright 2019 Google LLC All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -ex +rm -rf /go/src/agones.dev/agones/test/sdk/restapi/swagger +rm /go/src/agones.dev/agones/test/sdk/restapi/http-api-test.go diff --git a/build/build-sdk-images/restapi/sdktest.sh b/build/build-sdk-images/restapi/sdktest.sh new file mode 100644 index 0000000000..42cf5e7b0c --- /dev/null +++ b/build/build-sdk-images/restapi/sdktest.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +# Copyright 2019 Google LLC All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -ex +GO111MODULE=on +cd /go/src/agones.dev/agones/test/sdk/restapi +cp ./http-api-test.go.nolint ./http-api-test.go +go run http-api-test.go \ No newline at end of file diff --git a/build/includes/sdk.mk b/build/includes/sdk.mk index 7bf1d437f0..444d863fd3 100644 --- a/build/includes/sdk.mk +++ b/build/includes/sdk.mk @@ -116,9 +116,9 @@ ensure-build-sdk-image: # Run SDK conformance Sidecar server in docker in order to run # SDK client test against it. Useful for test development run-sdk-conformance-local: TIMEOUT ?= 30 -run-sdk-conformance-local: TESTS ?= ready,allocate,setlabel,setannotation,gameserver,health,shutdown,watch +run-sdk-conformance-local: TESTS ?= ready,allocate,setlabel,setannotation,gameserver,health,shutdown,watch,reserve run-sdk-conformance-local: ensure-agones-sdk-image - docker run -e "ADDRESS=" -p 59357:59357 \ + docker run -e "ADDRESS=" -p 59357:59357 -p 59358:59358 \ -e "TEST=$(TESTS)" -e "TIMEOUT=$(TIMEOUT)" $(sidecar_tag) # Run SDK conformance test, previously built, for a specific SDK_FOLDER @@ -130,7 +130,7 @@ run-sdk-conformance-no-build: TESTS ?= ready,allocate,setlabel,setannotation,gam run-sdk-conformance-no-build: ensure-agones-sdk-image run-sdk-conformance-no-build: ensure-build-sdk-image DOCKER_RUN_ARGS="--network=host $(DOCKER_RUN_ARGS)" COMMAND=sdktest $(MAKE) run-sdk-command & \ - docker run -p 59357:59357 -e "ADDRESS=" -e "TEST=$(TESTS)" -e "TIMEOUT=$(TIMEOUT)" -e "DELAY=$(DELAY)" \ + docker run -p 59357:59357 -p 59358:59358 -e "ADDRESS=" -e "TEST=$(TESTS)" -e "TIMEOUT=$(TIMEOUT)" -e "DELAY=$(DELAY)" \ --net=host $(sidecar_tag) # Run SDK conformance test for a specific SDK_FOLDER @@ -140,9 +140,11 @@ run-sdk-conformance-test: # Run a conformance test for all SDKs supported run-sdk-conformance-tests: + $(MAKE) run-sdk-conformance-test SDK_FOLDER=restapi $(MAKE) run-sdk-conformance-test SDK_FOLDER=node $(MAKE) run-sdk-conformance-test SDK_FOLDER=go $(MAKE) run-sdk-conformance-test SDK_FOLDER=rust + $(MAKE) run-sdk-command COMMAND=clean SDK_FOLDER=restapi # Clean package directories and binary files left # after building conformance tests for all SDKs supported diff --git a/test/sdk/restapi/http-api-test.go.nolint b/test/sdk/restapi/http-api-test.go.nolint new file mode 100644 index 0000000000..604ec57886 --- /dev/null +++ b/test/sdk/restapi/http-api-test.go.nolint @@ -0,0 +1,87 @@ +// Copyright 2019 Google LLC All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "fmt" + "log" + "time" + + "agones.dev/agones/test/sdk/restapi/swagger" + "golang.org/x/net/context" +) + +func main() { + log.Println("Client is starting") + time.Sleep(100 * time.Millisecond) + conf := swagger.NewConfiguration() + conf.BasePath = "http://localhost:59358" + cli := swagger.NewAPIClient(conf) + + ctx := context.Background() + uid := "" + go func() { + gs, _, err := cli.SDKApi.WatchGameServer(ctx) + if err != nil { + log.Fatalf("Error in WatchGameServer: %v\n", err) + } + uid = gs.ObjectMeta.Uid + }() + _, _, err := cli.SDKApi.Ready(ctx, swagger.SdkEmpty{}) + if err != nil { + log.Fatalf("Could not send Ready: %v\n", err) + } + + _, _, err = cli.SDKApi.Health(ctx, swagger.SdkEmpty{}) + if err != nil { + log.Fatalf("Could not GetGameserver: %v\n", err) + } + + _, _, err = cli.SDKApi.Reserve(ctx, swagger.SdkDuration{"5"}) + if err != nil { + log.Fatalf("Could not send Reserve: %v\n", err) + } + + _, _, err = cli.SDKApi.Allocate(ctx, swagger.SdkEmpty{}) + if err != nil { + log.Fatalf("Could not send Allocate: %v\n", err) + } + + gs, _, err := cli.SDKApi.GetGameServer(ctx) + if err != nil { + log.Fatalf("Could not GetGameserver: %v\n", err) + } + + creationTS := gs.ObjectMeta.CreationTimestamp + fmt.Println(creationTS) + + _, _, err = cli.SDKApi.SetLabel(ctx, swagger.SdkKeyValue{"creationTimestamp", creationTS}) + if err != nil { + log.Fatalf("Could not SetLabel: %v\n", err) + } + + time.Sleep(3 * time.Second) + uid = gs.ObjectMeta.Uid + _, _, err = cli.SDKApi.SetAnnotation(ctx, swagger.SdkKeyValue{"UID", uid}) + if err != nil { + log.Fatalf("Could not SetAnnotation: %v\n", err) + } + time.Sleep(1 * time.Second) + + _, _, err = cli.SDKApi.Shutdown(ctx, swagger.SdkEmpty{}) + if err != nil { + log.Fatalf("Could not GetGameserver: %v\n", err) + } +}