-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreqfile.go
49 lines (38 loc) · 859 Bytes
/
reqfile.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
package reql
import (
"fmt"
"net/http"
)
type Reqfile struct {
Request Request `hcl:"request,block"`
Response Response `hcl:"response,block"`
}
type Headers struct {
Values map[string]string `hcl:",remain"`
}
type Request struct {
HTTPVersion string
Method string `hcl:"method"`
URL string `hcl:"url"`
Headers map[string]string `hcl:"headers,optional"`
Body string `hcl:"body,optional"`
}
func NewRequest() Request {
return Request{
// Headers: make(Headers),
}
}
type Response struct {
Assertions []Assertion `hcl:"assert,block"`
}
type Assertion struct {
Name string `hcl:"name,label"`
Expr string `hcl:"expr"`
fn AssertionFunc
}
func (a Assertion) Assert(request *http.Request, response *http.Response) error {
if !a.fn(request, response) {
return fmt.Errorf("%s failed assertion", a.Name)
}
return nil
}