func TestExtractObj(t *testing.T) { client := framework.NewEtcdClient() helper := tools.EtcdHelper{Client: client, Codec: stringCodec{}} framework.WithEtcdKey(func(key string) { _, err := client.Set(key, "object", 0) if err != nil { t.Fatalf("unexpected error: %v", err) } s := fakeAPIObject("") if err := helper.ExtractObj(key, &s, false); err != nil { t.Fatalf("unexpected error: %v", err) } if s != "object" { t.Errorf("unexpected response: %#v", s) } }) }
func TestSetObj(t *testing.T) { client := framework.NewEtcdClient() helper := tools.EtcdHelper{Client: client, Codec: stringCodec{}} framework.WithEtcdKey(func(key string) { fakeObject := fakeAPIObject("object") if err := helper.SetObj(key, &fakeObject, nil, 0); err != nil { t.Fatalf("unexpected error: %v", err) } resp, err := client.Get(key, false, false) if err != nil || resp.Node == nil { t.Fatalf("unexpected error: %v %v", err, resp) } if resp.Node.Value != "object" { t.Errorf("unexpected response: %#v", resp.Node) } }) }