Testing "internal" packages?

552 views
Skip to first unread message

Vaidotas Sm

unread,
Dec 20, 2016, 7:39:17 PM12/20/16
to golang-nuts
Hi,

Why do "go test ./..." does not run any ./internal/... tests?
This however works - "go test ./internal/...".

What is the correct way to test all my code within project with single command?

Dave Cheney

unread,
Dec 20, 2016, 7:53:54 PM12/20/16
to golang-nuts
Works for me, 

deadwood(~/src/github.com/davecheney/test) % go test -v ./...
=== RUN   TestTest
--- PASS: TestTest (0.00s)
        test_test.go:6: hello
PASS
ok      github.com/davecheney/test      0.002s
=== RUN   TestTest
--- PASS: TestTest (0.00s)
        test_test.go:6: hello
PASS

Can you please post some details of what you have tried and what happened.

Vaidotas Sm

unread,
Dec 21, 2016, 4:03:19 AM12/21/16
to golang-nuts
OK, so I have a project named golang_web_boilerplate in $GOPATH/src:


> go test ./...

# golang_web_boilerplate/db/migrations
runtime.main: call to external function main.main
runtime.main: main.main: not defined
runtime.main: undefined: main.main
?       golang_web_boilerplate  [no test files]


> go test ./internal/...

?       golang_web_boilerplate/internal/app/data        [no test files]
--- FAIL: TestXxx (0.00s)
        Error Trace:    server_test.go:7
        Error:          Not equal:
                        expected: 10
                        received: 12
        Messages:       AAA
        Error Trace:    server_test.go:8
        Error:          Not equal:
                        expected: 10
                        received: 14
        Messages:       BBB
FAIL
FAIL    golang_web_boilerplate/internal/app/web 0.920s
ok      golang_web_boilerplate/internal/app/web/restutils       0.552s


Dave Cheney

unread,
Dec 21, 2016, 4:09:27 AM12/21/16
to golang-nuts
I'd bet that something is wrong with your go install. Double check you have not set goroot, then delete your go install and start again from scratch.

Dave Cheney

unread,
Dec 21, 2016, 4:09:27 AM12/21/16
to golang-nuts

vaidotas...@gmail.com

unread,
Dec 21, 2016, 10:48:08 AM12/21/16
to golang-nuts
So what I find out was that I was using Goose Database migrations in Go code form (and so runtime.main warnings) - so tests were not run. If I remove migration code, everything works. Will investigate this more later today.
Reply all
Reply to author
Forward
0 new messages