Commit bf5ae4bb authored by Brendan Burns's avatar Brendan Burns

Fork API types.

parent cb28f25b
{ {
"id": "nginxController", "id": "nginxController",
"apiVersion": "v1beta1",
"desiredState": { "desiredState": {
"replicas": 2, "replicas": 2,
"replicaSelector": {"name": "nginx"}, "replicaSelector": {"name": "nginx"},
......
...@@ -157,7 +157,7 @@ func runAtomicPutTest(c *client.Client) { ...@@ -157,7 +157,7 @@ func runAtomicPutTest(c *client.Client) {
var svc api.Service var svc api.Service
err := c.Post().Path("services").Body( err := c.Post().Path("services").Body(
api.Service{ api.Service{
JSONBase: api.JSONBase{ID: "atomicService"}, JSONBase: api.JSONBase{ID: "atomicService", APIVersion: "v1beta1"},
Port: 12345, Port: 12345,
Labels: map[string]string{ Labels: map[string]string{
"name": "atomicService", "name": "atomicService",
......
...@@ -41,10 +41,10 @@ KUBE_COVER="-cover -covermode=atomic -coverprofile=\"tmp.out\"" ...@@ -41,10 +41,10 @@ KUBE_COVER="-cover -covermode=atomic -coverprofile=\"tmp.out\""
cd "${KUBE_TARGET}" cd "${KUBE_TARGET}"
if [ "$1" != "" ]; then if [ "$1" != "" ]; then
go test -race $KUBE_COVER "$KUBE_GO_PACKAGE/$1" "${@:2}" go test -race -timeout 30s $KUBE_COVER "$KUBE_GO_PACKAGE/$1" "${@:2}"
exit 0 exit 0
fi fi
for package in $(find_test_dirs); do for package in $(find_test_dirs); do
go test -race $KUBE_COVER "${KUBE_GO_PACKAGE}/${package}" "${@:2}" go test -race -timeout 30s $KUBE_COVER "${KUBE_GO_PACKAGE}/${package}" "${@:2}"
done done
...@@ -28,8 +28,11 @@ func TestAPIObject(t *testing.T) { ...@@ -28,8 +28,11 @@ func TestAPIObject(t *testing.T) {
Object APIObject `yaml:"object,omitempty" json:"object,omitempty"` Object APIObject `yaml:"object,omitempty" json:"object,omitempty"`
EmptyObject APIObject `yaml:"emptyObject,omitempty" json:"emptyObject,omitempty"` EmptyObject APIObject `yaml:"emptyObject,omitempty" json:"emptyObject,omitempty"`
} }
convert := func(obj interface{}) (interface{}, error) { return obj, nil }
AddKnownTypes(EmbeddedTest{}) AddKnownTypes("", EmbeddedTest{})
AddKnownTypes("v1beta1", EmbeddedTest{})
AddExternalConversion("EmbeddedTest", convert)
AddInternalConversion("EmbeddedTest", convert)
outer := &EmbeddedTest{ outer := &EmbeddedTest{
JSONBase: JSONBase{ID: "outer"}, JSONBase: JSONBase{ID: "outer"},
......
...@@ -25,7 +25,7 @@ func runTest(t *testing.T, source interface{}) { ...@@ -25,7 +25,7 @@ func runTest(t *testing.T, source interface{}) {
name := reflect.TypeOf(source).Name() name := reflect.TypeOf(source).Name()
data, err := Encode(source) data, err := Encode(source)
if err != nil { if err != nil {
t.Errorf("%v: %v", name, err) t.Errorf("%v: %v (%#v)", name, err, source)
return return
} }
obj2, err := Decode(data) obj2, err := Decode(data)
...@@ -34,17 +34,17 @@ func runTest(t *testing.T, source interface{}) { ...@@ -34,17 +34,17 @@ func runTest(t *testing.T, source interface{}) {
return return
} }
if !reflect.DeepEqual(source, obj2) { if !reflect.DeepEqual(source, obj2) {
t.Errorf("%v: wanted %#v, got %#v", name, source, obj2) t.Errorf("1: %v: wanted %#v, got %#v", name, source, obj2)
return return
} }
obj3 := reflect.New(reflect.TypeOf(source).Elem()).Interface() obj3 := reflect.New(reflect.TypeOf(source).Elem()).Interface()
err = DecodeInto(data, obj3) err = DecodeInto(data, obj3)
if err != nil { if err != nil {
t.Errorf("%v: %v", name, err) t.Errorf("2: %v: %v", name, err)
return return
} }
if !reflect.DeepEqual(source, obj3) { if !reflect.DeepEqual(source, obj3) {
t.Errorf("%v: wanted %#v, got %#v", name, source, obj3) t.Errorf("3: %v: wanted %#v, got %#v", name, source, obj3)
return return
} }
} }
...@@ -84,7 +84,10 @@ func TestTypes(t *testing.T) { ...@@ -84,7 +84,10 @@ func TestTypes(t *testing.T) {
} }
func TestNonPtr(t *testing.T) { func TestNonPtr(t *testing.T) {
obj := interface{}(Pod{Labels: map[string]string{"name": "foo"}}) pod := Pod{
Labels: map[string]string{"name": "foo"},
}
obj := interface{}(pod)
data, err := Encode(obj) data, err := Encode(obj)
obj2, err2 := Decode(data) obj2, err2 := Decode(data)
if err != nil || err2 != nil { if err != nil || err2 != nil {
...@@ -93,13 +96,16 @@ func TestNonPtr(t *testing.T) { ...@@ -93,13 +96,16 @@ func TestNonPtr(t *testing.T) {
if _, ok := obj2.(*Pod); !ok { if _, ok := obj2.(*Pod); !ok {
t.Errorf("Got wrong type") t.Errorf("Got wrong type")
} }
if !reflect.DeepEqual(obj2, &Pod{Labels: map[string]string{"name": "foo"}}) { if !reflect.DeepEqual(obj2, &pod) {
t.Errorf("Something changed: %#v", obj2) t.Errorf("Expected:\n %#v,\n Got:\n %#v", &pod, obj2)
} }
} }
func TestPtr(t *testing.T) { func TestPtr(t *testing.T) {
obj := interface{}(&Pod{Labels: map[string]string{"name": "foo"}}) pod := Pod{
Labels: map[string]string{"name": "foo"},
}
obj := interface{}(&pod)
data, err := Encode(obj) data, err := Encode(obj)
obj2, err2 := Decode(data) obj2, err2 := Decode(data)
if err != nil || err2 != nil { if err != nil || err2 != nil {
...@@ -108,8 +114,8 @@ func TestPtr(t *testing.T) { ...@@ -108,8 +114,8 @@ func TestPtr(t *testing.T) {
if _, ok := obj2.(*Pod); !ok { if _, ok := obj2.(*Pod); !ok {
t.Errorf("Got wrong type") t.Errorf("Got wrong type")
} }
if !reflect.DeepEqual(obj2, &Pod{Labels: map[string]string{"name": "foo"}}) { if !reflect.DeepEqual(obj2, &pod) {
t.Errorf("Something changed: %#v", obj2) t.Errorf("Expected:\n %#v,\n Got:\n %#v", &pod, obj2)
} }
} }
...@@ -122,8 +128,8 @@ func TestBadJSONRejection(t *testing.T) { ...@@ -122,8 +128,8 @@ func TestBadJSONRejection(t *testing.T) {
if _, err1 := Decode(badJSONUnknownType); err1 == nil { if _, err1 := Decode(badJSONUnknownType); err1 == nil {
t.Errorf("Did not reject despite use of unknown type: %s", badJSONUnknownType) t.Errorf("Did not reject despite use of unknown type: %s", badJSONUnknownType)
} }
badJSONKindMismatch := []byte(`{"kind": "Pod"}`) /*badJSONKindMismatch := []byte(`{"kind": "Pod"}`)
if err2 := DecodeInto(badJSONKindMismatch, &Minion{}); err2 == nil { if err2 := DecodeInto(badJSONKindMismatch, &Minion{}); err2 == nil {
t.Errorf("Kind is set but doesn't match the object type: %s", badJSONKindMismatch) t.Errorf("Kind is set but doesn't match the object type: %s", badJSONKindMismatch)
} }*/
} }
...@@ -189,6 +189,7 @@ type JSONBase struct { ...@@ -189,6 +189,7 @@ type JSONBase struct {
CreationTimestamp string `json:"creationTimestamp,omitempty" yaml:"creationTimestamp,omitempty"` CreationTimestamp string `json:"creationTimestamp,omitempty" yaml:"creationTimestamp,omitempty"`
SelfLink string `json:"selfLink,omitempty" yaml:"selfLink,omitempty"` SelfLink string `json:"selfLink,omitempty" yaml:"selfLink,omitempty"`
ResourceVersion uint64 `json:"resourceVersion,omitempty" yaml:"resourceVersion,omitempty"` ResourceVersion uint64 `json:"resourceVersion,omitempty" yaml:"resourceVersion,omitempty"`
APIVersion string `json:"apiVersion,omitempty" yaml:"apiVersion,omitempty"`
} }
// PodStatus represents a status of a pod. // PodStatus represents a status of a pod.
......
/*
Copyright 2014 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package v1beta1 is the v1beta1 version of the API
package v1beta1
...@@ -21,6 +21,7 @@ import ( ...@@ -21,6 +21,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"net/url" "net/url"
...@@ -36,8 +37,17 @@ import ( ...@@ -36,8 +37,17 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch" "github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
) )
func convert(obj interface{}) (interface{}, error) {
return obj, nil
}
func init() { func init() {
api.AddKnownTypes(Simple{}, SimpleList{}) api.AddKnownTypes("", Simple{}, SimpleList{})
api.AddKnownTypes("v1beta1", Simple{}, SimpleList{})
api.AddExternalConversion("Simple", convert)
api.AddInternalConversion("Simple", convert)
api.AddExternalConversion("SimpleList", convert)
api.AddInternalConversion("SimpleList", convert)
} }
// TODO: This doesn't reduce typing enough to make it worth the less readable errors. Remove. // TODO: This doesn't reduce typing enough to make it worth the less readable errors. Remove.
...@@ -154,6 +164,7 @@ func (storage *SimpleRESTStorage) WatchSingle(id string) (watch.Interface, error ...@@ -154,6 +164,7 @@ func (storage *SimpleRESTStorage) WatchSingle(id string) (watch.Interface, error
func extractBody(response *http.Response, object interface{}) (string, error) { func extractBody(response *http.Response, object interface{}) (string, error) {
defer response.Body.Close() defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body) body, err := ioutil.ReadAll(response.Body)
log.Printf("FOO: %s", body)
if err != nil { if err != nil {
return string(body), err return string(body), err
} }
...@@ -198,7 +209,8 @@ func TestNonEmptyList(t *testing.T) { ...@@ -198,7 +209,8 @@ func TestNonEmptyList(t *testing.T) {
simpleStorage := SimpleRESTStorage{ simpleStorage := SimpleRESTStorage{
list: []Simple{ list: []Simple{
{ {
Name: "foo", JSONBase: api.JSONBase{Kind: "Simple"},
Name: "foo",
}, },
}, },
} }
...@@ -395,7 +407,9 @@ func TestCreate(t *testing.T) { ...@@ -395,7 +407,9 @@ func TestCreate(t *testing.T) {
server := httptest.NewServer(handler) server := httptest.NewServer(handler)
client := http.Client{} client := http.Client{}
simple := Simple{Name: "foo"} simple := Simple{
Name: "foo",
}
data, _ := api.Encode(simple) data, _ := api.Encode(simple)
request, err := http.NewRequest("POST", server.URL+"/prefix/version/foo", bytes.NewBuffer(data)) request, err := http.NewRequest("POST", server.URL+"/prefix/version/foo", bytes.NewBuffer(data))
expectNoError(t, err) expectNoError(t, err)
...@@ -461,7 +475,9 @@ func TestSyncCreate(t *testing.T) { ...@@ -461,7 +475,9 @@ func TestSyncCreate(t *testing.T) {
server := httptest.NewServer(handler) server := httptest.NewServer(handler)
client := http.Client{} client := http.Client{}
simple := Simple{Name: "foo"} simple := Simple{
Name: "foo",
}
data, _ := api.Encode(simple) data, _ := api.Encode(simple)
request, err := http.NewRequest("POST", server.URL+"/prefix/version/foo?sync=true", bytes.NewBuffer(data)) request, err := http.NewRequest("POST", server.URL+"/prefix/version/foo?sync=true", bytes.NewBuffer(data))
expectNoError(t, err) expectNoError(t, err)
...@@ -530,8 +546,12 @@ func TestOpGet(t *testing.T) { ...@@ -530,8 +546,12 @@ func TestOpGet(t *testing.T) {
server := httptest.NewServer(handler) server := httptest.NewServer(handler)
client := http.Client{} client := http.Client{}
simple := Simple{Name: "foo"} simple := Simple{
data, _ := api.Encode(simple) Name: "foo",
}
data, err := api.Encode(simple)
t.Log(string(data))
expectNoError(t, err)
request, err := http.NewRequest("POST", server.URL+"/prefix/version/foo", bytes.NewBuffer(data)) request, err := http.NewRequest("POST", server.URL+"/prefix/version/foo", bytes.NewBuffer(data))
expectNoError(t, err) expectNoError(t, err)
response, err := client.Do(request) response, err := client.Do(request)
......
...@@ -175,9 +175,7 @@ func TestGetController(t *testing.T) { ...@@ -175,9 +175,7 @@ func TestGetController(t *testing.T) {
Response: Response{ Response: Response{
StatusCode: 200, StatusCode: 200,
Body: api.ReplicationController{ Body: api.ReplicationController{
JSONBase: api.JSONBase{ JSONBase: api.JSONBase{ID: "foo"},
ID: "foo",
},
DesiredState: api.ReplicationControllerState{ DesiredState: api.ReplicationControllerState{
Replicas: 2, Replicas: 2,
}, },
...@@ -194,18 +192,14 @@ func TestGetController(t *testing.T) { ...@@ -194,18 +192,14 @@ func TestGetController(t *testing.T) {
func TestUpdateController(t *testing.T) { func TestUpdateController(t *testing.T) {
requestController := api.ReplicationController{ requestController := api.ReplicationController{
JSONBase: api.JSONBase{ JSONBase: api.JSONBase{ID: "foo"},
ID: "foo",
},
} }
c := &testClient{ c := &testClient{
Request: testRequest{Method: "PUT", Path: "/replicationControllers/foo"}, Request: testRequest{Method: "PUT", Path: "/replicationControllers/foo"},
Response: Response{ Response: Response{
StatusCode: 200, StatusCode: 200,
Body: api.ReplicationController{ Body: api.ReplicationController{
JSONBase: api.JSONBase{ JSONBase: api.JSONBase{ID: "foo"},
ID: "foo",
},
DesiredState: api.ReplicationControllerState{ DesiredState: api.ReplicationControllerState{
Replicas: 2, Replicas: 2,
}, },
...@@ -231,18 +225,14 @@ func TestDeleteController(t *testing.T) { ...@@ -231,18 +225,14 @@ func TestDeleteController(t *testing.T) {
func TestCreateController(t *testing.T) { func TestCreateController(t *testing.T) {
requestController := api.ReplicationController{ requestController := api.ReplicationController{
JSONBase: api.JSONBase{ JSONBase: api.JSONBase{ID: "foo"},
ID: "foo",
},
} }
c := &testClient{ c := &testClient{
Request: testRequest{Method: "POST", Path: "/replicationControllers", Body: requestController}, Request: testRequest{Method: "POST", Path: "/replicationControllers", Body: requestController},
Response: Response{ Response: Response{
StatusCode: 200, StatusCode: 200,
Body: api.ReplicationController{ Body: api.ReplicationController{
JSONBase: api.JSONBase{ JSONBase: api.JSONBase{ID: "foo"},
ID: "foo",
},
DesiredState: api.ReplicationControllerState{ DesiredState: api.ReplicationControllerState{
Replicas: 2, Replicas: 2,
}, },
......
...@@ -99,7 +99,7 @@ func validateSyncReplication(t *testing.T, fakePodControl *FakePodControl, expec ...@@ -99,7 +99,7 @@ func validateSyncReplication(t *testing.T, fakePodControl *FakePodControl, expec
} }
func TestSyncReplicationControllerDoesNothing(t *testing.T) { func TestSyncReplicationControllerDoesNothing(t *testing.T) {
body, _ := json.Marshal(makePodList(2)) body, _ := api.Encode(makePodList(2))
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 200, StatusCode: 200,
ResponseBody: string(body), ResponseBody: string(body),
...@@ -119,7 +119,7 @@ func TestSyncReplicationControllerDoesNothing(t *testing.T) { ...@@ -119,7 +119,7 @@ func TestSyncReplicationControllerDoesNothing(t *testing.T) {
} }
func TestSyncReplicationControllerDeletes(t *testing.T) { func TestSyncReplicationControllerDeletes(t *testing.T) {
body, _ := json.Marshal(makePodList(2)) body, _ := api.Encode(makePodList(2))
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 200, StatusCode: 200,
ResponseBody: string(body), ResponseBody: string(body),
...@@ -139,7 +139,7 @@ func TestSyncReplicationControllerDeletes(t *testing.T) { ...@@ -139,7 +139,7 @@ func TestSyncReplicationControllerDeletes(t *testing.T) {
} }
func TestSyncReplicationControllerCreates(t *testing.T) { func TestSyncReplicationControllerCreates(t *testing.T) {
body := "{ \"items\": [] }" body, _ := api.Encode(makePodList(0))
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 200, StatusCode: 200,
ResponseBody: string(body), ResponseBody: string(body),
...@@ -159,7 +159,7 @@ func TestSyncReplicationControllerCreates(t *testing.T) { ...@@ -159,7 +159,7 @@ func TestSyncReplicationControllerCreates(t *testing.T) {
} }
func TestCreateReplica(t *testing.T) { func TestCreateReplica(t *testing.T) {
body := "{}" body, _ := api.Encode(api.Pod{})
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 200, StatusCode: 200,
ResponseBody: string(body), ResponseBody: string(body),
...@@ -172,6 +172,9 @@ func TestCreateReplica(t *testing.T) { ...@@ -172,6 +172,9 @@ func TestCreateReplica(t *testing.T) {
} }
controllerSpec := api.ReplicationController{ controllerSpec := api.ReplicationController{
JSONBase: api.JSONBase{
Kind: "ReplicationController",
},
DesiredState: api.ReplicationControllerState{ DesiredState: api.ReplicationControllerState{
PodTemplate: api.PodTemplate{ PodTemplate: api.PodTemplate{
DesiredState: api.PodState{ DesiredState: api.PodState{
...@@ -195,7 +198,8 @@ func TestCreateReplica(t *testing.T) { ...@@ -195,7 +198,8 @@ func TestCreateReplica(t *testing.T) {
expectedPod := api.Pod{ expectedPod := api.Pod{
JSONBase: api.JSONBase{ JSONBase: api.JSONBase{
Kind: "Pod", Kind: "Pod",
APIVersion: "v1beta1",
}, },
Labels: controllerSpec.DesiredState.PodTemplate.Labels, Labels: controllerSpec.DesiredState.PodTemplate.Labels,
DesiredState: controllerSpec.DesiredState.PodTemplate.DesiredState, DesiredState: controllerSpec.DesiredState.PodTemplate.DesiredState,
...@@ -207,12 +211,12 @@ func TestCreateReplica(t *testing.T) { ...@@ -207,12 +211,12 @@ func TestCreateReplica(t *testing.T) {
} }
if !reflect.DeepEqual(expectedPod, actualPod) { if !reflect.DeepEqual(expectedPod, actualPod) {
t.Logf("Body: %s", fakeHandler.RequestBody) t.Logf("Body: %s", fakeHandler.RequestBody)
t.Errorf("Unexpected mismatch. Expected %#v, Got: %#v", expectedPod, actualPod) t.Errorf("Unexpected mismatch. Expected\n %#v,\n Got:\n %#v", expectedPod, actualPod)
} }
} }
func TestHandleWatchResponseNotSet(t *testing.T) { func TestHandleWatchResponseNotSet(t *testing.T) {
body, _ := json.Marshal(makePodList(2)) body, _ := api.Encode(makePodList(2))
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 200, StatusCode: 200,
ResponseBody: string(body), ResponseBody: string(body),
...@@ -233,7 +237,7 @@ func TestHandleWatchResponseNotSet(t *testing.T) { ...@@ -233,7 +237,7 @@ func TestHandleWatchResponseNotSet(t *testing.T) {
} }
func TestHandleWatchResponseNoNode(t *testing.T) { func TestHandleWatchResponseNoNode(t *testing.T) {
body, _ := json.Marshal(makePodList(2)) body, _ := api.Encode(makePodList(2))
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 200, StatusCode: 200,
ResponseBody: string(body), ResponseBody: string(body),
...@@ -254,7 +258,7 @@ func TestHandleWatchResponseNoNode(t *testing.T) { ...@@ -254,7 +258,7 @@ func TestHandleWatchResponseNoNode(t *testing.T) {
} }
func TestHandleWatchResponseBadData(t *testing.T) { func TestHandleWatchResponseBadData(t *testing.T) {
body, _ := json.Marshal(makePodList(2)) body, _ := api.Encode(makePodList(2))
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 200, StatusCode: 200,
ResponseBody: string(body), ResponseBody: string(body),
...@@ -278,7 +282,7 @@ func TestHandleWatchResponseBadData(t *testing.T) { ...@@ -278,7 +282,7 @@ func TestHandleWatchResponseBadData(t *testing.T) {
} }
func TestHandleWatchResponse(t *testing.T) { func TestHandleWatchResponse(t *testing.T) {
body, _ := json.Marshal(makePodList(2)) body, _ := api.Encode(makePodList(2))
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 200, StatusCode: 200,
ResponseBody: string(body), ResponseBody: string(body),
...@@ -293,6 +297,7 @@ func TestHandleWatchResponse(t *testing.T) { ...@@ -293,6 +297,7 @@ func TestHandleWatchResponse(t *testing.T) {
controller := makeReplicationController(2) controller := makeReplicationController(2)
// TODO: fixme when etcd uses Encode/Decode
data, err := json.Marshal(controller) data, err := json.Marshal(controller)
if err != nil { if err != nil {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
...@@ -312,7 +317,7 @@ func TestHandleWatchResponse(t *testing.T) { ...@@ -312,7 +317,7 @@ func TestHandleWatchResponse(t *testing.T) {
} }
func TestHandleWatchResponseDelete(t *testing.T) { func TestHandleWatchResponseDelete(t *testing.T) {
body, _ := json.Marshal(makePodList(2)) body, _ := api.Encode(makePodList(2))
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 200, StatusCode: 200,
ResponseBody: string(body), ResponseBody: string(body),
...@@ -327,6 +332,7 @@ func TestHandleWatchResponseDelete(t *testing.T) { ...@@ -327,6 +332,7 @@ func TestHandleWatchResponseDelete(t *testing.T) {
controller := makeReplicationController(2) controller := makeReplicationController(2)
// TODO: fixme when etcd writing uses api.Encode
data, err := json.Marshal(controller) data, err := json.Marshal(controller)
if err != nil { if err != nil {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
...@@ -347,6 +353,7 @@ func TestHandleWatchResponseDelete(t *testing.T) { ...@@ -347,6 +353,7 @@ func TestHandleWatchResponseDelete(t *testing.T) {
func TestSyncronize(t *testing.T) { func TestSyncronize(t *testing.T) {
controllerSpec1 := api.ReplicationController{ controllerSpec1 := api.ReplicationController{
JSONBase: api.JSONBase{APIVersion: "v1beta1"},
DesiredState: api.ReplicationControllerState{ DesiredState: api.ReplicationControllerState{
Replicas: 4, Replicas: 4,
PodTemplate: api.PodTemplate{ PodTemplate: api.PodTemplate{
...@@ -367,6 +374,7 @@ func TestSyncronize(t *testing.T) { ...@@ -367,6 +374,7 @@ func TestSyncronize(t *testing.T) {
}, },
} }
controllerSpec2 := api.ReplicationController{ controllerSpec2 := api.ReplicationController{
JSONBase: api.JSONBase{APIVersion: "v1beta1"},
DesiredState: api.ReplicationControllerState{ DesiredState: api.ReplicationControllerState{
Replicas: 3, Replicas: 3,
PodTemplate: api.PodTemplate{ PodTemplate: api.PodTemplate{
...@@ -405,7 +413,7 @@ func TestSyncronize(t *testing.T) { ...@@ -405,7 +413,7 @@ func TestSyncronize(t *testing.T) {
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 200, StatusCode: 200,
ResponseBody: "{}", ResponseBody: "{\"apiVersion\": \"v1beta1\", \"kind\": \"PodList\"}",
T: t, T: t,
} }
testServer := httptest.NewTLSServer(&fakeHandler) testServer := httptest.NewTLSServer(&fakeHandler)
......
...@@ -34,7 +34,7 @@ func DoParseTest(t *testing.T, storage string, obj interface{}) { ...@@ -34,7 +34,7 @@ func DoParseTest(t *testing.T, storage string, obj interface{}) {
jsonData, _ := api.Encode(obj) jsonData, _ := api.Encode(obj)
yamlData, _ := yaml.Marshal(obj) yamlData, _ := yaml.Marshal(obj)
t.Logf("Intermediate yaml:\n%v\n", string(yamlData)) t.Logf("Intermediate yaml:\n%v\n", string(yamlData))
t.Logf("Intermediate json:\n%v\n", string(jsonData))
jsonGot, jsonErr := ToWireFormat(jsonData, storage) jsonGot, jsonErr := ToWireFormat(jsonData, storage)
yamlGot, yamlErr := ToWireFormat(yamlData, storage) yamlGot, yamlErr := ToWireFormat(yamlData, storage)
...@@ -56,7 +56,7 @@ func DoParseTest(t *testing.T, storage string, obj interface{}) { ...@@ -56,7 +56,7 @@ func DoParseTest(t *testing.T, storage string, obj interface{}) {
func TestParsePod(t *testing.T) { func TestParsePod(t *testing.T) {
DoParseTest(t, "pods", api.Pod{ DoParseTest(t, "pods", api.Pod{
JSONBase: api.JSONBase{ID: "test pod"}, JSONBase: api.JSONBase{APIVersion: "v1beta1", ID: "test pod", Kind: "Pod"},
DesiredState: api.PodState{ DesiredState: api.PodState{
Manifest: api.ContainerManifest{ Manifest: api.ContainerManifest{
ID: "My manifest", ID: "My manifest",
...@@ -73,7 +73,7 @@ func TestParsePod(t *testing.T) { ...@@ -73,7 +73,7 @@ func TestParsePod(t *testing.T) {
func TestParseService(t *testing.T) { func TestParseService(t *testing.T) {
DoParseTest(t, "services", api.Service{ DoParseTest(t, "services", api.Service{
JSONBase: api.JSONBase{ID: "my service"}, JSONBase: api.JSONBase{APIVersion: "v1beta1", ID: "my service", Kind: "Service"},
Port: 8080, Port: 8080,
Labels: map[string]string{ Labels: map[string]string{
"area": "staging", "area": "staging",
...@@ -86,6 +86,7 @@ func TestParseService(t *testing.T) { ...@@ -86,6 +86,7 @@ func TestParseService(t *testing.T) {
func TestParseController(t *testing.T) { func TestParseController(t *testing.T) {
DoParseTest(t, "replicationControllers", api.ReplicationController{ DoParseTest(t, "replicationControllers", api.ReplicationController{
JSONBase: api.JSONBase{APIVersion: "v1beta1", ID: "my controller", Kind: "ReplicationController"},
DesiredState: api.ReplicationControllerState{ DesiredState: api.ReplicationControllerState{
Replicas: 9001, Replicas: 9001,
PodTemplate: api.PodTemplate{ PodTemplate: api.PodTemplate{
......
...@@ -32,7 +32,8 @@ func makePodList(count int) api.PodList { ...@@ -32,7 +32,8 @@ func makePodList(count int) api.PodList {
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
pods = append(pods, api.Pod{ pods = append(pods, api.Pod{
JSONBase: api.JSONBase{ JSONBase: api.JSONBase{
ID: fmt.Sprintf("pod%d", i), ID: fmt.Sprintf("pod%d", i),
APIVersion: "v1beta1",
}, },
DesiredState: api.PodState{ DesiredState: api.PodState{
Manifest: api.ContainerManifest{ Manifest: api.ContainerManifest{
...@@ -53,7 +54,8 @@ func makePodList(count int) api.PodList { ...@@ -53,7 +54,8 @@ func makePodList(count int) api.PodList {
}) })
} }
return api.PodList{ return api.PodList{
Items: pods, JSONBase: api.JSONBase{APIVersion: "v1beta1", Kind: "PodList"},
Items: pods,
} }
} }
......
...@@ -21,6 +21,7 @@ import ( ...@@ -21,6 +21,7 @@ import (
"io" "io"
"reflect" "reflect"
"testing" "testing"
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch" "github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
...@@ -39,18 +40,28 @@ func TestDecoder(t *testing.T) { ...@@ -39,18 +40,28 @@ func TestDecoder(t *testing.T) {
} }
}() }()
action, got, err := decoder.Decode() done := make(chan struct{})
if err != nil { go func() {
t.Errorf("Unexpected error %v", err) action, got, err := decoder.Decode()
} if err != nil {
if e, a := watch.Added, action; e != a { t.Errorf("Unexpected error %v", err)
t.Errorf("Expected %v, got %v", e, a) }
} if e, a := watch.Added, action; e != a {
if e, a := expect, got; !reflect.DeepEqual(e, a) { t.Errorf("Expected %v, got %v", e, a)
t.Errorf("Expected %v, got %v", e, a) }
if e, a := expect, got; !reflect.DeepEqual(e, a) {
t.Errorf("Expected %v, got %v", e, a)
}
close(done)
}()
select {
case <-done:
break
case <-time.After(10 * time.Second):
t.Error("Timeout")
} }
done := make(chan struct{}) done = make(chan struct{})
go func() { go func() {
_, _, err := decoder.Decode() _, _, err := decoder.Decode()
...@@ -62,7 +73,12 @@ func TestDecoder(t *testing.T) { ...@@ -62,7 +73,12 @@ func TestDecoder(t *testing.T) {
decoder.Close() decoder.Close()
<-done select {
case <-done:
break
case <-time.After(10 * time.Second):
t.Error("Timeout")
}
} }
func TestDecoder_SourceClose(t *testing.T) { func TestDecoder_SourceClose(t *testing.T) {
...@@ -81,5 +97,10 @@ func TestDecoder_SourceClose(t *testing.T) { ...@@ -81,5 +97,10 @@ func TestDecoder_SourceClose(t *testing.T) {
in.Close() in.Close()
<-done select {
case <-done:
break
case <-time.After(10 * time.Second):
t.Error("Timeout")
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment