From 30a58fb7a0c69cdb6cbb2e527deb8a02dee506c4 Mon Sep 17 00:00:00 2001 From: Mitja Zivkovic <10356476+mitjaziv@users.noreply.github.com> Date: Mon, 13 Nov 2023 20:27:16 +0100 Subject: [PATCH] TT-10430: add integration tests for mserv and mservctl --- .github/workflows/test.yaml | 45 ++++++++++++++++++++++++++++-------- .gitignore | 6 ++--- Makefile | 44 +++++++++++++++++------------------ docker-compose.yaml | 4 ++++ integration/integration.yaml | 45 ++++++++++++++++++++++++++++++++++++ 5 files changed, 107 insertions(+), 37 deletions(-) create mode 100644 integration/integration.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 9422a4dd..629d8b62 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -8,21 +8,46 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Setup Go ${{ matrix.go-version }} + + - name: Setup Go uses: actions/setup-go@v4 with: - go-version: '1.15.x' + go-version: '1.20.x' + + - name: Setup Golang caches + uses: actions/cache@v3 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-golang-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-golang- - name: Test run: make test - - name: Lint - run: make lint + # - name: Lint + # run: make lint + + - name: Build server and client + run: make build + + - name: Cache Docker images. + uses: ScribeMD/docker-cache@0.3.6 + with: + key: docker-${{ runner.os }}-${{ hashFiles('docker-compose.yaml') }} + + - name: Start Docker Compose with MongoDB and Tyk Mserv + run: make start + + - name: Build and bundle plugins + run: | + make plugin + make bundles - - name: Build server - if: always() - run: make build-binary + - name: Install Venom command line tool + run: go install github.com/ovh/venom/cmd/venom@latest - - name: Build cli - if: always() - run: make build-cli + - name: Run Venom tests + run: make integration diff --git a/.gitignore b/.gitignore index 0baed960..22b8353b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,9 @@ # Binaries/objects +bin/ mserv mservctl *.so -# Makefile things -/out/ -/tmp/ - # macOS .DS_Store @@ -18,6 +15,7 @@ files/mserv-plugin-* hack mserv.json plugins +integration/outputs/ # IDE resources .idea diff --git a/Makefile b/Makefile index fe0db42a..13ce2c9c 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ SHELL := bash # Default - top level rule is what gets run when you run just `make` without specifying a goal/target. -.DEFAULT_GOAL := build +.DEFAULT_GOAL := help .DELETE_ON_ERROR: .ONESHELL: @@ -17,8 +17,7 @@ ifeq ($(origin .RECIPEPREFIX), undefined) endif .RECIPEPREFIX = > -binary_name ?= $(shell basename $(CURDIR)) -image_repository ?= tykio/$(binary_name) +image_repository ?= tykio/mserv # Adjust the width of the first column by changing the '16' value in the printf pattern. help: @@ -26,12 +25,6 @@ help: | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-16s\033[0m %s\n", $$1, $$2}' .PHONY: help -all: test lint build build-cli ## Test and lint and build. -build: out/image-id ## Build the mserv Docker image. Will also test and lint. -build-binary: $(binary_name) ## Build a bare binary only, without a Docker image wrapped around it. -build-cli: mservctl/mservctl ## Build the mservctl CLI binary. Will also test and lint. -.PHONY: all test lint build build-binary build-cli - check-swagger: > which swagger || (GO111MODULE=off go get -u github.com/go-swagger/go-swagger/cmd/swagger) @@ -48,7 +41,7 @@ swagger-client: check-swagger > swagger generate client -f ./doc/swagger.yaml -t ./mservclient clean: ## Clean up the temp and output directories, and any built binaries. This will cause everything to get rebuilt. -> rm -rf ./tmp ./out +> rm -rf ./bin > go clean > cd mservctl > go clean @@ -82,28 +75,27 @@ hack/bin/golangci-lint: > curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh \ > | sh -s -- -b $(shell pwd)/hack/bin -# Docker image - re-build if the lint output is re-run. -out/image-id: Dockerfile +docker: Dockerfile ## Builds mserv docker image. > mkdir -p $(@D) > image_id="$(image_repository):$(shell uuidgen)" > DOCKER_BUILDKIT=1 docker build --tag="$${image_id}" . -> echo "$${image_id}" > out/image-id -# Main server binary -$(binary_name): -> go build -mod=vendor +build: mserv mservctl ## Build server and client binary. +.PHONY: build + +mserv: +> go build -o bin/mserv -mod=vendor +.PHONY: mserv -# CLI binary - re-build if the lint output is re-run. -mservctl/mservctl: +mservctl: > cd mservctl -> go build -mod=vendor +> go build -o ../bin/mservctl -mod=vendor +.PHONY: mservctl -# Start runs development environment with mserv and mongo in docker-compose. -start: +start: ## Start runs development environment with mserv and mongo in docker-compose. > docker-compose up -d -# Stop runs development environment with mserv and mongo in docker-compose. -stop: +stop: ## Stop runs development environment with mserv and mongo in docker-compose. > docker-compose stop # Builds Go plugin and moves it into local Tyk instance. @@ -114,3 +106,9 @@ plugin: bundles: > docker-compose run --rm --workdir /plugin-source --entrypoint "/opt/tyk-gateway/tyk bundle build -y -o bundle.zip" tyk-gateway .PHONY: bundles + +integration: ## Runs integration test for mserv and mservctl it needs services running. +> cd integration +> venom run integration.yaml -vvv --output-dir outputs +> cd .. +.PHONY: integration diff --git a/docker-compose.yaml b/docker-compose.yaml index 5e13e907..90a1dabb 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -7,12 +7,16 @@ services: platform: linux/amd64 volumes: - ./bundles/simple:/plugin-source + networks: + - tyk tyk-gateway: image: tykio/tyk-gateway:${TYK_VERSION} platform: linux/amd64 volumes: - ./bundles/simple:/plugin-source + networks: + - tyk mongodb: image: mongo:4.0 diff --git a/integration/integration.yaml b/integration/integration.yaml new file mode 100644 index 00000000..25eb737b --- /dev/null +++ b/integration/integration.yaml @@ -0,0 +1,45 @@ +name: Integration tests for mserv and mservctl + +testcases: + - name: List + steps: + - script: ../bin/mservctl list -e http://localhost:8989 + assertions: + - result.code ShouldEqual 0 + - result.systemout MustContainSubstring "ID ACTIVE SERVE ONLY LAST UPDATE" + - result.systemout MustNotContainSubstring true # Should not have any other rows as header row. + - result.systemout MustNotContainSubstring false # Should not have any other rows as header row. + + - name: Push + steps: + - script: ../bin/mservctl push -e http://localhost:8989 ../bundles/simple/bundle.zip + assertions: + - result.code ShouldEqual 0 + - result.systemerr MustContainSubstring Middleware uploaded successfully, ID + vars: + bundle: + from: result.systemerr + regex: "Middleware uploaded successfully, ID: ([a-z0-9-]+)" + + - name: Fetch + steps: + - script: ../bin/mservctl fetch -e http://localhost:8989 {{.Push.bundle}} + assertions: + - result.code ShouldEqual 0 + - result.systemout MustContainSubstring {{.Push.bundle}} + + - name: Delete + steps: + - script: ../bin/mservctl delete -e http://localhost:8989 {{.Push.bundle}} + assertions: + - result.code ShouldEqual 0 + - result.systemerr MustContainSubstring "Middleware deleted successfully, ID" + + - name: List + steps: + - script: ../bin/mservctl list -e http://localhost:8989 + assertions: + - result.code ShouldEqual 0 + - result.systemout MustContainSubstring "ID ACTIVE SERVE ONLY LAST UPDATE" + - result.systemout MustNotContainSubstring true # Should not have any other rows as header row. + - result.systemout MustNotContainSubstring false # Should not have any other rows as header row.