I have installed the following in my Windows 10 machine:
- VS Code - version 1.38.1
- Golang - version go1.13
- Delve - version 1.3.0
I have set GOROOT and GOPATH in environment variables. My GOPATH has the following three folders:
- src
- bin
- pkg
Under src, I have created a basic sam-app. It auto-creates main_test.go file. When I do 'debug test', breakpoint is not hitting in UI. Howerver, I am able to debug using dlv in command line.
I have tried different configurations in launch.json. None of them worked. In my friend's machine, the UI Debugging works even without configurations
In VS Code settings --> node debug --> auto attach --> I have set 'on'
I have closed VS Code and re-opened. It did not work
I have opened VS Code as Administrator, it did't work either
I have uninstalled and reinstalled VS Code
I have uninstalled and reinstalled Golang
I have installed Go extension in VS Code
package main import ( "fmt" "net/http" "net/http/httptest" "testing" "github.com/aws/aws-lambda-go/events" ) func TestHandler(t *testing.T) { t.Run("Unable to get IP", func(t *testing.T) { DefaultHTTPGetAddress = "http://127.0.0.1:12345" _, err := handler(events.APIGatewayProxyRequest{}) if err == nil { t.Fatal("Error failed to trigger with an invalid request") } }) t.Run("Non 200 Response", func(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(500) })) defer ts.Close() DefaultHTTPGetAddress = ts.URL _, err := handler(events.APIGatewayProxyRequest{}) if err != nil && err.Error() != ErrNon200Response.Error() { t.Fatalf("Error failed to trigger with an invalid HTTP response: %v", err) } }) t.Run("Unable decode IP", func(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(500) })) defer ts.Close() DefaultHTTPGetAddress = ts.URL _, err := handler(events.APIGatewayProxyRequest{}) if err == nil { t.Fatal("Error failed to trigger with an invalid HTTP response") } }) t.Run("Successful Request", func(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(200) fmt.Fprintf(w, "127.0.0.1") })) defer ts.Close() DefaultHTTPGetAddress = ts.URL _, err := handler(events.APIGatewayProxyRequest{}) if err != nil { t.Fatal("Everything should be ok") } }) }
I want the breakpoint to be hit, in UI, when I debug main.go or main_test.go.
UPDATE:
After I downgraded my VS Code to 1.30.2 and installed Go extension and Delve, I get the following error when I debug:
"Debug adapter process has terminated unexpectedly (read error)"