[BUG] go vet fails with undeclared name error
Ayush21298 opened this issue · comments
Describe the bug
A clear and concise description of what the bug is.
go vet
throws following error when run in the root directory of source code.
whereabouts$ go vet ./...
# github.com/k8snetworkplumbingwg/whereabouts/pkg/controlloop
vet: pkg/controlloop/pod_controller_test.go:72:10: undeclared name: podSpec
Expected behavior
A clear and concise description of what you expected to happen.
go vet
should throw no error
To Reproduce
Steps to reproduce the behavior:
git clone https://github.com/k8snetworkplumbingwg/whereabouts
- Run
go vet ./...
Environment:
- Skipping it as it is not a functional error
Additional info / context
Add any other information / context about the problem here.
- go version go1.18 linux/amd64
You just have to pass the test tags via CLI - go vet --tags=test ./...
, as our CI is doing.
You just have to pass the test tags via CLI -
go vet --tags=test ./...
, as our CI is doing.
But shouldn't all the test related files have +build test
tag ? 🤔
the tests ? Why would you put the tests in a binary ?
Actually pod_control_test.go
requires podSpec
here
This is defined in entity_generator.go
here
whereabouts/pkg/controlloop/entity_generators.go
Lines 53 to 60 in acddfd5
But entity_generator.go
has build flags
whereabouts/pkg/controlloop/entity_generators.go
Lines 1 to 3 in acddfd5
Because of this the issue happens.
You just have to pass the test tags via CLI -
go vet --tags=test ./...
, as our CI is doing.But shouldn't all the test related files have
+build test
tag ? thinking
I suggested this because I think pod_control_test.go
should not be included in the binary until and unless test
tag is present.
@maiqueb What do you think ? ^^
I think I don't understand what you mean; pod_control_test.go
- along with anything not reachable from the main entrypoint of either the pod controller or the CNI plugin - will not be present in the binary, hence, there is no need to tag it.
Continuing from the call, yes I agree it will be better to remove the tags from the files which don't require tags :)
I was just concern that all the go vet
with and without tag should pass independently (all the dependent files should either have tags or don't i.e. kind of independent sets ) :)