forked from smartcontractkit/wasp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgun_http_mock.go
39 lines (34 loc) · 913 Bytes
/
gun_http_mock.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
package wasp
import "github.com/go-resty/resty/v2"
// MockHTTPGunConfig configures a mock HTTP gun
type MockHTTPGunConfig struct {
TargetURL string
}
// MockHTTPGun is a mock gun
type MockHTTPGun struct {
client *resty.Client
cfg *MockHTTPGunConfig
Data []string
}
// NewHTTPMockGun create an HTTP mock gun
func NewHTTPMockGun(cfg *MockHTTPGunConfig) *MockHTTPGun {
return &MockHTTPGun{
client: resty.New(),
cfg: cfg,
Data: make([]string, 0),
}
}
// Call implements example gun call, assertions on response bodies should be done here
func (m *MockHTTPGun) Call(l *Generator) CallResult {
var result map[string]interface{}
r, err := m.client.R().
SetResult(&result).
Get(m.cfg.TargetURL)
if err != nil {
return CallResult{Data: result, Error: err.Error()}
}
if r.Status() != "200 OK" {
return CallResult{Data: result, Error: "not 200"}
}
return CallResult{Data: result}
}