Newer
Older
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
import (
"context"
"net/http"
"testing"
"time"
)
func TestRun(t *testing.T) {
type args struct {
request string
}
tests := []struct {
name string
args args
want interface{}
wantErr bool
}{
{
name: "liveliness indicator",
args: args{request: apiEndpoint + "/livez"},
want: &http.Response{StatusCode: http.StatusOK},
wantErr: false,
},
{
name: "readyness indicator",
args: args{request: apiEndpoint + "/readyz"},
want: &http.Response{StatusCode: http.StatusOK},
wantErr: false,
},
{
name: "init",
args: args{request: apiEndpoint + "/api?q=init"},
want: &http.Response{StatusCode: http.StatusOK},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
go func() {
if err := Run(ctx); (err != nil) != tt.wantErr {
t.Errorf("Run() error = %v, wantErr %v", err, tt.wantErr)
}
}()
time.Sleep(time.Second)
cancel()
time.Sleep(time.Second)
})
}
}