mirror of https://github.com/k3s-io/k3s
Merge pull request #751 from smarterclayton/remove_expect_no_error
Remove expectNoError from pkg/registrypull/6/head
commit
97a6aaba53
|
@ -44,7 +44,9 @@ func TestCachingHit(t *testing.T) {
|
|||
minions: expected,
|
||||
}
|
||||
list, err := cache.List()
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(list, expected) {
|
||||
t.Errorf("expected: %v, got %v", expected, list)
|
||||
}
|
||||
|
@ -65,7 +67,10 @@ func TestCachingMiss(t *testing.T) {
|
|||
}
|
||||
fakeClock.now = time.Unix(3, 0)
|
||||
list, err := cache.List()
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(list, fakeRegistry.minions) {
|
||||
t.Errorf("expected: %v, got %v", fakeRegistry.minions, list)
|
||||
}
|
||||
|
@ -85,9 +90,15 @@ func TestCachingInsert(t *testing.T) {
|
|||
minions: expected,
|
||||
}
|
||||
err := cache.Insert("foo")
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
list, err := cache.List()
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(list, fakeRegistry.minions) {
|
||||
t.Errorf("expected: %v, got %v", fakeRegistry.minions, list)
|
||||
}
|
||||
|
@ -107,9 +118,15 @@ func TestCachingDelete(t *testing.T) {
|
|||
minions: expected,
|
||||
}
|
||||
err := cache.Delete("m2")
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
list, err := cache.List()
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(list, fakeRegistry.minions) {
|
||||
t.Errorf("expected: %v, got %v", fakeRegistry.minions, list)
|
||||
}
|
||||
|
|
|
@ -29,10 +29,15 @@ func TestCloudList(t *testing.T) {
|
|||
Machines: instances,
|
||||
}
|
||||
registry, err := MakeCloudMinionRegistry(&fakeCloud, ".*")
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
list, err := registry.List()
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(list, instances) {
|
||||
t.Errorf("Unexpected inequality: %#v, %#v", list, instances)
|
||||
}
|
||||
|
@ -44,16 +49,24 @@ func TestCloudContains(t *testing.T) {
|
|||
Machines: instances,
|
||||
}
|
||||
registry, err := MakeCloudMinionRegistry(&fakeCloud, ".*")
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
contains, err := registry.Contains("m1")
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if !contains {
|
||||
t.Errorf("Unexpected !contains")
|
||||
}
|
||||
|
||||
contains, err = registry.Contains("m100")
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if contains {
|
||||
t.Errorf("Unexpected contains")
|
||||
}
|
||||
|
@ -65,10 +78,15 @@ func TestCloudListRegexp(t *testing.T) {
|
|||
Machines: instances,
|
||||
}
|
||||
registry, err := MakeCloudMinionRegistry(&fakeCloud, "m[0-9]+")
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
list, err := registry.List()
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
expectedList := []string{"m1", "m2"}
|
||||
if !reflect.DeepEqual(list, expectedList) {
|
||||
t.Errorf("Unexpected inequality: %#v, %#v", list, expectedList)
|
||||
|
|
|
@ -79,7 +79,10 @@ func TestListEmptyControllerList(t *testing.T) {
|
|||
registry: &mockRegistry,
|
||||
}
|
||||
controllers, err := storage.List(labels.Everything())
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(controllers.(api.ReplicationControllerList).Items) != 0 {
|
||||
t.Errorf("Unexpected non-zero ctrl list: %#v", controllers)
|
||||
}
|
||||
|
@ -105,7 +108,10 @@ func TestListControllerList(t *testing.T) {
|
|||
}
|
||||
controllersObj, err := storage.List(labels.Everything())
|
||||
controllers := controllersObj.(api.ReplicationControllerList)
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(controllers.Items) != 2 {
|
||||
t.Errorf("Unexpected controller list: %#v", controllers)
|
||||
}
|
||||
|
@ -128,9 +134,15 @@ func TestExtractControllerJson(t *testing.T) {
|
|||
},
|
||||
}
|
||||
body, err := api.Encode(&controller)
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
controllerOut, err := storage.Extract(body)
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(controller, controllerOut) {
|
||||
t.Errorf("Expected %#v, found %#v", controller, controllerOut)
|
||||
}
|
||||
|
@ -173,18 +185,35 @@ func TestControllerParsing(t *testing.T) {
|
|||
}
|
||||
file, err := ioutil.TempFile("", "controller")
|
||||
fileName := file.Name()
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
data, err := json.Marshal(expectedController)
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
_, err = file.Write(data)
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
err = file.Close()
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
data, err = ioutil.ReadFile(fileName)
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
var controller api.ReplicationController
|
||||
err = json.Unmarshal(data, &controller)
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(controller, expectedController) {
|
||||
t.Errorf("Parsing failed: %s %#v %#v", string(data), controller, expectedController)
|
||||
|
@ -232,7 +261,9 @@ func TestCreateController(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
select {
|
||||
case <-time.After(time.Millisecond * 100):
|
||||
|
|
|
@ -79,12 +79,18 @@ func TestFindPort(t *testing.T) {
|
|||
},
|
||||
}
|
||||
port, err := findPort(&manifest, util.IntOrString{Kind: util.IntstrString, StrVal: "foo"})
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if port != 8080 {
|
||||
t.Errorf("Expected 8080, Got %d", port)
|
||||
}
|
||||
port, err = findPort(&manifest, util.IntOrString{Kind: util.IntstrString, StrVal: "bar"})
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if port != 8000 {
|
||||
t.Errorf("Expected 8000, Got %d", port)
|
||||
}
|
||||
|
@ -101,12 +107,18 @@ func TestFindPort(t *testing.T) {
|
|||
t.Error("unexpected non-error")
|
||||
}
|
||||
port, err = findPort(&manifest, util.IntOrString{Kind: util.IntstrString, StrVal: ""})
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if port != 8080 {
|
||||
t.Errorf("Expected 8080, Got %d", port)
|
||||
}
|
||||
port, err = findPort(&manifest, util.IntOrString{})
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if port != 8080 {
|
||||
t.Errorf("Expected 8080, Got %d", port)
|
||||
}
|
||||
|
@ -125,7 +137,10 @@ func TestSyncEndpointsEmpty(t *testing.T) {
|
|||
|
||||
endpoints := MakeEndpointController(&serviceRegistry, client)
|
||||
err := endpoints.SyncServiceEndpoints()
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestSyncEndpointsError(t *testing.T) {
|
||||
|
@ -171,7 +186,10 @@ func TestSyncEndpointsItems(t *testing.T) {
|
|||
|
||||
endpoints := MakeEndpointController(&serviceRegistry, client)
|
||||
err := endpoints.SyncServiceEndpoints()
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(serviceRegistry.endpoints.Endpoints) != 1 {
|
||||
t.Errorf("Unexpected endpoints update: %#v", serviceRegistry.endpoints)
|
||||
}
|
||||
|
|
|
@ -40,7 +40,10 @@ func TestEtcdGetPod(t *testing.T) {
|
|||
fakeClient.Set("/registry/hosts/machine/pods/foo", util.MakeJSONString(api.Pod{JSONBase: api.JSONBase{ID: "foo"}}), 0)
|
||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||
pod, err := registry.GetPod("foo")
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if pod.ID != "foo" {
|
||||
t.Errorf("Unexpected pod: %#v", pod)
|
||||
}
|
||||
|
@ -85,20 +88,29 @@ func TestEtcdCreatePod(t *testing.T) {
|
|||
},
|
||||
},
|
||||
})
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
resp, err := fakeClient.Get("/registry/hosts/machine/pods/foo", false, false)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error %v", err)
|
||||
}
|
||||
var pod api.Pod
|
||||
err = api.DecodeInto([]byte(resp.Node.Value), &pod)
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if pod.ID != "foo" {
|
||||
t.Errorf("Unexpected pod: %#v %s", pod, resp.Node.Value)
|
||||
}
|
||||
var manifests api.ContainerManifestList
|
||||
resp, err = fakeClient.Get("/registry/hosts/machine/kubelet", false, false)
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
err = api.DecodeInto([]byte(resp.Node.Value), &manifests)
|
||||
if len(manifests.Items) != 1 || manifests.Items[0].ID != "foo" {
|
||||
t.Errorf("Unexpected manifest list: %#v", manifests)
|
||||
|
@ -188,20 +200,29 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) {
|
|||
},
|
||||
},
|
||||
})
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
resp, err := fakeClient.Get("/registry/hosts/machine/pods/foo", false, false)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error %v", err)
|
||||
}
|
||||
var pod api.Pod
|
||||
err = api.DecodeInto([]byte(resp.Node.Value), &pod)
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if pod.ID != "foo" {
|
||||
t.Errorf("Unexpected pod: %#v %s", pod, resp.Node.Value)
|
||||
}
|
||||
var manifests api.ContainerManifestList
|
||||
resp, err = fakeClient.Get("/registry/hosts/machine/kubelet", false, false)
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
err = api.DecodeInto([]byte(resp.Node.Value), &manifests)
|
||||
if len(manifests.Items) != 1 || manifests.Items[0].ID != "foo" {
|
||||
t.Errorf("Unexpected manifest list: %#v", manifests)
|
||||
|
@ -237,20 +258,29 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) {
|
|||
},
|
||||
},
|
||||
})
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
resp, err := fakeClient.Get("/registry/hosts/machine/pods/foo", false, false)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error %v", err)
|
||||
}
|
||||
var pod api.Pod
|
||||
err = api.DecodeInto([]byte(resp.Node.Value), &pod)
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if pod.ID != "foo" {
|
||||
t.Errorf("Unexpected pod: %#v %s", pod, resp.Node.Value)
|
||||
}
|
||||
var manifests api.ContainerManifestList
|
||||
resp, err = fakeClient.Get("/registry/hosts/machine/kubelet", false, false)
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
err = api.DecodeInto([]byte(resp.Node.Value), &manifests)
|
||||
if len(manifests.Items) != 2 || manifests.Items[1].ID != "foo" {
|
||||
t.Errorf("Unexpected manifest list: %#v", manifests)
|
||||
|
@ -268,7 +298,10 @@ func TestEtcdDeletePod(t *testing.T) {
|
|||
}), 0)
|
||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||
err := registry.DeletePod("foo")
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(fakeClient.DeletedKeys) != 1 {
|
||||
t.Errorf("Expected 1 delete, found %#v", fakeClient.DeletedKeys)
|
||||
} else if fakeClient.DeletedKeys[0] != key {
|
||||
|
@ -297,7 +330,10 @@ func TestEtcdDeletePodMultipleContainers(t *testing.T) {
|
|||
}), 0)
|
||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||
err := registry.DeletePod("foo")
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(fakeClient.DeletedKeys) != 1 {
|
||||
t.Errorf("Expected 1 delete, found %#v", fakeClient.DeletedKeys)
|
||||
}
|
||||
|
@ -331,7 +367,10 @@ func TestEtcdEmptyListPods(t *testing.T) {
|
|||
}
|
||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||
pods, err := registry.ListPods(labels.Everything())
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(pods) != 0 {
|
||||
t.Errorf("Unexpected pod list: %#v", pods)
|
||||
}
|
||||
|
@ -346,7 +385,10 @@ func TestEtcdListPodsNotFound(t *testing.T) {
|
|||
}
|
||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||
pods, err := registry.ListPods(labels.Everything())
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(pods) != 0 {
|
||||
t.Errorf("Unexpected pod list: %#v", pods)
|
||||
}
|
||||
|
@ -372,7 +414,10 @@ func TestEtcdListPods(t *testing.T) {
|
|||
}
|
||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||
pods, err := registry.ListPods(labels.Everything())
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(pods) != 2 || pods[0].ID != "foo" || pods[1].ID != "bar" {
|
||||
t.Errorf("Unexpected pod list: %#v", pods)
|
||||
}
|
||||
|
@ -391,7 +436,10 @@ func TestEtcdListControllersNotFound(t *testing.T) {
|
|||
}
|
||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||
controllers, err := registry.ListControllers()
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(controllers) != 0 {
|
||||
t.Errorf("Unexpected controller list: %#v", controllers)
|
||||
}
|
||||
|
@ -406,7 +454,10 @@ func TestEtcdListServicesNotFound(t *testing.T) {
|
|||
}
|
||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||
services, err := registry.ListServices()
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(services.Items) != 0 {
|
||||
t.Errorf("Unexpected controller list: %#v", services)
|
||||
}
|
||||
|
@ -432,7 +483,10 @@ func TestEtcdListControllers(t *testing.T) {
|
|||
}
|
||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||
controllers, err := registry.ListControllers()
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(controllers) != 2 || controllers[0].ID != "foo" || controllers[1].ID != "bar" {
|
||||
t.Errorf("Unexpected controller list: %#v", controllers)
|
||||
}
|
||||
|
@ -443,7 +497,10 @@ func TestEtcdGetController(t *testing.T) {
|
|||
fakeClient.Set("/registry/controllers/foo", util.MakeJSONString(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}), 0)
|
||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||
ctrl, err := registry.GetController("foo")
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if ctrl.ID != "foo" {
|
||||
t.Errorf("Unexpected controller: %#v", ctrl)
|
||||
}
|
||||
|
@ -471,7 +528,10 @@ func TestEtcdDeleteController(t *testing.T) {
|
|||
fakeClient := tools.MakeFakeEtcdClient(t)
|
||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||
err := registry.DeleteController("foo")
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(fakeClient.DeletedKeys) != 1 {
|
||||
t.Errorf("Expected 1 delete, found %#v", fakeClient.DeletedKeys)
|
||||
}
|
||||
|
@ -489,14 +549,20 @@ func TestEtcdCreateController(t *testing.T) {
|
|||
ID: "foo",
|
||||
},
|
||||
})
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
resp, err := fakeClient.Get("/registry/controllers/foo", false, false)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error %v", err)
|
||||
}
|
||||
var ctrl api.ReplicationController
|
||||
err = api.DecodeInto([]byte(resp.Node.Value), &ctrl)
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if ctrl.ID != "foo" {
|
||||
t.Errorf("Unexpected pod: %#v %s", ctrl, resp.Node.Value)
|
||||
}
|
||||
|
@ -512,7 +578,10 @@ func TestEtcdUpdateController(t *testing.T) {
|
|||
Replicas: 2,
|
||||
},
|
||||
})
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
ctrl, err := registry.GetController("foo")
|
||||
if ctrl.DesiredState.Replicas != 2 {
|
||||
t.Errorf("Unexpected controller: %#v", ctrl)
|
||||
|
@ -539,7 +608,10 @@ func TestEtcdListServices(t *testing.T) {
|
|||
}
|
||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||
services, err := registry.ListServices()
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(services.Items) != 2 || services.Items[0].ID != "foo" || services.Items[1].ID != "bar" {
|
||||
t.Errorf("Unexpected pod list: %#v", services)
|
||||
}
|
||||
|
@ -557,12 +629,21 @@ func TestEtcdCreateService(t *testing.T) {
|
|||
err := registry.CreateService(api.Service{
|
||||
JSONBase: api.JSONBase{ID: "foo"},
|
||||
})
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
resp, err := fakeClient.Get("/registry/services/specs/foo", false, false)
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
var service api.Service
|
||||
err = api.DecodeInto([]byte(resp.Node.Value), &service)
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if service.ID != "foo" {
|
||||
t.Errorf("Unexpected service: %#v %s", service, resp.Node.Value)
|
||||
}
|
||||
|
@ -573,7 +654,10 @@ func TestEtcdGetService(t *testing.T) {
|
|||
fakeClient.Set("/registry/services/specs/foo", util.MakeJSONString(api.Service{JSONBase: api.JSONBase{ID: "foo"}}), 0)
|
||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||
service, err := registry.GetService("foo")
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if service.ID != "foo" {
|
||||
t.Errorf("Unexpected pod: %#v", service)
|
||||
}
|
||||
|
@ -598,7 +682,10 @@ func TestEtcdDeleteService(t *testing.T) {
|
|||
fakeClient := tools.MakeFakeEtcdClient(t)
|
||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||
err := registry.DeleteService("foo")
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(fakeClient.DeletedKeys) != 2 {
|
||||
t.Errorf("Expected 2 delete, found %#v", fakeClient.DeletedKeys)
|
||||
}
|
||||
|
@ -626,9 +713,15 @@ func TestEtcdUpdateService(t *testing.T) {
|
|||
},
|
||||
}
|
||||
err := registry.UpdateService(testService)
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
svc, err := registry.GetService("foo")
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(*svc, testService) {
|
||||
t.Errorf("Unexpected service: got %#v, wanted %#v", svc, testService)
|
||||
}
|
||||
|
@ -642,7 +735,10 @@ func TestEtcdUpdateEndpoints(t *testing.T) {
|
|||
Endpoints: []string{"baz", "bar"},
|
||||
}
|
||||
err := registry.UpdateEndpoints(endpoints)
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
response, err := fakeClient.Get("/registry/services/endpoints/foo", false, false)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error %v", err)
|
||||
|
|
|
@ -47,21 +47,32 @@ func TestBasicDelegation(t *testing.T) {
|
|||
}
|
||||
|
||||
list, err := healthy.List()
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(list, mockMinionRegistry.minions) {
|
||||
t.Errorf("Expected %v, Got %v", mockMinionRegistry.minions, list)
|
||||
}
|
||||
err = healthy.Insert("foo")
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
ok, err := healthy.Contains("m1")
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if !ok {
|
||||
t.Errorf("Unexpected absence of 'm1'")
|
||||
}
|
||||
|
||||
ok, err = healthy.Contains("m5")
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if ok {
|
||||
t.Errorf("Unexpected presence of 'm5'")
|
||||
}
|
||||
|
@ -91,12 +102,18 @@ func TestFiltering(t *testing.T) {
|
|||
|
||||
expected := []string{"m2", "m3"}
|
||||
list, err := healthy.List()
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(list, expected) {
|
||||
t.Errorf("Expected %v, Got %v", expected, list)
|
||||
}
|
||||
ok, err := healthy.Contains("m1")
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if ok {
|
||||
t.Errorf("Unexpected presence of 'm1'")
|
||||
}
|
||||
|
|
|
@ -42,7 +42,10 @@ func TestMakeManifestNoServices(t *testing.T) {
|
|||
},
|
||||
},
|
||||
})
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
container := manifest.Containers[0]
|
||||
if len(container.Env) != 1 ||
|
||||
container.Env[0].Name != "SERVICE_HOST" ||
|
||||
|
@ -84,7 +87,10 @@ func TestMakeManifestServices(t *testing.T) {
|
|||
},
|
||||
},
|
||||
})
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
container := manifest.Containers[0]
|
||||
envs := []api.EnvVar{
|
||||
{
|
||||
|
@ -162,7 +168,10 @@ func TestMakeManifestServicesExistingEnvVar(t *testing.T) {
|
|||
},
|
||||
},
|
||||
})
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
container := manifest.Containers[0]
|
||||
|
||||
envs := []api.EnvVar{
|
||||
|
|
|
@ -27,7 +27,10 @@ import (
|
|||
func TestListPodsEmpty(t *testing.T) {
|
||||
registry := MakeMemoryRegistry()
|
||||
pods, err := registry.ListPods(labels.Everything())
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(pods) != 0 {
|
||||
t.Errorf("Unexpected pod list: %#v", pods)
|
||||
}
|
||||
|
@ -37,7 +40,10 @@ func TestMemoryListPods(t *testing.T) {
|
|||
registry := MakeMemoryRegistry()
|
||||
registry.CreatePod("machine", api.Pod{JSONBase: api.JSONBase{ID: "foo"}})
|
||||
pods, err := registry.ListPods(labels.Everything())
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(pods) != 1 || pods[0].ID != "foo" {
|
||||
t.Errorf("Unexpected pod list: %#v", pods)
|
||||
}
|
||||
|
@ -60,7 +66,10 @@ func TestMemorySetGetPods(t *testing.T) {
|
|||
expectedPod := api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
|
||||
registry.CreatePod("machine", expectedPod)
|
||||
pod, err := registry.GetPod("foo")
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if expectedPod.ID != pod.ID {
|
||||
t.Errorf("Unexpected pod, expected %#v, actual %#v", expectedPod, pod)
|
||||
}
|
||||
|
@ -100,7 +109,10 @@ func TestMemorySetUpdateGetPods(t *testing.T) {
|
|||
registry.CreatePod("machine", oldPod)
|
||||
registry.UpdatePod(expectedPod)
|
||||
pod, err := registry.GetPod("foo")
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if expectedPod.ID != pod.ID || pod.DesiredState.Host != expectedPod.DesiredState.Host {
|
||||
t.Errorf("Unexpected pod, expected %#v, actual %#v", expectedPod, pod)
|
||||
}
|
||||
|
@ -136,7 +148,10 @@ func TestMemorySetDeleteGetPods(t *testing.T) {
|
|||
func TestListControllersEmpty(t *testing.T) {
|
||||
registry := MakeMemoryRegistry()
|
||||
ctls, err := registry.ListControllers()
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(ctls) != 0 {
|
||||
t.Errorf("Unexpected controller list: %#v", ctls)
|
||||
}
|
||||
|
@ -146,7 +161,10 @@ func TestMemoryListControllers(t *testing.T) {
|
|||
registry := MakeMemoryRegistry()
|
||||
registry.CreateController(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}})
|
||||
ctls, err := registry.ListControllers()
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(ctls) != 1 || ctls[0].ID != "foo" {
|
||||
t.Errorf("Unexpected controller list: %#v", ctls)
|
||||
}
|
||||
|
@ -169,7 +187,10 @@ func TestMemorySetGetControllers(t *testing.T) {
|
|||
expectedController := api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}
|
||||
registry.CreateController(expectedController)
|
||||
ctl, err := registry.GetController("foo")
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if expectedController.ID != ctl.ID {
|
||||
t.Errorf("Unexpected controller, expected %#v, actual %#v", expectedController, ctl)
|
||||
}
|
||||
|
@ -209,7 +230,10 @@ func TestMemorySetUpdateGetControllers(t *testing.T) {
|
|||
registry.CreateController(oldController)
|
||||
registry.UpdateController(expectedController)
|
||||
ctl, err := registry.GetController("foo")
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if expectedController.ID != ctl.ID || ctl.DesiredState.Replicas != expectedController.DesiredState.Replicas {
|
||||
t.Errorf("Unexpected controller, expected %#v, actual %#v", expectedController, ctl)
|
||||
}
|
||||
|
@ -245,7 +269,10 @@ func TestMemorySetDeleteGetControllers(t *testing.T) {
|
|||
func TestListServicesEmpty(t *testing.T) {
|
||||
registry := MakeMemoryRegistry()
|
||||
svcs, err := registry.ListServices()
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(svcs.Items) != 0 {
|
||||
t.Errorf("Unexpected service list: %#v", svcs)
|
||||
}
|
||||
|
@ -255,7 +282,10 @@ func TestMemoryListServices(t *testing.T) {
|
|||
registry := MakeMemoryRegistry()
|
||||
registry.CreateService(api.Service{JSONBase: api.JSONBase{ID: "foo"}})
|
||||
svcs, err := registry.ListServices()
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(svcs.Items) != 1 || svcs.Items[0].ID != "foo" {
|
||||
t.Errorf("Unexpected service list: %#v", svcs)
|
||||
}
|
||||
|
@ -278,7 +308,10 @@ func TestMemorySetGetServices(t *testing.T) {
|
|||
expectedService := api.Service{JSONBase: api.JSONBase{ID: "foo"}}
|
||||
registry.CreateService(expectedService)
|
||||
svc, err := registry.GetService("foo")
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if expectedService.ID != svc.ID {
|
||||
t.Errorf("Unexpected service, expected %#v, actual %#v", expectedService, svc)
|
||||
}
|
||||
|
@ -314,7 +347,10 @@ func TestMemorySetUpdateGetServices(t *testing.T) {
|
|||
registry.CreateService(oldService)
|
||||
registry.UpdateService(expectedService)
|
||||
svc, err := registry.GetService("foo")
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if expectedService.ID != svc.ID || svc.Port != expectedService.Port {
|
||||
t.Errorf("Unexpected service, expected %#v, actual %#v", expectedService, svc)
|
||||
}
|
||||
|
|
|
@ -29,12 +29,6 @@ import (
|
|||
"github.com/fsouza/go-dockerclient"
|
||||
)
|
||||
|
||||
func expectNoError(t *testing.T, err error) {
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %#v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func expectApiStatusError(t *testing.T, ch <-chan interface{}, msg string) {
|
||||
out := <-ch
|
||||
status, ok := out.(*api.Status)
|
||||
|
@ -170,7 +164,10 @@ func TestListEmptyPodList(t *testing.T) {
|
|||
registry: &mockRegistry,
|
||||
}
|
||||
pods, err := storage.List(labels.Everything())
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(pods.(api.PodList).Items) != 0 {
|
||||
t.Errorf("Unexpected non-zero pod list: %#v", pods)
|
||||
}
|
||||
|
@ -196,7 +193,10 @@ func TestListPodList(t *testing.T) {
|
|||
}
|
||||
podsObj, err := storage.List(labels.Everything())
|
||||
pods := podsObj.(api.PodList)
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(pods.Items) != 2 {
|
||||
t.Errorf("Unexpected pod list: %#v", pods)
|
||||
}
|
||||
|
@ -219,9 +219,15 @@ func TestExtractJson(t *testing.T) {
|
|||
},
|
||||
}
|
||||
body, err := api.Encode(&pod)
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
podOut, err := storage.Extract(body)
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(pod, podOut) {
|
||||
t.Errorf("Expected %#v, found %#v", pod, podOut)
|
||||
}
|
||||
|
@ -238,7 +244,10 @@ func TestGetPod(t *testing.T) {
|
|||
}
|
||||
obj, err := storage.Get("foo")
|
||||
pod := obj.(*api.Pod)
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(*mockRegistry.pod, *pod) {
|
||||
t.Errorf("Unexpected pod. Expected %#v, Got %#v", *mockRegistry.pod, *pod)
|
||||
}
|
||||
|
@ -257,7 +266,10 @@ func TestGetPodCloud(t *testing.T) {
|
|||
}
|
||||
obj, err := storage.Get("foo")
|
||||
pod := obj.(*api.Pod)
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(*mockRegistry.pod, *pod) {
|
||||
t.Errorf("Unexpected pod. Expected %#v, Got %#v", *mockRegistry.pod, *pod)
|
||||
}
|
||||
|
@ -414,7 +426,10 @@ func TestCreatePod(t *testing.T) {
|
|||
DesiredState: desiredState,
|
||||
}
|
||||
channel, err := storage.Create(pod)
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
select {
|
||||
case <-time.After(time.Millisecond * 100):
|
||||
// Do nothing, this is expected.
|
||||
|
|
|
@ -44,7 +44,10 @@ func TestServiceRegistry(t *testing.T) {
|
|||
t.Errorf("Unexpected call(s): %#v", fakeCloud.Calls)
|
||||
}
|
||||
srv, err := memory.GetService(svc.ID)
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if srv == nil {
|
||||
t.Errorf("Failed to find service: %s", svc.ID)
|
||||
}
|
||||
|
@ -123,7 +126,10 @@ func TestServiceRegistryExternalService(t *testing.T) {
|
|||
t.Errorf("Unexpected call(s): %#v", fakeCloud.Calls)
|
||||
}
|
||||
srv, err := memory.GetService(svc.ID)
|
||||
expectNoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if srv == nil {
|
||||
t.Errorf("Failed to find service: %s", svc.ID)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue