forked from gobuffalo/genny
-
Notifications
You must be signed in to change notification settings - Fork 2
/
dry_runner_test.go
50 lines (43 loc) · 966 Bytes
/
dry_runner_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
38
39
40
41
42
43
44
45
46
47
48
49
50
package genny
import (
"context"
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/require"
)
func Test_DryRunner_Request(t *testing.T) {
table := []struct {
code int
method string
path string
boom bool
}{
{200, "GET", "/a", false},
{200, "POST", "/b", false},
{399, "PATCH", "/c", false},
{401, "GET", "/d", true},
{500, "POST", "/e", true},
}
for _, tt := range table {
t.Run(tt.method+tt.path, func(st *testing.T) {
r := require.New(st)
req, err := http.NewRequest(tt.method, tt.path, nil)
r.NoError(err)
run := DryRunner(context.Background())
run.RequestFn = func(req *http.Request, c *http.Client) (*http.Response, error) {
if tt.boom {
return nil, fmt.Errorf("error %d", tt.code)
}
return &http.Response{StatusCode: tt.code}, nil
}
res, err := run.Request(req)
if tt.boom {
r.Error(err)
return
}
r.NoError(err)
r.Equal(tt.code, res.StatusCode)
})
}
}