-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_attacker_mock.go
56 lines (48 loc) · 1.15 KB
/
http_attacker_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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* // Copyright 2020 Insolar Network Ltd.
* // All rights reserved.
* // This material is licensed under the Insolar License version 1.0,
* // available at https://github.com/insolar/assured-ledger/blob/master/LICENSE.md.
*/
package loaderbot
import (
"context"
"io"
"io/ioutil"
"net/http"
)
func init() {
RegisterAttacker("HTTPAttackerExample", &HTTPAttackerExample{})
}
type HTTPAttackerExample struct {
*Runner
}
func (a *HTTPAttackerExample) Clone(r *Runner) Attack {
return &HTTPAttackerExample{Runner: r}
}
func (a *HTTPAttackerExample) Setup(c RunnerConfig) error {
return nil
}
func (a *HTTPAttackerExample) Do(ctx context.Context) DoResult {
req, _ := http.NewRequestWithContext(ctx, "GET", a.Cfg.TargetUrl, nil)
res, err := a.HTTPClient.Do(req)
if res != nil {
if _, err = io.Copy(ioutil.Discard, res.Body); err != nil {
return DoResult{
RequestLabel: a.Name,
Error: err.Error(),
}
}
defer res.Body.Close()
}
if err != nil {
return DoResult{
RequestLabel: a.Name,
Error: err.Error(),
}
}
return DoResult{RequestLabel: a.Name}
}
func (a *HTTPAttackerExample) Teardown() error {
return nil
}