예제 #1
0
func TestPublisherStoppped(t *testing.T) {
	var (
		logger = log.NewNopLogger()
		e      = func(context.Context, interface{}) (interface{}, error) { return struct{}{}, nil }
	)

	factory := func(instance string) (endpoint.Endpoint, error) {
		return e, errors.New("_")
	}

	client := &fakeClient{
		responses: map[string]*stdetcd.Response{"/foo": fakeResponse},
	}

	p, err := kitetcd.NewPublisher(client, "/foo", factory, logger)
	if err != nil {
		t.Fatalf("failed to create new publisher: %v", err)
	}

	p.Stop()

	_, have := p.Endpoints()
	if want := loadbalancer.ErrPublisherStopped; want != have {
		t.Fatalf("want %v, have %v", want, have)
	}
}
예제 #2
0
func TestBadFactory(t *testing.T) {
	logger := log.NewNopLogger()

	factory := func(string) (endpoint.Endpoint, io.Closer, error) {
		return nil, nil, errors.New("kaboom")
	}

	client := &fakeClient{
		responses: map[string]*stdetcd.Response{"/foo": fakeResponse},
	}

	p, err := kitetcd.NewPublisher(client, "/foo", factory, logger)
	if err != nil {
		t.Fatalf("failed to create new publisher: %v", err)
	}
	defer p.Stop()

	endpoints, err := p.Endpoints()
	if err != nil {
		t.Fatal(err)
	}

	if want, have := 0, len(endpoints); want != have {
		t.Errorf("want %q, have %q", want, have)
	}
}
예제 #3
0
func TestPublisher(t *testing.T) {
	var (
		logger = log.NewNopLogger()
		e      = func(context.Context, interface{}) (interface{}, error) { return struct{}{}, nil }
	)

	factory := func(instance string) (endpoint.Endpoint, error) {
		return e, nil
	}

	client := &fakeClient{
		responses: map[string]*stdetcd.Response{"/foo": fakeResponse},
	}

	p, err := kitetcd.NewPublisher(client, "/foo", factory, logger)
	if err != nil {
		t.Fatalf("failed to create new publisher: %v", err)
	}
	defer p.Stop()

	if _, err := p.Endpoints(); err != nil {
		t.Fatal(err)
	}
}