Package list golang-github-go-kit-kit / 298086e
Fix tests Yuri Shkuro 4 years ago
1 changed file(s) with 18 addition(s) and 57 deletion(s). Raw diff Collapse all Expand all
2525
2626 instancer := NewInstancer(connection, appNameTest, loggerTest)
2727 defer instancer.Stop()
28
2829 endpointer := sd.NewEndpointer(instancer, factory, loggerTest)
29
3030 endpoints, err := endpointer.Endpoints()
3131 if err != nil {
3232 t.Fatal(err)
3838 }
3939
4040 func TestInstancerScheduleUpdates(t *testing.T) {
41 factory := func(string) (endpoint.Endpoint, io.Closer, error) {
42 return endpoint.Nop, nil, nil
43 }
44
4541 connection := &testConnection{
4642 instances: []*fargo.Instance{instanceTest1},
4743 application: appUpdateTest,
5046
5147 instancer := NewInstancer(connection, appNameTest, loggerTest)
5248 defer instancer.Stop()
53 endpointer := sd.NewEndpointer(instancer, factory, loggerTest)
5449
55 endpoints, _ := endpointer.Endpoints()
56 if want, have := 1, len(endpoints); want != have {
50 state := instancer.State()
51 if want, have := 1, len(state.Instances); want != have {
5752 t.Errorf("want %d, have %d", want, have)
5853 }
5954
6055 time.Sleep(50 * time.Millisecond)
6156
62 endpoints, _ = endpointer.Endpoints()
63 if want, have := 2, len(endpoints); want != have {
57 state = instancer.State()
58 if want, have := 2, len(state.Instances); want != have {
6459 t.Errorf("want %v, have %v", want, have)
6560 }
6661 }
6762
68 func TestBadFactory(t *testing.T) {
69 factory := func(string) (endpoint.Endpoint, io.Closer, error) {
70 return nil, nil, errTest
71 }
72
73 connection := &testConnection{
74 instances: []*fargo.Instance{instanceTest1},
75 application: appUpdateTest,
76 errApplication: nil,
77 }
78
79 instancer := NewInstancer(connection, appNameTest, loggerTest)
80 defer instancer.Stop()
81 endpointer := sd.NewEndpointer(instancer, factory, loggerTest)
82
83 endpoints, err := endpointer.Endpoints()
84 if err != nil {
85 t.Fatal(err)
86 }
87
88 if want, have := 0, len(endpoints); want != have {
89 t.Errorf("want %d, have %d", want, have)
90 }
91 }
92
9363 func TestBadInstancerInstances(t *testing.T) {
94 factory := func(string) (endpoint.Endpoint, io.Closer, error) {
95 return endpoint.Nop, nil, nil
96 }
97
9864 connection := &testConnection{
9965 instances: []*fargo.Instance{},
10066 errInstances: errTest,
10470
10571 instancer := NewInstancer(connection, appNameTest, loggerTest)
10672 defer instancer.Stop()
107 endpointer := sd.NewEndpointer(instancer, factory, loggerTest)
10873
109 endpoints, err := endpointer.Endpoints()
110 if err != nil {
111 t.Fatal(err)
74 state := instancer.State()
75 if state.Err == nil {
76 t.Fatal("expecting error")
11277 }
11378
114 if want, have := 0, len(endpoints); want != have {
79 if want, have := 0, len(state.Instances); want != have {
11580 t.Errorf("want %d, have %d", want, have)
11681 }
11782 }
11883
11984 func TestBadInstancerScheduleUpdates(t *testing.T) {
120 factory := func(string) (endpoint.Endpoint, io.Closer, error) {
121 return endpoint.Nop, nil, nil
122 }
123
12485 connection := &testConnection{
12586 instances: []*fargo.Instance{instanceTest1},
12687 application: appUpdateTest,
12990
13091 instancer := NewInstancer(connection, appNameTest, loggerTest)
13192 defer instancer.Stop()
132 endpointer := sd.NewEndpointer(instancer, factory, loggerTest)
13393
134 endpoints, err := endpointer.Endpoints()
135 if err != nil {
136 t.Error(err)
94 state := instancer.State()
95 if state.Err != nil {
96 t.Error(state.Err)
13797 }
138 if want, have := 1, len(endpoints); want != have {
98 if want, have := 1, len(state.Instances); want != have {
13999 t.Errorf("want %d, have %d", want, have)
140100 }
141101
142102 time.Sleep(50 * time.Millisecond)
143103
144 endpoints, err = endpointer.Endpoints()
145 if err != nil {
146 t.Error(err)
104 state = instancer.State()
105 if state.Err == nil {
106 t.Fatal("expecting error")
147107 }
148 if want, have := 1, len(endpoints); want != have {
108
109 if want, have := 0, len(state.Instances); want != have {
149110 t.Errorf("want %v, have %v", want, have)
150111 }
151112 }