Package list golang-github-go-kit-kit / 432e292
Convert endpoints test to instance tests Yuri Shkuro 4 years ago
2 changed file(s) with 15 addition(s) and 30 deletion(s). Raw diff Collapse all Expand all
00 package eureka
11
22 import (
3 "io"
43 "testing"
54 "time"
65
76 "github.com/hudl/fargo"
87
9 "github.com/go-kit/kit/endpoint"
108 "github.com/go-kit/kit/sd"
119 )
1210
1311 var _ sd.Instancer = &Instancer{} // API check
1412
1513 func TestInstancer(t *testing.T) {
16 factory := func(string) (endpoint.Endpoint, io.Closer, error) {
17 return endpoint.Nop, nil, nil
18 }
19
2014 connection := &testConnection{
2115 instances: []*fargo.Instance{instanceTest1},
2216 application: appUpdateTest,
2620 instancer := NewInstancer(connection, appNameTest, loggerTest)
2721 defer instancer.Stop()
2822
29 endpointer := sd.NewEndpointer(instancer, factory, loggerTest)
30 endpoints, err := endpointer.Endpoints()
31 if err != nil {
32 t.Fatal(err)
23 state := instancer.State()
24 if state.Err != nil {
25 t.Fatal(state.Err)
3326 }
3427
35 if want, have := 1, len(endpoints); want != have {
28 if want, have := 1, len(state.Instances); want != have {
3629 t.Errorf("want %d, have %d", want, have)
3730 }
3831 }
22 package eureka
33
44 import (
5 "io"
65 "os"
76 "testing"
87 "time"
98
109 "github.com/hudl/fargo"
1110
12 "github.com/go-kit/kit/endpoint"
1311 "github.com/go-kit/kit/log"
14 "github.com/go-kit/kit/sd"
1512 )
1613
1714 // Package sd/eureka provides a wrapper around the Netflix Eureka service
4946 // This should be enough time for the Eureka server response cache to update.
5047 time.Sleep(time.Second)
5148
52 // Build a Eureka subscriber.
53 factory := func(instance string) (endpoint.Endpoint, io.Closer, error) {
54 t.Logf("factory invoked for %q", instance)
55 return endpoint.Nop, nil, nil
56 }
49 // Build a Eureka instancer.
5750 instancer := NewInstancer(
5851 &fargoConnection,
5952 appNameTest,
6053 log.With(logger, "component", "instancer"),
6154 )
6255 defer instancer.Stop()
63 endpointer := sd.NewEndpointer(instancer, factory, log.With(logger, "component", "endpointer"))
6456
65 // We should have one endpoint immediately after subscriber instantiation.
66 endpoints, err := endpointer.Endpoints()
67 if err != nil {
68 t.Error(err)
57 // We should have one instance immediately after subscriber instantiation.
58 state := instancer.State()
59 if state.Err != nil {
60 t.Error(state.Err)
6961 }
70 if want, have := 1, len(endpoints); want != have {
62 if want, have := 1, len(state.Instances); want != have {
7163 t.Errorf("want %d, have %d", want, have)
7264 }
7365
8072 // configured with the properties mentioned in the function comments.
8173 time.Sleep(2 * time.Second)
8274
83 // Now we should have two endpoints.
84 endpoints, err = endpointer.Endpoints()
85 if err != nil {
86 t.Error(err)
75 // Now we should have two instances.
76 state = instancer.State()
77 if state.Err != nil {
78 t.Error(state.Err)
8779 }
88 if want, have := 2, len(endpoints); want != have {
80 if want, have := 2, len(state.Instances); want != have {
8981 t.Errorf("want %d, have %d", want, have)
9082 }
9183