Questions tagged [go-testing]

121 questions
1
vote
1 answer

Run before ALL integration tests

Does Go have any ability to run some code before ALL tests? I know that Go provides with TestMain(), but its package scope func, and will set up and tear down only tests in package where she located. But I want to run some docker test containers…
Vadziec Poplavsky
  • 709
  • 1
  • 6
  • 12
0
votes
1 answer

Issue with executing tests for main function in Go

I wrote this test a few months back and it was running successfully without any error and never went through init() function as I have only invoked handler function from test but now it's failing with below error: /usr/local/opt/go/libexec/bin/go…
SamD
  • 185
  • 5
  • 22
0
votes
1 answer

How to use gomock to make a mocked function return different results on subsequent calls?

I am using gomock to mock an http function that is called within the function under test. While it works great for one call it seems to call the first function again when I want to return a different result on the second call (see code below). The…
124141251
  • 31
  • 5
0
votes
1 answer

How to write unit test when a member function is calling another member function of the same object in golang?

In golang, I often see a member function calling another member function of the same object. For example check following golang code: type Obj struct{} func (o Obj) First() { // do something o.Second() } func (o Obj) Second() { // do…
Vikas Kaushik
  • 369
  • 2
  • 9
0
votes
1 answer

How to tell gazelle that a go file is meant for go_default_test and not go_default_library?

I have a file, embed_testdata.go, meant to be used in tests but does not itself have tests (so I don't want to suffix it with _test.go). How do I tell gazelle that it's really test source and not prod source? FYI, simply adding it to go_default_test…
Noel Yap
  • 18,822
  • 21
  • 92
  • 144
0
votes
0 answers

Is there anyway to debug "go test -msan" command?

I've recently looking for any way to debug "go test -msan". I am facing with a core-dump (Segmentation Fault) when pipeline executing this command and I need more detailed background informations about what is going on. So, I need to a way to debug…
alimertkoc
  • 13
  • 2
0
votes
1 answer

Temporary filesystem only visible to the process in Go

I am writing e2e tests for a command line app where I have to do file manipulation (such as cp, mv, rm, touch, and mkdir). The tests can execute just fine in my local environment. The problem occurs when they are executed on the server across…
cxc
  • 201
  • 2
  • 10
0
votes
0 answers

Permission denied when running Go shell script in Github Actions

I have a Go project which creates an endpoint, to consume system information like CPU temps and clock speed etc. (For debian based distros) I am able to build and test the project successfully in my local environment. In Github Actions the tests…
0
votes
0 answers

go tests error "Request validation failed"

I'm getting a request validation failed when running a test in golang but not when running the code: {"error":"Request validation…
X T
  • 445
  • 6
  • 22
0
votes
1 answer

Function like assert.Contains by stretchr/testify but ignore case and whitespace

For example, I have this test here assert.Contains(t, "HELLO WORLD", "hello world) and I want this to return true. Obviously, I can clean up the string with strings.TrimSpace(), strings.ReplaceAll(), and strings.ToLower() beforehand. Although…
cxc
  • 201
  • 2
  • 10
0
votes
0 answers

Same file needed for multiple packages in GoLang

I am using this method here to collect the code coverage for my system tests. The overall idea is that I need a dummy test so that I can generate an executable that calls the main() in the package. As a result, I have a file like the following in…
cxc
  • 201
  • 2
  • 10
0
votes
2 answers

`go test` fails because it cannot read files in root dir

package model is imports package config which reads config.xml in it's init When running test; I get an error complaining it cannot read the file. I've checked the file does exists and I can run my application(read the config file) Does golang test…
capsci
  • 65
  • 1
  • 5
0
votes
2 answers

go assertion utility functions behave like non-blocking operation

I expected that each assertion is a blocking operation and test would stop at a point as soon as it detects a failure. But it didn't happened. How go tool can smell upcoming failures and inform me ? AFAIK, assertion's methods are all blocking, it…
nevzatseferoglu
  • 988
  • 7
  • 18
0
votes
1 answer

Building go tests from multiple packages into single file

Is there any way to build all the test files in a project located inside multiple packages into a single binary file? To build binary inside a single package, I could use go test -c. I need something like go test ./... -c,but this returns "cannot…
0
votes
1 answer

go testing outputs wrong case names in json format under parallel mode

go version: 1.18.1 suppose i wrote this test file parallel_test.go package parallel_json_output import ( "fmt" "testing" "time" ) func TestP(t *testing.T) { t.Run("a", func(t *testing.T) { t.Parallel() for i := 0; i…
Rainy Chan
  • 109
  • 7
1 2 3
8 9