Rename JSONBase -> TypeMeta in preparation for v1beta3

Will make subsequent refactor much easier
This commit is contained in:
Clayton Coleman
2014-10-07 11:12:16 -04:00
parent e294cef9d4
commit d3e51a0f24
69 changed files with 464 additions and 464 deletions

View File

@@ -36,7 +36,7 @@ type fakeClientGetSet struct {
}
type TestResource struct {
api.JSONBase `json:",inline" yaml:",inline"`
api.TypeMeta `json:",inline" yaml:",inline"`
Value int `json:"value" yaml:"value,omitempty"`
}
@@ -44,7 +44,7 @@ func (*TestResource) IsAnAPIObject() {}
var scheme *runtime.Scheme
var codec runtime.Codec
var versioner = runtime.NewJSONBaseResourceVersioner()
var versioner = runtime.NewTypeMetaResourceVersioner()
func init() {
scheme = runtime.NewScheme()
@@ -89,11 +89,11 @@ func TestExtractToList(t *testing.T) {
},
}
expect := api.PodList{
JSONBase: api.JSONBase{ResourceVersion: 10},
TypeMeta: api.TypeMeta{ResourceVersion: 10},
Items: []api.Pod{
{JSONBase: api.JSONBase{ID: "foo", ResourceVersion: 1}},
{JSONBase: api.JSONBase{ID: "bar", ResourceVersion: 2}},
{JSONBase: api.JSONBase{ID: "baz", ResourceVersion: 3}},
{TypeMeta: api.TypeMeta{ID: "foo", ResourceVersion: 1}},
{TypeMeta: api.TypeMeta{ID: "bar", ResourceVersion: 2}},
{TypeMeta: api.TypeMeta{ID: "baz", ResourceVersion: 3}},
},
}
@@ -110,7 +110,7 @@ func TestExtractToList(t *testing.T) {
func TestExtractObj(t *testing.T) {
fakeClient := NewFakeEtcdClient(t)
expect := api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
expect := api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}}
fakeClient.Set("/some/key", util.EncodeJSON(expect), 0)
helper := EtcdHelper{fakeClient, latest.Codec, versioner}
var got api.Pod
@@ -164,7 +164,7 @@ func TestExtractObjNotFoundErr(t *testing.T) {
}
func TestCreateObj(t *testing.T) {
obj := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
obj := &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}}
fakeClient := NewFakeEtcdClient(t)
helper := EtcdHelper{fakeClient, latest.Codec, versioner}
err := helper.CreateObj("/some/key", obj, 5)
@@ -185,7 +185,7 @@ func TestCreateObj(t *testing.T) {
}
func TestSetObj(t *testing.T) {
obj := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
obj := &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}}
fakeClient := NewFakeEtcdClient(t)
helper := EtcdHelper{fakeClient, latest.Codec, versioner}
err := helper.SetObj("/some/key", obj)
@@ -204,7 +204,7 @@ func TestSetObj(t *testing.T) {
}
func TestSetObjWithVersion(t *testing.T) {
obj := &api.Pod{JSONBase: api.JSONBase{ID: "foo", ResourceVersion: 1}}
obj := &api.Pod{TypeMeta: api.TypeMeta{ID: "foo", ResourceVersion: 1}}
fakeClient := NewFakeEtcdClient(t)
fakeClient.TestIndex = true
fakeClient.Data["/some/key"] = EtcdResponseWithError{
@@ -233,7 +233,7 @@ func TestSetObjWithVersion(t *testing.T) {
}
func TestSetObjWithoutResourceVersioner(t *testing.T) {
obj := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
obj := &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}}
fakeClient := NewFakeEtcdClient(t)
helper := EtcdHelper{fakeClient, latest.Codec, nil}
err := helper.SetObj("/some/key", obj)
@@ -254,11 +254,11 @@ func TestSetObjWithoutResourceVersioner(t *testing.T) {
func TestAtomicUpdate(t *testing.T) {
fakeClient := NewFakeEtcdClient(t)
fakeClient.TestIndex = true
helper := EtcdHelper{fakeClient, codec, runtime.NewJSONBaseResourceVersioner()}
helper := EtcdHelper{fakeClient, codec, runtime.NewTypeMetaResourceVersioner()}
// Create a new node.
fakeClient.ExpectNotFoundGet("/some/key")
obj := &TestResource{JSONBase: api.JSONBase{ID: "foo"}, Value: 1}
obj := &TestResource{TypeMeta: api.TypeMeta{ID: "foo"}, Value: 1}
err := helper.AtomicUpdate("/some/key", &TestResource{}, func(in runtime.Object) (runtime.Object, error) {
return obj, nil
})
@@ -277,7 +277,7 @@ func TestAtomicUpdate(t *testing.T) {
// Update an existing node.
callbackCalled := false
objUpdate := &TestResource{JSONBase: api.JSONBase{ID: "foo"}, Value: 2}
objUpdate := &TestResource{TypeMeta: api.TypeMeta{ID: "foo"}, Value: 2}
err = helper.AtomicUpdate("/some/key", &TestResource{}, func(in runtime.Object) (runtime.Object, error) {
callbackCalled = true
@@ -308,11 +308,11 @@ func TestAtomicUpdate(t *testing.T) {
func TestAtomicUpdateNoChange(t *testing.T) {
fakeClient := NewFakeEtcdClient(t)
fakeClient.TestIndex = true
helper := EtcdHelper{fakeClient, codec, runtime.NewJSONBaseResourceVersioner()}
helper := EtcdHelper{fakeClient, codec, runtime.NewTypeMetaResourceVersioner()}
// Create a new node.
fakeClient.ExpectNotFoundGet("/some/key")
obj := &TestResource{JSONBase: api.JSONBase{ID: "foo"}, Value: 1}
obj := &TestResource{TypeMeta: api.TypeMeta{ID: "foo"}, Value: 1}
err := helper.AtomicUpdate("/some/key", &TestResource{}, func(in runtime.Object) (runtime.Object, error) {
return obj, nil
})
@@ -322,7 +322,7 @@ func TestAtomicUpdateNoChange(t *testing.T) {
// Update an existing node with the same data
callbackCalled := false
objUpdate := &TestResource{JSONBase: api.JSONBase{ID: "foo"}, Value: 1}
objUpdate := &TestResource{TypeMeta: api.TypeMeta{ID: "foo"}, Value: 1}
fakeClient.Err = errors.New("should not be called")
err = helper.AtomicUpdate("/some/key", &TestResource{}, func(in runtime.Object) (runtime.Object, error) {
callbackCalled = true
@@ -339,7 +339,7 @@ func TestAtomicUpdateNoChange(t *testing.T) {
func TestAtomicUpdate_CreateCollision(t *testing.T) {
fakeClient := NewFakeEtcdClient(t)
fakeClient.TestIndex = true
helper := EtcdHelper{fakeClient, codec, runtime.NewJSONBaseResourceVersioner()}
helper := EtcdHelper{fakeClient, codec, runtime.NewTypeMetaResourceVersioner()}
fakeClient.ExpectNotFoundGet("/some/key")
@@ -365,7 +365,7 @@ func TestAtomicUpdate_CreateCollision(t *testing.T) {
}
currValue := in.(*TestResource).Value
obj := &TestResource{JSONBase: api.JSONBase{ID: "foo"}, Value: currValue + 1}
obj := &TestResource{TypeMeta: api.TypeMeta{ID: "foo"}, Value: currValue + 1}
return obj, nil
})
if err != nil {

View File

@@ -32,9 +32,9 @@ import (
func TestWatchInterpretations(t *testing.T) {
codec := latest.Codec
// Declare some pods to make the test cases compact.
podFoo := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
podBar := &api.Pod{JSONBase: api.JSONBase{ID: "bar"}}
podBaz := &api.Pod{JSONBase: api.JSONBase{ID: "baz"}}
podFoo := &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}}
podBar := &api.Pod{TypeMeta: api.TypeMeta{ID: "bar"}}
podBaz := &api.Pod{TypeMeta: api.TypeMeta{ID: "baz"}}
firstLetterIsB := func(obj runtime.Object) bool {
return obj.(*api.Pod).ID[0] == 'b'
}
@@ -236,7 +236,7 @@ func TestWatch(t *testing.T) {
}
// Test normal case
pod := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
pod := &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}}
podBytes, _ := codec.Encode(pod)
fakeClient.WatchResponse <- &etcd.Response{
Action: "set",
@@ -294,7 +294,7 @@ func TestWatchEtcdState(t *testing.T) {
{
Action: "create",
Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(codec, &api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{}})),
Value: string(runtime.EncodeOrDie(codec, &api.Endpoints{TypeMeta: api.TypeMeta{ID: "foo"}, Endpoints: []string{}})),
},
},
},
@@ -308,12 +308,12 @@ func TestWatchEtcdState(t *testing.T) {
{
Action: "compareAndSwap",
Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(codec, &api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{"127.0.0.1:9000"}})),
Value: string(runtime.EncodeOrDie(codec, &api.Endpoints{TypeMeta: api.TypeMeta{ID: "foo"}, Endpoints: []string{"127.0.0.1:9000"}})),
CreatedIndex: 1,
ModifiedIndex: 2,
},
PrevNode: &etcd.Node{
Value: string(runtime.EncodeOrDie(codec, &api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{}})),
Value: string(runtime.EncodeOrDie(codec, &api.Endpoints{TypeMeta: api.TypeMeta{ID: "foo"}, Endpoints: []string{}})),
CreatedIndex: 1,
ModifiedIndex: 1,
},
@@ -330,7 +330,7 @@ func TestWatchEtcdState(t *testing.T) {
R: &etcd.Response{
Action: "get",
Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(codec, &api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{}})),
Value: string(runtime.EncodeOrDie(codec, &api.Endpoints{TypeMeta: api.TypeMeta{ID: "foo"}, Endpoints: []string{}})),
CreatedIndex: 1,
ModifiedIndex: 1,
},
@@ -343,12 +343,12 @@ func TestWatchEtcdState(t *testing.T) {
{
Action: "compareAndSwap",
Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(codec, &api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{"127.0.0.1:9000"}})),
Value: string(runtime.EncodeOrDie(codec, &api.Endpoints{TypeMeta: api.TypeMeta{ID: "foo"}, Endpoints: []string{"127.0.0.1:9000"}})),
CreatedIndex: 1,
ModifiedIndex: 2,
},
PrevNode: &etcd.Node{
Value: string(runtime.EncodeOrDie(codec, &api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{}})),
Value: string(runtime.EncodeOrDie(codec, &api.Endpoints{TypeMeta: api.TypeMeta{ID: "foo"}, Endpoints: []string{}})),
CreatedIndex: 1,
ModifiedIndex: 1,
},
@@ -391,7 +391,7 @@ func TestWatchEtcdState(t *testing.T) {
func TestWatchFromZeroIndex(t *testing.T) {
codec := latest.Codec
pod := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
pod := &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}}
testCases := map[string]struct {
Response EtcdResponseWithError
@@ -464,7 +464,7 @@ func TestWatchFromZeroIndex(t *testing.T) {
func TestWatchListFromZeroIndex(t *testing.T) {
codec := latest.Codec
pod := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
pod := &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}}
fakeClient := NewFakeEtcdClient(t)
fakeClient.Data["/some/key"] = EtcdResponseWithError{