Exemple #1
0
func (r *registry) Register(i discovery.Instance, ttl uint64) error {
	_, err := r.client.Set(
		r.storePath(i),
		i.String(),
		ttl,
	)
	return err
}
Exemple #2
0
func TestRegister(t *testing.T) {
	var (
		namespace = "namespace"
		machines  = []string{"foo", "bar"}
		ttl       = uint64(1234)
		instance  = discovery.Instance{
			ID:     "id",
			Name:   "name",
			Env:    "env",
			Region: "region",
			Host:   "host",
			Port:   987,
		}
		path   = "namespace/region/env/name/id"
		json   = instance.String()
		client = new(fake.EtcdClient)
	)

	oldEtcdClient := injectClient(client, machines, t)
	defer func() { etcdClient = oldEtcdClient }()

	registry := NewRegistry(machines, namespace)

	err := registry.Register(instance, ttl)
	if want, have := error(nil), err; want != have {
		t.Fatalf("want %v, have %v", want, have)
	}

	if want, have := 1, client.SetCallCount(); want != have {
		t.Fatalf("want %v, have %v", want, have)
	}

	actualPath, actualJSON, actualTTL := client.SetArgsForCall(0)

	if want, have := path, actualPath; want != have {
		t.Fatalf("want %v, have %v", want, have)
	}

	if want, have := json, actualJSON; want != have {
		t.Fatalf("want %v, have %v", want, have)
	}

	if want, have := ttl, actualTTL; want != have {
		t.Fatalf("want %v, have %v", want, have)
	}
}