P
P
Proshka172019-12-25 00:10:27
go
Proshka17, 2019-12-25 00:10:27

Testing a Go program?

Good afternoon!
I have written a web service in Go and am writing tests for it. I wrote a test to test the handler but I get an error

package main

import (
  "net/http"
  "net/http/httptest"
  "testing"

)

func TestHealthCheckHandler(t *testing.T) {

  req, err := http.NewRequest("POST", "/ad/getall", nil)
  if err != nil {
    t.Fatal(err)
  }

  rr := httptest.NewRecorder()
  handler := http.HandlerFunc(GetAll)


  handler.ServeHTTP(rr, req)


  expected := `400`
  if rr.Body.String() != expected {
    t.Errorf("handler returned unexpected body: got %v want %v",
      rr.Body.String(), expected)
  }
}

5e027ea846f70484609869.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DmitriyTitov, 2019-12-25
@DmitriyTitov

The test is written correctly. But the main program, apparently, no. Give the text of main.go.
Well, or look at line No. 80 in it, as the execution stack dump writes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question