travis-ci
6 of 6 new or added lines in 3 files covered. (100.0%)
3433 of 3817 relevant lines covered (89.94%)
273.28 hits per line
1 |
package error |
|
2 |
|
|
3 |
import (
|
|
4 |
"fmt"
|
|
5 |
"math/rand"
|
|
6 |
|
|
7 |
"github.com/gansoi/gansoi/plugins"
|
|
8 |
) |
|
9 |
|
|
10 |
type (
|
|
11 |
// Error is only useful for testing Gansoi.
|
|
12 |
Error struct {
|
|
13 |
Chance int `json:"chance" description:"What's the chance of failure (0-100)" default:"50"` |
|
14 |
} |
|
15 |
) |
|
16 |
|
|
17 |
func init() {
|
60✔ |
18 |
plugins.RegisterAgent("error", Error{})
|
60✔ |
19 |
} |
60✔ |
20 |
|
|
21 |
// Check implements plugins.Agent.
|
|
22 |
func (e *Error) Check(result plugins.AgentResult) error { |
4 only 427.1 and 427.2 ✔ |
23 |
n := rand.Intn(99) + 1 |
4 only 427.1 and 427.2 ✔ |
24 |
|
4 only 427.1 and 427.2 ✔ |
25 |
if n <= e.Chance {
|
6 only 427.1 and 427.2 ✔ |
26 |
return fmt.Errorf("%d was below %d", n, e.Chance) |
2 only 427.1 and 427.2 ✔ |
27 |
} |
2 only 427.1 and 427.2 ✔ |
28 |
|
|
29 |
return nil |
2 only 427.1 and 427.2 ✔ |
30 |
} |