-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_test.go
37 lines (32 loc) · 816 Bytes
/
run_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package apitestr_test
import (
"context"
"encoding/json"
"github.com/tomwright/apitestr"
"github.com/tomwright/apitestr/parse"
"net/http"
"net/http/httptest"
"testing"
)
func TestRun(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
res, _ := json.Marshal(map[string]interface{}{
"completed": false,
"id": 1,
"title": "delectus aut autem",
"userId": 1,
})
_, _ = w.Write(res)
}))
defer ts.Close()
ctx := apitestr.ContextWithBaseURL(context.Background(), ts.URL)
te, err := parse.File(ctx, "tests/example.json")
if err != nil {
t.Errorf("unexpected error parsing file: %s", err)
return
}
if err := apitestr.Run(ctx, te, nil, nil); err != nil {
t.Errorf("unexpected error in test: %s", err)
return
}
}