question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

go_unittest cannot depend on non go_library() target

See original GitHub issue

I am trying to build a golang unittest that depends on a non go_library target. I need the side effects of the target to run. I see the error:

BUILD FAILED: //:generated_asset (needed for //:main#compile,darwin_amd64) is not an instance of go_library!

Is this just a missing feature of the golang support in buck? Is there another way to create a manual dependency between a golang targets and something else that does not imply the golang target should link the targeted thing as if it were a go library?

Note, I have create a sample project demonstrating the issue: https://github.com/lloyd/buckissue

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mkaczanowskicommented, Apr 3, 2018

It can but only for go_test. Buck will symlink the output to current directory while running buck test, for example:

...
go_test_link_tree @ buck-out/gen/buckissue/__test_main_test_output__/working_dir
go test
...

so the asset can be referenced within current directory. However this is only during buck test execution, so if you try to run:

./buck-out/gen/buckissue/main_test#test-main/main_test -test.v

it won’t find the file.

Let’s say we add “resources” to go_binary then we could mimic the go_test behavior with:

$ buck run ... 

which would change the working directory

1reaction
kageiitcommented, Apr 2, 2018

Legit 😃

screen shot 2018-04-02 at 4 29 24 pm
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to test Go program that involves ... - GitHub
Within a Bazel workspace with dependencies managed by Gazelle, and a program that depends upon the google.golang.org/grpc Go module at version " ...
Read more >
Go unit test not finding required file - Stack Overflow
The problem that I am having is that when I run the test the package of the test is the root directory which...
Read more >
testing - Go Packages
When TestMain is called, flag.Parse has not been run. If TestMain depends on command-line flags, including those of the testing package, it should...
Read more >
Building a Go project using Bazel - Tweag
The target's name is blockchain , and it builds a library from the Go sources listed. The import path tells us how another...
Read more >
Outsmarting Go Dependencies in Testing Code
But tests in the sql package cannot depend on the server package because that creates a circular dependency. This problem is not specific...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found