-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathping_test.go
95 lines (88 loc) · 2 KB
/
ping_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
package wfi
import (
"testing"
"time"
)
func TestPingPostgres(t *testing.T) {
if err := Up("./test", "docker-compose.database.yaml", "--build"); err != nil {
t.Error(err)
}
defer Down("./test", "docker-compose.database.yaml")
type args struct {
host string
duration time.Duration
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "wait for database",
args: args{
host: "127.0.0.1:5432",
duration: time.Second * 15,
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := Ping(tt.args.host, tt.args.duration); (err != nil) != tt.wantErr {
t.Errorf("Ping() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestPingNsq(t *testing.T) {
if err := Up("./test", "docker-compose.nsq.yaml"); err != nil {
t.Error(err)
}
defer Down("./test", "docker-compose.nsq.yaml")
type args struct {
host string
duration time.Duration
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "wait for nsqlookupd",
args: args{
host: "localhost:4161",
duration: time.Second * 15,
},
wantErr: false,
},
{
name: "wait for nsqld",
args: args{
host: "localhost:4151",
duration: time.Second * 15,
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := Ping(tt.args.host, tt.args.duration); (err != nil) != tt.wantErr {
t.Errorf("Ping() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestFind(t *testing.T) {
r, err := UpWithLogs("./test", "docker-compose.kafka.yaml")
if err != nil {
t.Error(err)
}
defer Down("./test", "docker-compose.kafka.yaml")
if err = Find("started (kafka.server.KafkaServer)", r, time.Second*10); err != nil {
t.Errorf(`"started (kafka.server.KafkaServer)" phrase should show up within 10s, %v`, err)
}
if err = Find("a random message", r, time.Second*10); err == nil {
t.Error(`'a random message' phrase should not exist`)
}
}