-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Add busted unit testing framework for lua code #2379
Conversation
/assign @bowei |
e85f28c
to
2b66965
Compare
Codecov Report
@@ Coverage Diff @@
## master #2379 +/- ##
==========================================
+ Coverage 40.72% 40.91% +0.19%
==========================================
Files 74 74
Lines 5228 5252 +24
==========================================
+ Hits 2129 2149 +20
- Misses 2807 2809 +2
- Partials 292 294 +2
Continue to review full report at Codecov.
|
/assign @ElvinEfendi |
@zrdaley why did bindata change? |
@ElvinEfendi it seems like all lua changes require bindata to be updated? Or at least anytime new files/directories are added. In this case adding |
yeah looks like any update under |
/approve |
This is required to avoid polluting the filesystem when we run the tests. Before go-bindata it was required to run as root |
docs/development.md
Outdated
$ 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we enforce _test
pattern rather than -test
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately no. Initially this is the pattern I used. However, this causes errors because these files are converted to go source code in the bindata.go file and underscores are not allowed in go naming convention. It was causing the ./hack/verify-gofmt.sh
test to fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, are you sure? Looking at https://github.com/kubernetes/ingress-nginx/blob/master/hack/verify-gofmt.sh#L32 bindata.go
should not be checked by ./hack/verify-gofmt.sh
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and that's the problem. go-bindata
creates functions for each converted lua file in bindata.go (https://github.com/Shopify/ingress/blob/2b6696573c77a32cc3f4ba3f333e39b5bd746bbd/internal/file/bindata.go#L170). So lua files here can't be named with underscores in them or it will create a go function with an underscore which isn't allowed by the formatter.
3369700
to
382f7ae
Compare
hack/verify-golint.sh
Outdated
@@ -23,7 +23,7 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. | |||
cd "${KUBE_ROOT}" | |||
|
|||
GOLINT=${GOLINT:-"golint"} | |||
PACKAGES=($(go list ./... | grep -v /vendor/)) | |||
PACKAGES=($(find . -type f -name "*.go" | grep -v -E '(vendor/|internal/file/bindata.go)')) | |||
bad_files=() | |||
for package in "${PACKAGES[@]}"; do | |||
out=$("${GOLINT}" -min_confidence=0.9 "${package}" | grep -v 'should not use dot imports' || :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zrdaley you could just do something like following?
out=$("${GOLINT}" -min_confidence=0.9 "${package}" | grep -v '(should not use dot imports|internal/file/bindata.go)' || :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is not too different than your fix, but with your changes the variable name PACKAGES
is not correct anymore
/approve |
@zrdaley please rebase |
@ElvinEfendi add your lgtm when you think this is ready to go |
waiting for the rebase |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: aledbf, ElvinEfendi, zrdaley The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What this PR does / why we need it:
Currently Lua code is only tested through e2e tests and no unit tests exist.
This adds busted as a unit testing framework for Lua code and adds documentation within the developer guide.
Which issue this PR fixes: N/A