Skip to content

go test fails because of global vars and init() #292

@larham

Description

@larham

Repro:

cd $GOPATH
mkdir MyTestGroup
cd MyTestGroup
operator-sdk new test --api-version MyTestGroup/v1alpha1 --kind MyTestKind
cd test/pkg/stub
echo "package stub_test" > handler_test.go
go test

output like:

panic: lookup kubernetes.default.svc: no such host

goroutine 1 [running]:
MyTestGroup/test/vendor/github.com/operator-framework/operator-sdk/pkg/k8sclient.mustNewKubeClientAndConfig(0x1012d68, 0x10, 0x1b69220)
	/Users/pivotal/go/src/MyTestGroup/test/vendor/github.com/operator-framework/operator-sdk/pkg/k8sclient/client.go:102 +0xc2
MyTestGroup/test/vendor/github.com/operator-framework/operator-sdk/pkg/k8sclient.init.0()
	/Users/pivotal/go/src/MyTestGroup/test/vendor/github.com/operator-framework/operator-sdk/pkg/k8sclient/client.go:43 +0x34
exit status 2
FAIL	MyTestGroup/test/pkg/stub	0.268s

This appears to be a result of global vars and init() causing an initialization of the k8sclient after the test system is run, and the test (an empty file) passes.

In other words, no test framework can work with the current implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions