Build test tag real life example

49 views
Skip to first unread message

sbezverk

unread,
Oct 4, 2023, 4:00:25 AM10/4/23
to golan...@googlegroups.com

Hello,

 

I saw there was some debates about having “test build tag” here: https://github.com/golang/go/issues/21360  and people were asking about real life scenario. Here is one with CGO code, initially I was planning to add stubs for C land calls into blah_test.go file. (I do not need to test C land calls, I just need them to return 0) It turned  out, CGO is not supported in go unit tests. I had no other choice but to add these stubs into a normal go file, so unit test now is happy. It links locally defined stubs into a test binary. The problem now is with a production build where these stubs must be ignored and real C land calls from shared library should be invoked.  Having build test tag would be really useful, as I could exclude from the production build locally defined stubs and life is good.

 

The unit tests are for the library code, I do not know how to tell “go build -a ./…” when building  the client of the library binary to exclude locally defined stubs file.

 

Greatly appreciate some ideas on how to solve it.

 

Thank you

Serguei

 

 

Reply all
Reply to author
Forward
0 new messages