Use Decode/Encode in etcd_tools
This commit is contained in:

committed by
Daniel Smith

parent
d558a93a98
commit
f1d6069b01
@@ -45,10 +45,6 @@ func TestIsNotFoundErr(t *testing.T) {
|
||||
try(fmt.Errorf("some other kind of error"), false)
|
||||
}
|
||||
|
||||
type testMarshalType struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
func TestExtractList(t *testing.T) {
|
||||
fakeClient := MakeFakeEtcdClient(t)
|
||||
fakeClient.Data["/some/key"] = EtcdResponseWithError{
|
||||
@@ -68,12 +64,12 @@ func TestExtractList(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
expect := []testMarshalType{
|
||||
{"foo"},
|
||||
{"bar"},
|
||||
{"baz"},
|
||||
expect := []api.Pod{
|
||||
{JSONBase: api.JSONBase{ID: "foo"}},
|
||||
{JSONBase: api.JSONBase{ID: "bar"}},
|
||||
{JSONBase: api.JSONBase{ID: "baz"}},
|
||||
}
|
||||
var got []testMarshalType
|
||||
var got []api.Pod
|
||||
helper := EtcdHelper{fakeClient}
|
||||
err := helper.ExtractList("/some/key", &got)
|
||||
if err != nil {
|
||||
@@ -86,10 +82,10 @@ func TestExtractList(t *testing.T) {
|
||||
|
||||
func TestExtractObj(t *testing.T) {
|
||||
fakeClient := MakeFakeEtcdClient(t)
|
||||
expect := testMarshalType{ID: "foo"}
|
||||
expect := api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
|
||||
fakeClient.Set("/some/key", util.MakeJSONString(expect), 0)
|
||||
helper := EtcdHelper{fakeClient}
|
||||
var got testMarshalType
|
||||
var got api.Pod
|
||||
err := helper.ExtractObj("/some/key", &got, false)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error %#v", err)
|
||||
@@ -123,7 +119,7 @@ func TestExtractObjNotFoundErr(t *testing.T) {
|
||||
}
|
||||
helper := EtcdHelper{fakeClient}
|
||||
try := func(key string) {
|
||||
var got testMarshalType
|
||||
var got api.Pod
|
||||
err := helper.ExtractObj(key, &got, false)
|
||||
if err == nil {
|
||||
t.Errorf("%s: wanted error but didn't get one", key)
|
||||
@@ -140,14 +136,18 @@ func TestExtractObjNotFoundErr(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSetObj(t *testing.T) {
|
||||
obj := testMarshalType{ID: "foo"}
|
||||
obj := api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
|
||||
fakeClient := MakeFakeEtcdClient(t)
|
||||
helper := EtcdHelper{fakeClient}
|
||||
err := helper.SetObj("/some/key", obj)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error %#v", err)
|
||||
}
|
||||
expect := util.MakeJSONString(obj)
|
||||
data, err := api.Encode(obj)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error %#v", err)
|
||||
}
|
||||
expect := string(data)
|
||||
got := fakeClient.Data["/some/key"].R.Node.Value
|
||||
if expect != got {
|
||||
t.Errorf("Wanted %v, got %v", expect, got)
|
||||
|
Reference in New Issue
Block a user