Skip to content
This repository has been archived by the owner on Apr 27, 2021. It is now read-only.

Add busted unit testing framework for lua code #49

Closed
wants to merge 10 commits into from
Closed
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
1 change: 1 addition & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
std = 'ngx_lua'
globals = {'_'}
exclude_files = {'./rootfs/etc/nginx/lua/test/*.lua'}
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ env:
- DOCKER=docker
- TRAVIS_TIMEOUT=240
- TAG=0.13.0-rc.1
- BUSTEDVERSION=2.0.rc12

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at the above constants the convention is to split the words with _ so BUSTED_VERSION

- secure: LIS2XpZufWTcJ53jiRsSZy2Gi1EUJ1XmLg7z3f2ZHeMnyG2Jhk3GW4vod1FNru+PY4PWgddLdCdIl+jqOYXndFlbdAWF3/Oy5fEkYLXdYV7tdlHcPWDkqNFrfiyZ4guChN+b2Nk6FqU7o5fsZAIR7VAbgqNRF5XMo9Mhn/vhDCQRcnbXy7uq7JTrYUkqDbQoyYvT6b480GCY5gags1zp/xZfPDNZEe936o8i5IPTyiykRyNOXN/AH6kd3pR5e1xYgcvJ9KpSVPghcwFE7kJ4fOVMRhRG5ML+IyML+xD0jX43EMNoqRKZ/HS42kIMCInFbJEcxVde7DPNBZ7Y3GAqh7HO6qrE70Dn3ha6DID6zCoH2ArW39BxG4zempjn2VxYoMRGREyZszWQb++dwGoHmo5FHt6zvIrYBG0dA0H8ja9VkZkjFwtYTGHU1ooPzUfJK4O4VBayV8LqZibyZQR+GrmyQc0aagUY7J/fe4A2PJyI4DbkeZ7GX1ELj0ciDz4urQSzUc8l/T3aU3X+FuJItjgYtMLPmqcjA5uifDCtutE8Z9L2gSpanqU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5AQgRAhG8i7rNKfghqX8OccKNWUhvFB3eOFFf4dlb02IA2L/b8Fl4NnZpyAWcwF+CBZrzQoFARBE1xIvGfaNa9i6noyrpJ/g+0g7EyKgTsixaQInBmZ7ECVpQkSO+/3leWfwssZs7H4cqy2HeXH6dkE+JUeI0WDjYV7YwdVNoFm8wXszDu+MCQTGXJ4moO4F/jMvY4w+tNo8ISJiNZ/+uQaIlPaijCdwu9FPvAY59lJXORGVHd1Fq2pKkGkNjQVHtu9BH7ufO1fX5a6FtYbclMwm7w9BE5jnJNoP+y8Yq0bVwbGONSUFTyMWCbSCYDsyUPzmaZLkFpZPbnJua5y9c1x0/OYijNizBW0UVQDZauortsTPzwYlZ1J7TywVtpUEoI8CGuUb2QEWh+O/IwrogtiKvFtPrrYakIwV/lr7mO294=
Expand All @@ -43,6 +44,11 @@ jobs:
- go get github.com/golang/lint/golint
- go get -u github.com/jteeuwen/go-bindata/...
- make verify-all-verbose
- stage: Lua Unit Test
before_script:
- rootfs/etc/nginx/lua/test/up.sh
script:
- make lua-test
- stage: Coverage
before_script:
# start minikube
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ ALL_ARCH = amd64 arm arm64 ppc64le s390x

QEMUVERSION=v2.9.1-1

BUSTED_ARGS=-v --pattern=_test

IMGNAME = nginx-ingress-controller
IMAGE = $(REGISTRY)/$(IMGNAME)
MULTI_ARCH_IMG = $(IMAGE)-$(ARCH)
Expand Down Expand Up @@ -155,6 +157,10 @@ verify-all:
test:
@go test -v -race -tags "$(BUILDTAGS) cgo" $(shell go list ${PKG}/... | grep -v vendor | grep -v '/test/e2e')

.PHONY: lua-test
lua-test:
@busted $(BUSTED_ARGS) ./rootfs/etc/nginx/lua/test;

.PHONY: e2e-image
e2e-image: sub-container-amd64
TAG=$(TAG) IMAGE=$(MULTI_ARCH_IMG) docker tag $(IMAGE):$(TAG) $(IMAGE):test
Expand Down
10 changes: 10 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ $ cd $GOPATH/src/k8s.io/ingress-nginx
$ make e2e-test
```

To run unit-tests for lua code locally, run:

```console
$ cd $GOPATH/src/k8s.io/ingress-nginx
$ ./rootfs/etc/nginx/lua/test/up.sh
$ make lua-test
```

Lua tests are located in `$GOPATH/src/k8s.io/ingress-nginx/rootfs/etc/nginx/lua/test`. When creating a new test file it must follow the naming convention `<mytest>_test.lua` or it will be ignored.

## Releasing

All Makefiles will produce a release binary, as shown above. To publish this
Expand Down
2 changes: 2 additions & 0 deletions rootfs/etc/nginx/lua/test/balancer_test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
describe("[balancer_test]", function()
end)
8 changes: 8 additions & 0 deletions rootfs/etc/nginx/lua/test/up.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

if luarocks list --porcelain busted $BUSTEDVERSION | grep -q "installed"; then
echo busted already installed, skipping ;
else
echo busted not found, installing via luarocks...;
sudo luarocks install busted $BUSTEDVERSION;
fi