From d94ceaf2a35195c92837faecaf329711a81b6d17 Mon Sep 17 00:00:00 2001 From: Ben Parees Date: Tue, 26 Sep 2017 17:11:14 -0400 Subject: [PATCH] unit test cleanup --- pkg/build/builder/util.go | 6 +++--- pkg/build/controller/strategy/docker_test.go | 14 ++++++++------ pkg/build/controller/strategy/sti_test.go | 14 ++++++++------ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/pkg/build/builder/util.go b/pkg/build/builder/util.go index 9983e5e2c402..df51579f4846 100644 --- a/pkg/build/builder/util.go +++ b/pkg/build/builder/util.go @@ -12,8 +12,8 @@ import ( "strconv" "strings" - //"github.com/google/cadvisor/container/crio" - crio "github.com/kubernetes-incubator/cri-o/client" + "github.com/google/cadvisor/container/crio" + crioclient "github.com/kubernetes-incubator/cri-o/client" docker "github.com/fsouza/go-dockerclient" @@ -79,7 +79,7 @@ func getContainerNetworkConfig() (string, string, error) { return s2iapi.DockerNetworkModeContainerPrefix + id, "", nil } - crioClient, err := crio.New("/var/run/crio.sock") + crioClient, err := crioclient.New(crio.CrioSocket) if err != nil { return "", "", err } diff --git a/pkg/build/controller/strategy/docker_test.go b/pkg/build/controller/strategy/docker_test.go index 8359fcb1f20d..f65da2cfc059 100644 --- a/pkg/build/controller/strategy/docker_test.go +++ b/pkg/build/controller/strategy/docker_test.go @@ -5,6 +5,8 @@ import ( "strings" "testing" + "github.com/google/cadvisor/container/crio" + "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -63,20 +65,20 @@ func TestDockerCreateBuildPod(t *testing.T) { t.Errorf("Expected environment keys:\n%v\ngot keys\n%v", expectedKeys, gotKeys) } - // the pod has 5 volumes but the git source secret is not mounted into the main container. - if len(container.VolumeMounts) != 4 { - t.Fatalf("Expected 4 volumes in container, got %d", len(container.VolumeMounts)) + // the pod has 6 volumes but the git source secret is not mounted into the main container. + if len(container.VolumeMounts) != 5 { + t.Fatalf("Expected 5 volumes in container, got %d", len(container.VolumeMounts)) } if *actual.Spec.ActiveDeadlineSeconds != 60 { t.Errorf("Expected ActiveDeadlineSeconds 60, got %d", *actual.Spec.ActiveDeadlineSeconds) } - for i, expected := range []string{buildutil.BuildWorkDirMount, dockerSocketPath, DockerPushSecretMountPath, DockerPullSecretMountPath} { + for i, expected := range []string{buildutil.BuildWorkDirMount, dockerSocketPath, crio.CrioSocket, DockerPushSecretMountPath, DockerPullSecretMountPath} { if container.VolumeMounts[i].MountPath != expected { t.Fatalf("Expected %s in VolumeMount[%d], got %s", expected, i, container.VolumeMounts[i].MountPath) } } - if len(actual.Spec.Volumes) != 5 { - t.Fatalf("Expected 5 volumes in Build pod, got %d", len(actual.Spec.Volumes)) + if len(actual.Spec.Volumes) != 6 { + t.Fatalf("Expected 6 volumes in Build pod, got %d", len(actual.Spec.Volumes)) } if !kapihelper.Semantic.DeepEqual(container.Resources, util.CopyApiResourcesToV1Resources(&build.Spec.Resources)) { t.Fatalf("Expected actual=expected, %v != %v", container.Resources, build.Spec.Resources) diff --git a/pkg/build/controller/strategy/sti_test.go b/pkg/build/controller/strategy/sti_test.go index f7380947ca77..b51214366421 100644 --- a/pkg/build/controller/strategy/sti_test.go +++ b/pkg/build/controller/strategy/sti_test.go @@ -6,6 +6,8 @@ import ( "strings" "testing" + "github.com/google/cadvisor/container/crio" + "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -98,17 +100,17 @@ func testSTICreateBuildPod(t *testing.T, rootAllowed bool) { t.Errorf("Expected environment keys:\n%v\ngot keys\n%v", expectedKeys, gotKeys) } - // the pod has 5 volumes but the git source secret is not mounted into the main container. - if len(container.VolumeMounts) != 4 { - t.Fatalf("Expected 4 volumes in container, got %d", len(container.VolumeMounts)) + // the pod has 6 volumes but the git source secret is not mounted into the main container. + if len(container.VolumeMounts) != 5 { + t.Fatalf("Expected 5 volumes in container, got %d", len(container.VolumeMounts)) } - for i, expected := range []string{buildutil.BuildWorkDirMount, dockerSocketPath, DockerPushSecretMountPath, DockerPullSecretMountPath} { + for i, expected := range []string{buildutil.BuildWorkDirMount, dockerSocketPath, crio.CrioSocket, DockerPushSecretMountPath, DockerPullSecretMountPath} { if container.VolumeMounts[i].MountPath != expected { t.Fatalf("Expected %s in VolumeMount[%d], got %s", expected, i, container.VolumeMounts[i].MountPath) } } - if len(actual.Spec.Volumes) != 5 { - t.Fatalf("Expected 5 volumes in Build pod, got %d", len(actual.Spec.Volumes)) + if len(actual.Spec.Volumes) != 6 { + t.Fatalf("Expected 6 volumes in Build pod, got %d", len(actual.Spec.Volumes)) } if *actual.Spec.ActiveDeadlineSeconds != 60 { t.Errorf("Expected ActiveDeadlineSeconds 60, got %d", *actual.Spec.ActiveDeadlineSeconds)