Skip to main content
Filter by
Sorted by
Tagged with
0 votes
2 answers
248 views

I'm using Go 1.24.3, installed via Homebrew on an Apple M1, running Sequoia 15.5. I have a main: //main.go package main import "fmt" func main() { fmt.Println("Hello, world!") }...
GKelly's user avatar
  • 3,949
0 votes
0 answers
117 views

Context I have a very simple, bare bones cloudbuild.yaml that: sets up GOPRIVATE variable so that the CI environment is able to download dependencies Runs go build Runs go test: steps: - id: "...
a3y3's user avatar
  • 1,255
0 votes
1 answer
140 views

I modified a function from a book I was reading, the function writes "ping" to a writer at a predefined interval. The program runs in a go routine so I appended a context so the function can ...
Dassy Areg's user avatar
0 votes
0 answers
56 views

TL;DR: Is there any known hack to capture and/or print additional context when a Golang test fails? (using standard library testing) Example: func TestSomething(t *testing.T) { ... ... if ... { ...
Marco's user avatar
  • 637
1 vote
2 answers
293 views

I have a program that calls a web service and I want to write a unit test that checks the correct failure handling (nothing fancy). I use net/http/httptest to simulate the web service (backend). But I ...
Thomas W.'s user avatar
  • 824
2 votes
2 answers
240 views

package main import "github.com/gocql/gocql" var CassandraSession *gocql.Session func getSelectQuery(ClientId, UID, UUID, tableName, selectColumns string, sess *gocql.Session) (*gocql....
Mesc's user avatar
  • 155
-1 votes
1 answer
69 views

I have a generator which generates me code in Go, for example: foo.go bar.go ... After generation, I need to test if my generator is doing good job. For every generated file, I have a test ...
GreyCat's user avatar
  • 17.3k
2 votes
2 answers
314 views

I recently started playing with go build -cover -o to collect the code coverage for integration test in Go 1.20. I used the textfmt to get the coverage, but looking at the text file, it has a local ...
cxc's user avatar
  • 263
-3 votes
1 answer
348 views

As far as I tested, go test -- <custom flag(s)> works but I couldn't find any documentation for it. I have this test code: package main import ( "os" "testing" ) ...
ynn's user avatar
  • 5,077
2 votes
1 answer
327 views

I want to test my oauth2 client and use a mock for TokenURL endpoint. The mock responds with access_token but there is always an error with missing access_token. I am using golang.org/x/oauth2 and ...
SebastianWi's user avatar
1 vote
0 answers
149 views

This is my test: // A test of TestSuite func (ts *TestSuite) TestMyThing() { cmd := RootCmd() b := bytes.NewBufferString("") cmd.SetOut(b) cmd.SetErr(b) err := cmd....
red888's user avatar
  • 32.3k
0 votes
1 answer
1k views

I have a go function called setupConfig() and I have a Test_setupconfig that tests it and tests it just fine. But when I do a cover test on it and look at the HTML report, it shows my handling of ...
Dan Sherwin's user avatar
4 votes
1 answer
5k views

I'm currently running a suite of tests in Go using the go test ./... command. This suite contains multiple test functions, and the execution time exceeds 10 minutes. Unfortunately, the go test command ...
Sruthi CP's user avatar
  • 452
0 votes
1 answer
491 views

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 ...
SamD's user avatar
  • 337
2 votes
1 answer
41 views

I am a Go newbie. I have written an API server built on the Echo server, using the DeepMap OpenAPI generator and Postgres using pgxpool. It is working well enough and has been in use for a year, but ...
Drew's user avatar
  • 121
1 vote
0 answers
66 views

How to create Unit test cases for “GetListOfUsers()” function of “UserService.go“ file. Facing issue in creating dummy aerospike.Recordset object this is the test file Sample testfile func (suite *...
A_Gour's user avatar
  • 21
2 votes
0 answers
611 views

I have a project in go lang, I can run tests and sonar can identify the total percentage of test coverage. But I want to know if I can generate any metrics in this coverage.out file that can show how ...
Murilo Alves's user avatar
2 votes
2 answers
815 views

Assume that some code defined under package pkg/somepkg1. And there are some tests in this package and some tests are in package tests/integration. If i call go test -cover -coverprofile=cover.out ./.....
comdiv's user avatar
  • 959
-1 votes
1 answer
156 views

I am having trouble testing foo_handler in my Go project. My project has the following structure: ├── Makefile ├── cmd │ └── main.go ├── go.mod ├── go.sum └── internal ├── api │ ├── router....
Dana 's user avatar
  • 57
1 vote
1 answer
157 views

Take a look at this directory structure: /root /hoge go.mod go.sum main.go /test main_test.go /unit sub_test.go /fuga ...
kyoshi's user avatar
  • 31
1 vote
1 answer
542 views

I was looking at some benchmark tests from https://github.com/RoaringBitmap/roaring When running a specific benchmark using -run - (as mentioned in there comments): go test -bench BenchmarkNexts -...
Chris's user avatar
  • 585
1 vote
1 answer
1k views

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 ...
124141251's user avatar
0 votes
1 answer
1k views

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 ...
Vikas Kaushik's user avatar
1 vote
1 answer
2k views

I'm using mysql transaction in my project, I want to know how to write unit test when using db transaction? for example: func SomeFunc() error { return db.Transaction(func(tx *gorm.DB) { // my ...
lee3164's user avatar
  • 19
1 vote
0 answers
65 views

Consider the following code: package ifaces import ( "fmt" "testing" ) type IFace1 interface { Do1() } type IFace2 interface { ...
caxcaxcoatl's user avatar
  • 9,040
0 votes
1 answer
1k views

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 ...
Noel Yap's user avatar
  • 19.9k
5 votes
1 answer
1k views

In my Go code, I have to use filepath.Abs() several times, which may lead to different errors that my method returns. func (s *service) myFunc(path string) error { dir := s.Component().Dir() ...
Apollo's user avatar
  • 1,908
2 votes
1 answer
202 views

While I'm reading how to test on k8s with the fake client on this link, I noticed this function, which, IIUC, assigns a faked server version to the faked k8s cluster. k8s.clientset.Discovery().(*...
Mike's user avatar
  • 1,897
2 votes
0 answers
564 views

I am trying to test a gRPC service locally. Here is the sample code type TestGrpcServer struct { t *testing.T Server *grpc.Server Lis *bufconn.Listener Conn *grpc.ClientConn }...
Sanath Manavarte's user avatar
2 votes
3 answers
215 views

I'm studying Go language and I have a question now. I was just testing buffered and unbuffered channels. While writing the test code for it, a situation occurred that I couldn't understand the result. ...
didnlie23's user avatar
  • 111
-1 votes
1 answer
3k views

I compiled a Go test library by running go test -c ./model. According to Go docs it can be run using go run -exec xprog command, however, I keep getting errors while trying to run my generated model....
mevoker659's user avatar
3 votes
1 answer
2k views

Consider the following test: import ( "errors" "fmt" "testing" ) func TestError(t *testing.T) { err := &MyError{} var target error fmt....
Sam Herrmann's user avatar
  • 7,026
0 votes
2 answers
2k views

I try to test function StartP, Expect that Start() should be called 1 times, Done() should be called 1 times but I have trouble that test will block when run this step <-ps.Done() I expect <-ps....
Y. Ryan's user avatar
  • 11
1 vote
0 answers
365 views

Is there a way to get the difference in coverage percentage? My goal is to fail a build when the coverage has decreased. I can easily get the current coverage percentage and compare it to a threshold ...
treesan's user avatar
  • 49
1 vote
0 answers
188 views

I'm running gotestsum --junitfile-testcase-classname=short --junitfile-testsuite-name=relative \ -- -coverprofile=coverage.out ./serviceName/... The structure looks like this: serviceName ...
treesan's user avatar
  • 49
1 vote
1 answer
2k views

I'm trying to write a test for a handler which receives a file. As part of such I'm trying to configure my context so the handler can use it. My intention is to create a file and use multipart....
user672009's user avatar
  • 4,655
5 votes
0 answers
474 views

I am using the -cover to collect coverage in my Go project. However, it seems that the tests have to be 100% success rate in order to get the coverage report. Is there any way I can get the coverage ...
cxc's user avatar
  • 263
1 vote
1 answer
126 views

I'm trying to understand the difference between handler.ServeHTTP(w,req) and handler(w,req) in Go testing. When should I use each of them? Are they exactly the same? Docs say simply: ServeHTTP calls f(...
mishkamashka's user avatar
1 vote
1 answer
90 views

Consider a multi binary project with the following structure. . ├── bin1 │   ├── config │   │   ├── config.go │   │   └── config_test.go │   └── utils │   ├── utils.go │   └── utils_test.go ├──...
kexic63212's user avatar
1 vote
0 answers
68 views

I have a package which does some error checking for specific error types. One of the errors is from an external package, its fields are all unexported as well as the relevant creation func, so I cant ...
Person1's user avatar
  • 149
1 vote
1 answer
705 views

I am new to golang, I have a task to collect the application logs, application is running as deployment in k8s cluster, there are 4 pods in total. As part of test automation, I need to collect the ...
Karthic.K's user avatar
  • 446
7 votes
2 answers
5k views

I need to calculate code coverage for golang project where source of tests will be integration tests written in Java language . This requires go build to be instrumented first and then run on server ...
Shreenivash's user avatar
1 vote
1 answer
181 views

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 ...
cxc's user avatar
  • 263
0 votes
0 answers
262 views

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 ...
Rafael Zasas's user avatar
1 vote
0 answers
360 views

I have many classes of test, which are marked with build constraints, e.g.: //go:build all || (!foo && !bar && !baz && quux) for the test class quux. This is okay, as far as ...
YoureIt's user avatar
  • 21
0 votes
0 answers
516 views

I'm getting a request validation failed when running a test in golang but not when running the code: {"error":"Request validation failed","validation":[{"keyword&...
X T's user avatar
  • 516
1 vote
1 answer
3k views

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(), ...
cxc's user avatar
  • 263
0 votes
0 answers
117 views

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 ...
cxc's user avatar
  • 263
7 votes
1 answer
7k views

I understand that in order to avoid cached results in Go tests you can use the -count=1 flag in the go test command, but why? This is from the docs: The idiomatic way to disable test caching ...
asaf92's user avatar
  • 1,901
4 votes
0 answers
526 views

I'm using VS Code for a Go project. I have it configured to show the code coverage with gutter markings after I run the tests. The issue I'm having is that if I make any changes to a file in the ...
Jordan's user avatar
  • 4,650