Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TT-10430: add integration tests for mserv and mservctl #46

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 35 additions & 10 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
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
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# Binaries/objects
bin/
mserv
mservctl
*.so

# Makefile things
/out/
/tmp/

# macOS
.DS_Store

Expand All @@ -18,6 +15,7 @@ files/mserv-plugin-*
hack
mserv.json
plugins
integration/outputs/

# IDE resources
.idea
44 changes: 21 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -17,21 +17,14 @@ 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:
> @grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| 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)

Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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
4 changes: 4 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 45 additions & 0 deletions integration/integration.yaml
Original file line number Diff line number Diff line change
@@ -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.
Loading