-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathschroedinger_test.go
107 lines (95 loc) · 2.73 KB
/
schroedinger_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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package schroedinger
import (
"math/rand"
"os"
"reflect"
"testing"
"time"
)
func init() {
rand.Seed(time.Now().UnixNano())
}
func TestCat(t *testing.T) {
if os.Getenv("thisIsOnlyATest") == "" {
t.Skip("No peeking!")
}
aliveOrDead := rand.Float64()
if aliveOrDead > 0.3 { // i mean, the odds could be worse
t.Fatalf("Kitty? %.2f", aliveOrDead)
}
}
func TestGrepFailures(t *testing.T) {
var outputWithFails = `
ok github.com/ethereumproject/go-ethereum/p2p 0.395s
ok github.com/ethereumproject/go-ethereum/p2p/discover 6.374s
ok github.com/ethereumproject/go-ethereum/p2p/distip 0.014s
--- FAIL: TestUPNP_DDWRT (2.10s)
natupnp_test.go:201: HTTPU request M-SEARCH *
natupnp_test.go:201: HTTPU request M-SEARCH *
natupnp_test.go:201: HTTPU request M-SEARCH *
natupnp_test.go:201: HTTPU request M-SEARCH *
natupnp_test.go:201: HTTPU request M-SEARCH *
natupnp_test.go:201: HTTPU request M-SEARCH *
natupnp_test.go:167: not discovered
FAIL
FAIL github.com/ethereumproject/go-ethereum/p2p/nat 2.664s
`
var outputOK = `
ok github.com/ethereumproject/go-ethereum/p2p 0.395s
ok github.com/ethereumproject/go-ethereum/p2p/discover 6.374s
ok github.com/ethereumproject/go-ethereum/p2p/distip 0.014s
`
if failures := grepFailures([]byte(outputWithFails)); len(failures) != 1 {
t.Errorf("got %v, want: %v", len(failures), 1)
}
if failures := grepFailures([]byte(outputOK)); len(failures) != 0 {
t.Errorf("got %v, want: %v", len(failures), 0)
}
}
func TestParseMatchList(t *testing.T) {
cases := []struct {
arg string
want []string
}{
{arg: "", want: nil},
{arg: "downloader,fetcher ", want: []string{"downloader", "fetcher"}},
}
for _, c := range cases {
if got := parseMatchList(c.arg); (got == nil && c.want != nil) || len(got) != len(c.want) {
t.Errorf("got: %v, want: %v", got, c.want)
}
}
}
func TestIntegration(t *testing.T) {
//github.com/etcdevteam/go-schroedinger TestTest1
//github.com/etcdevteam/go-schroedinger/...
//github.com/etcdevteam/go-schroedinger
want := []*test{
{pkg: "github.com/ETCDEVTeam/go-schroedinger", name: "TestCat"},
{pkg: "github.com/ETCDEVTeam/go-schroedinger/..."},
{pkg: "github.com/ETCDEVTeam/go-schroedinger"},
}
got, err := collectTestsFromFile("./example.txt")
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(got, want) {
t.Errorf("got: %v, want: %v", got, want)
}
allowed := func(t *test) bool {
if t.name == "" {
return false
}
return true
}
filteredWant := want[:1]
filteredGot := filterTests(got, allowed)
if !reflect.DeepEqual(filteredGot, filteredWant) {
t.Errorf("got: %v, want: %v", got, want)
}
os.Setenv("thisIsOnlyATest", "WTF")
if e := run("./example.txt", "Cat", "", 20); e != nil {
t.Fatal(e)
}
os.Setenv("thisIsOnlyATest", "")
}