shad-go/lectures/06-http/httptest/code_test.go
2020-04-02 11:42:31 +00:00

30 lines
566 B
Go

package httptest
import (
"context"
"net/http"
"net/http/httptest"
"testing"
)
func TestGetReposCount(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("42"))
}))
defer srv.Close()
client := NewAPICLient(srv.URL)
count, err := client.GetReposCount(context.Background(), "007")
if err != nil {
t.Errorf("unexpected error: %s", err)
}
expectedCount := 42
if count != expectedCount {
t.Errorf("expected count to be: %d, got: %d", expectedCount, count)
}
}
// OMIT