Skip to main content

All Questions

Tagged with
-3 votes
1 answer
38 views

Go: test fails when expected value is the same as got value [closed]

I'm learning to test http endpoints in Go with the httptest library and my test is failingeven though by the result it should pass. The function being tested: func testHandler(w http.ResponseWriter, r ...
Anacardo's user avatar
1 vote
1 answer
59 views

How to unit test for multipart.Form

I need to write tests for that function: func Parse(f *multipart.Form) ([]Person, error) It's important to say, that multipart.Form.Value is not just key:value, thats more complicated json, simple ...
kirin's user avatar
  • 31
-4 votes
2 answers
228 views

Test callbacks like beforeEach

I want to perform unit tests over a struct that I coded in golang. However I have repetitive tasks that I don't want to explicitly repeat manually every time. Still, I like to put them in a BeforeEach ...
Andrea Costanzo's user avatar
0 votes
0 answers
65 views

Mocking constructors in main func

I would like to find a better way to mock my constructor. The constructor itself already returns an interface, thanks to which I can mock its functions in tests. //main.go var createSSMClient = ssm....
Kepes's user avatar
  • 59
0 votes
0 answers
47 views

How to test multiple implementations of a common interface without duplicating the testcode in Go?

How would I streamline the following testing scenario in Go? Say I have some interface I with a corresponding implementation A and most of my tests for A basically look like: func TestSomething(t *...
raisyn's user avatar
  • 4,554
0 votes
1 answer
721 views

How to test for exit codes in go without exiting the testcase when the exit code is != 0

I'm trying to write a unit test in go for a function that returns non-zero exit codes. I'm developing a CLI app with cobra to validate semantic versions. In case a validation fails, I return some ...
Sebastian Sommerfeld's user avatar
1 vote
0 answers
155 views

Permission denied for "go test" in jenkins

currently I am trying to create a Pipeline in Jenkins to automatically deploy my go application into a docker container on my linux VM. There is no problem in building and deploying the application, ...
mrtz's user avatar
  • 11
2 votes
0 answers
63 views

Unit test cases in go

I am writing unit test cases for the simple service. I am trying to write test case for error condition for Run function. How can I write the test case for the s.Run error condition. type ...
vk_'s user avatar
  • 55
0 votes
1 answer
187 views

Mocking child functions in unit testing

How do you mock standalone functions in Golang? Let me use an example to explain. Example (Written in Golang) Suppose you have some code like this: type Item struct { price int ...
Ryn's user avatar
  • 471
1 vote
1 answer
564 views

How to write testable commands for app using cobra and viper

Summary:- I have a cobra-cli based golang app which uses viper for config management. I want to make my commands testable. For this I want to inject dependencies to my commands when they are being ...
abnvanand's user avatar
  • 223
0 votes
2 answers
386 views

Add Skipped Tests to Coverage

I created say connect.go and connect_test.go. For some reason I need to skip some tests in connect_test.go (using t.Skip()), especially when it comes to contacting external APIs and may involve some ...
محمد جعفر نعمة's user avatar
0 votes
2 answers
224 views

Golang mock forces to change functions definition

I have the following function: func getPrice(date string) { url := (fmt.Printf("http://endponint/%s", date)) resp, err := http.Get(url) // Unmarshall body and get price return ...
Uday Reddy's user avatar
  • 1,451
1 vote
1 answer
509 views

Writing unit tests for generics function in golang

I have this trivial generic function that retrieves the keys from a map // getMapKeys returns the keys of a map func getMapKeys[T comparable, U any](m map[T]U) []T { keys := make([]T, len(m)) ...
pkaramol's user avatar
  • 18.6k
1 vote
1 answer
195 views

Testing a func to read a specific JSON config file

I am new to testing in Go and am trying to test a func that reads a JSON config file (for Snowflake). I've read several questions that suggest using an io.Reader interface but I can't totally put it ...
Coldchain9's user avatar
  • 1,585
2 votes
4 answers
6k views

Golang GORM DB mock

I have to mock test a service.to create new service i need to pass gorm.DB{} but every time i pass it and run the test i get nil pointer error(panic). please help on how to mock gorm.DB{} instance ...
Viraj24Gupta's user avatar

15 30 50 per page
1
2 3 4 5
11