-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmonkey_test.go
48 lines (38 loc) · 1.16 KB
/
monkey_test.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
package main
import (
"testing"
"os"
"os/exec"
)
func TestSetupAttackThreads(t *testing.T) {
t.Run("Test that the monkey correctly reports failing attacks", func(t *testing.T) {
MaxTimeBetweenAttacks = 20
responseChannel := make(chan Response)
config := CreateFullTestConfiguration("200", "HTTP_SPAM")
go SetupTargets(&config, responseChannel)
response := <- responseChannel
if response.Passed {
t.Error("Expected test response to not be passing. Test has passing = true")
}
})
}
func TestPerformSequentialAttack(t *testing.T) {
t.Run("Test that the monkey correctly runs each of the attacks in config", func(t *testing.T) {
ok := getStatusFromSequentialAttack()
if ok {
t.Error("Expected error status from the command line. Got ok status.")
}
})
}
func getStatusFromSequentialAttack() bool {
config := CreateFullTestConfiguration("200", "HTTP_SPAM")
if os.Getenv("TEST_SEQ_ATTACK") == "1" {
PerformSequentialAttack(&config)
return false
}
cmd := exec.Command(os.Args[0])
cmd.Env = append(os.Environ(), "TEST_SEQ_ATTACK=1")
err := cmd.Run()
_, ok := err.(*exec.ExitError)
return ok
}