-
Notifications
You must be signed in to change notification settings - Fork 0
/
gostman.go
79 lines (66 loc) · 1.83 KB
/
gostman.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package gostman
import (
_ "embed"
"net/http"
neturl "net/url"
"strings"
"testing"
)
// Gostman represents an API development set.
type Gostman struct {
t *testing.T
}
// New returns new Gostman.
func New(t *testing.T) *Gostman {
return &Gostman{
t: t,
}
}
// Request run the request.
func (gm *Gostman) Request(name, method, url string, fn func(*Request)) {
gm.t.Run(strings.ReplaceAll(name, " ", ""), func(t *testing.T) {
fn(&Request{
t: t,
method: method,
url: url,
params: make(neturl.Values),
headers: recomendedHeader(),
})
})
}
// GET run the request using GET method.
func (gm *Gostman) GET(name, url string, fn func(*Request)) {
gm.Request(name, http.MethodGet, url, fn)
}
// POST run the request using POST method.
func (gm *Gostman) POST(name, url string, fn func(*Request)) {
gm.Request(name, http.MethodPost, url, fn)
}
// PUT run the request using PUT method.
func (gm *Gostman) PUT(name, url string, fn func(*Request)) {
gm.Request(name, http.MethodPut, url, fn)
}
// PATCH run the request using PATCH method.
func (gm *Gostman) PATCH(name, url string, fn func(*Request)) {
gm.Request(name, http.MethodPatch, url, fn)
}
// DELETE run the request using DELETE method.
func (gm *Gostman) DELETE(name, url string, fn func(*Request)) {
gm.Request(name, http.MethodDelete, url, fn)
}
// HEAD run the request using HEAD method.
func (gm *Gostman) HEAD(name, url string, fn func(*Request)) {
gm.Request(name, http.MethodHead, url, fn)
}
// OPTIONS run the request using OPTIONS method.
func (gm *Gostman) OPTIONS(name, url string, fn func(*Request)) {
gm.Request(name, http.MethodOptions, url, fn)
}
// SetV sets a variable.
func (gm *Gostman) SetV(name, val string) {
runtime.setEnvVar(name, val)
}
// V returns a variable.
func (gm *Gostman) V(name string) string {
return runtime.envVar(name)
}