-
Notifications
You must be signed in to change notification settings - Fork 63
/
ammo.go
80 lines (68 loc) · 1.6 KB
/
ammo.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
80
package httpscenario
import (
"io"
"net/http"
"time"
"github.com/yandex/pandora/components/providers/scenario"
)
type SourceStorage interface {
Variables() map[string]any
}
type Scenario struct {
Requests []Request
ID uint64
Name string
MinWaitingTime time.Duration
VariableStorage SourceStorage
}
func (a *Scenario) SetID(id uint64) {
a.ID = id
}
func (a *Scenario) Clone() scenario.ProvAmmo {
return &Scenario{
Requests: a.Requests,
Name: a.Name,
MinWaitingTime: a.MinWaitingTime,
VariableStorage: a.VariableStorage,
}
}
type Request struct {
Method string
Headers map[string]string
Tag string
Body *string
Name string
URI string
Preprocessor Preprocessor
Postprocessors []Postprocessor
Templater Templater
Sleep time.Duration
}
func (r *Request) GetBody() []byte {
if r.Body == nil {
return nil
}
return []byte(*r.Body)
}
func (r *Request) GetHeaders() map[string]string {
result := make(map[string]string, len(r.Headers))
for k, v := range r.Headers {
result[k] = v
}
return result
}
type Preprocessor interface {
// Process is called before request is sent
// templateVars - variables from template. Can be modified
// sourceVars - variables from sources. Must NOT be modified
Process(templateVars map[string]any) (map[string]any, error)
}
type Postprocessor interface {
Process(resp *http.Response, body io.Reader) (map[string]any, error)
}
type RequestParts struct {
URL string
Method string
Body []byte
Headers map[string]string
}