module dependency & testing

62 views
Skip to first unread message

Serhat Şevki Dinçer

unread,
Oct 25, 2019, 2:33:53 AM10/25/19
to golang-nuts
Hi,

Say you have a project with:
- hard dependencies
- some extra dependencies only used during testing, not needed otherwise

Are they treated equally? When you switch to go modules, does the second group become hard dependencies? It seems like they do.

Cody Oss

unread,
Oct 25, 2019, 7:49:21 PM10/25/19
to golang-nuts
A dependency is a dependency. There are no scopes like you might find in Maven(Java) land. Your project needs these "test deps" to run your tests, so they are in your module file. Even so, Go is smart enough when it builds your binary to not include the extra bloat.

t hepudds

unread,
Oct 25, 2019, 8:00:52 PM10/25/19
to golang-nuts
To show the exact versions used in your build excluding test-only dependencies, I think this works:

go list -deps -f '{{with .Module}}{{.Path}} {{.Version}}{{end}}' ./... | sort -u

(Command originally from Bryan Mills).

Regards,
thepudds

Serhat Sevki Dincer

unread,
Oct 26, 2019, 8:23:28 AM10/26/19
to Cody Oss, golang-nuts
There is an important distinction:
- users of your project / library are interested in hard dependencies of it
- developers / testers of your library will actually be using its test dependencies

Go modules enforces the first group your test dependencies as hard dependencies, which is not right.

26 Eki 2019 Cmt 02:49 tarihinde Cody Oss <the.co...@gmail.com> şunu yazdı:
A dependency is a dependency. There are no scopes like you might find in Maven(Java) land. Your project needs these "test deps" to run your tests, so they are in your module file. Even so, Go is smart enough when it builds your binary to not include the extra bloat.

--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/4kldLhXlfAU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/6269fe14-6708-48e9-ad98-62b2aadd3866%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages