Questions tagged [go-testing]

121 questions
0
votes
1 answer

Issues with debugging tests in golang with vscode

I'm running Golang tests on VSCode with some global variables, that being initialized before reaching the test function. The global variables in my program get their values from runline arguments, that specified in the launch.json file…
0
votes
0 answers

Run go test using Golang's exec library

I am trying to run go test command using the exec library as this. output, err := exec.Command("bash", "-c", "go test -v -run TestX ./test/*").Output() if err != nil { log.GetLogger().Error(err.Error()) } It is failing with exit…
techjourneyman
  • 1,701
  • 3
  • 33
  • 53
0
votes
1 answer

Go gin nested JSON request body POST, error unexpected end of JSON input

I am new to GO and was trying to create a simple POST API with gin and gorm. The request data is nested JSON like below: { "fall_orders_request": [ { "fruit": "Watermelon", "vegetable": "Carrot" } ], …
Valhala
  • 21
  • 4
0
votes
3 answers

Golang: Mock an interface method before Init method is called

How can I mock something that gets called in a package init() method? For example: main.go var myService MyService = myservicepkg.New() func init(){ response := myService.get() } func otherMethod(){ //do something } maintest.go func…
cosbor11
  • 14,709
  • 10
  • 54
  • 69
0
votes
2 answers

How to test a Oauth2.0 resource of server

I want to code the test for validate the right document to reach to the Oauth2.0 of third party server, how should i complete the pseudocode? import ( "net/http" "net/http/httptest" } func testAuthServer(t *testing.T) { form :=…
ccd
  • 5,788
  • 10
  • 46
  • 96
0
votes
1 answer

How to simulate multiple different HTTP responses using Go's httptest?

I have created some Go functions that make HTTP GET calls to services that are out there on the internet and parse the results. I am now working on writing test-cases for these functions. In my test cases, I'm using the go package httptest to…
Saqib Ali
  • 11,931
  • 41
  • 133
  • 272
0
votes
1 answer

How to generate test report in XML

I have tests (Unit and Integration) in Go and I need to generate a report in XML (Preferably Junit). Also each test tests a certain functionality. Hence I would like them to be grouped/tagged in report. The only thing I could find in internet was Go…
PRASANNA SARAF
  • 333
  • 1
  • 4
  • 17
0
votes
0 answers

Mocking `peer` while unit testing gRPC with bufconn

I have unidirectional (both client- and server-) streaming gRPC methods implemented in my golang server. I came across bufconn which enables me to creates my server via in-memory connections in my tests. However, I have logic in my method where I…
Bak
  • 3
  • 3
0
votes
0 answers

How to get Integration Test Coverage for GoLang Microservice

I created a couple of Rest API based Microservices running of different ports of a server. Then i wrote a Test code that actually sends a Rest API call over HTTP to serviceA (which in turn calls serviceB), and gets its response, decodes it and…
kernelman
  • 992
  • 1
  • 13
  • 28
0
votes
1 answer

Go unit testing Bcrypt

I am performing unit tests for a service where request dto's are validated and user passwords are hashed using Go's Bcrypt package before being passed to a repository for insertion into the DB. I don't know how my mock functions should return a…
Jeremy
  • 1,447
  • 20
  • 40
0
votes
2 answers

Disable race detection in test binary

Is there a way to disable the data race checking in a compiled test binary? Sometimes I want to specifically exclude binaries in my test suite. Of course I could just not run it with go test -race but I'd have to rewrite part of our test pipeline…
hbogert
  • 4,198
  • 5
  • 24
  • 38
0
votes
1 answer

Go sqlmock SELECT missing expected query

Go here. Trying to figure out how to use SQL mock v2. Here's my interface: type OrderPersister interface { FetchOrderById(string) (*Order, error) } And my implementation of that interface: type DbPersister struct { Config config.DbConfig …
hotmeatballsoup
  • 385
  • 6
  • 58
  • 136
0
votes
1 answer

Using package level variables in go test files

I am trying to write a unit test for a file that is like this //file1.go var ( fileName = "/path/to/original/file.json" ) func DoSomething(){ // Read and do some stuff } But for unit testing, I would like to use…
Aman Chourasiya
  • 1,078
  • 1
  • 10
  • 23
0
votes
0 answers

Unable to validate Http response with expected output using golang test and beego framework

I am not able to match response body with expected value Here is the code i have tried to POST method to create resource func TestCreateFileShare(t *testing.T) { var jsonStr = []byte(`{ "id": "bd5b12a8-a101-11e7-941e-d77981b584d8", …
tech01
  • 1
  • 1
0
votes
1 answer

Go test can access production functions but not test functions

I have a Go 1.14 project with the following directory structure: myapp/ server/ payments/ capture_payment.go capture_payment_test.go billing/ billing.go billing_test.go fulfillment/ fulfillment.go …
hotmeatballsoup
  • 385
  • 6
  • 58
  • 136
1 2 3
8 9