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

go test: fails, when server.StartServer(...) is in main - violated testing rules #60

Closed
diefans opened this issue Mar 29, 2021 · 0 comments · Fixed by #64
Closed

go test: fails, when server.StartServer(...) is in main - violated testing rules #60

diefans opened this issue Mar 29, 2021 · 0 comments · Fixed by #64

Comments

@diefans
Copy link

diefans commented Mar 29, 2021

I want to integrate my plugin with the go-pdk server:

func main() {
	log.Info().Str("version", version).Msg("Starting pdk server")
	server.StartServer(New, version, 100)
}

If I run go test I get

flag provided but not defined: -test.paniconexit0
Usage of /tmp/go-build1002799689/b001/bm-authx.test:
  -dump
        Dump info about plugins
  -help
        Show usage info
  -kong-prefix string
        Kong prefix path (specified by the -p argument commonly used in the kong cli) (default
"/usr/local/kong")
exit status 2
FAIL    bm-authx        0.003s

After reading through docs at https://golang.org/doc/go1.13#testing

As a result, testing flags are now only registered when running a test binary, and packages that call flag.Parse during package initialization may cause tests to fail.

I think https://github.com/Kong/go-pdk/blob/master/server/server.go#L32 violates the testing rules for golang, e.g.:

func init() {
	flag.Parse()
	// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant