3
0

upd(internal/http): perform internal test for http client

Signed-off-by: Tit Petric <black@scene-si.org>
This commit is contained in:
Tit Petric 2019-05-19 14:41:15 +02:00
parent ccc50012ce
commit 4a6798ea3f
2 changed files with 21 additions and 3 deletions

View File

@ -0,0 +1,14 @@
package http
import (
"fmt"
"net/http"
)
type Fortune struct{}
func (*Fortune) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fortune := "Fortune favors the prepared mind. - Louis Pasteur"
fmt.Fprintf(w, fortune)
}

View File

@ -1,22 +1,26 @@
// +build external
package http
import (
"testing"
"net/http/httptest"
"github.com/crusttech/crust/internal/config"
"github.com/crusttech/crust/internal/test"
)
func TestHTTPClient(t *testing.T) {
handler := &Fortune{}
server := httptest.NewServer(handler)
defer server.Close()
client, err := New(&config.HTTPClient{
Timeout: 10,
})
test.Assert(t, err == nil, "%+v", err)
client.Debug(FULL)
req, err := client.Get("https://api.scene-si.org/fortune.php")
req, err := client.Get(server.URL)
test.Assert(t, err == nil, "%+v", err)
resp, err := client.Do(req)