From adc437f5b3a6f6d6596b8b4aad72ab753a9df3cb Mon Sep 17 00:00:00 2001 From: Jesse Brown Date: Thu, 27 Aug 2020 12:45:00 -0500 Subject: [PATCH] added more tests for #Labels Signed-off-by: Jesse Brown --- local/local_test.go | 38 ++++++++++++++++++++++++++++++++++++-- remote/remote_test.go | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/local/local_test.go b/local/local_test.go index e297249b..cb55674c 100644 --- a/local/local_test.go +++ b/local/local_test.go @@ -190,7 +190,7 @@ func testImage(t *testing.T, when spec.G, it spec.S) { }) when("#Labels", func() { - when("image exists", func() { + when("image exists with labels", func() { var repoName = newTestImageName() it.Before(func() { @@ -206,7 +206,7 @@ func testImage(t *testing.T, when spec.G, it spec.S) { h.AssertNil(t, h.DockerRmi(dockerClient, repoName)) }) - it("returns the labels", func() { + it("returns all the labels", func() { img, err := local.NewImage(repoName, dockerClient, local.FromBaseImage(repoName)) h.AssertNil(t, err) @@ -216,6 +216,40 @@ func testImage(t *testing.T, when spec.G, it spec.S) { h.AssertEq(t, labels["other"], "data") }) }) + + when("image exists with no labels", func() { + var repoName = newTestImageName() + + it.Before(func() { + existingImage, err := local.NewImage(repoName, dockerClient) + h.AssertNil(t, err) + h.AssertNil(t, existingImage.Save()) + }) + + it.After(func() { + h.AssertNil(t, h.DockerRmi(dockerClient, repoName)) + }) + + it("returns an empty map", func() { + img, err := local.NewImage(repoName, dockerClient, local.FromBaseImage(repoName)) + h.AssertNil(t, err) + + labels, err := img.Labels() + h.AssertNil(t, err) + h.AssertEq(t, 0, len(labels)) + }) + }) + + when("image NOT exists", func() { + it("returns an empty map", func() { + img, err := local.NewImage(newTestImageName(), dockerClient) + h.AssertNil(t, err) + + labels, err := img.Labels() + h.AssertNil(t, err) + h.AssertEq(t, 0, len(labels)) + }) + }) }) when("#Label", func() { diff --git a/remote/remote_test.go b/remote/remote_test.go index c9b716e6..b3d00922 100644 --- a/remote/remote_test.go +++ b/remote/remote_test.go @@ -197,7 +197,7 @@ func testImage(t *testing.T, when spec.G, it spec.S) { }) when("#Labels", func() { - when("image exists", func() { + when("image exists with labels", func() { var repoName = newTestImageName() it.Before(func() { @@ -209,7 +209,7 @@ func testImage(t *testing.T, when spec.G, it spec.S) { h.AssertNil(t, baseImage.Save()) }) - it("returns the labels", func() { + it("returns all the labels", func() { img, err := remote.NewImage(repoName, authn.DefaultKeychain, remote.FromBaseImage(repoName)) h.AssertNil(t, err) @@ -219,6 +219,36 @@ func testImage(t *testing.T, when spec.G, it spec.S) { h.AssertEq(t, labels["other"], "data") }) }) + + when("image exists with no labels", func() { + var repoName = newTestImageName() + + it.Before(func() { + baseImage, err := remote.NewImage(repoName, authn.DefaultKeychain) + h.AssertNil(t, err) + h.AssertNil(t, baseImage.Save()) + }) + + it("returns an empty map", func() { + img, err := remote.NewImage(repoName, authn.DefaultKeychain, remote.FromBaseImage(repoName)) + h.AssertNil(t, err) + + labels, err := img.Labels() + h.AssertNil(t, err) + h.AssertEq(t, 0, len(labels)) + }) + }) + + when("image NOT exists", func() { + it("returns an empty map", func() { + img, err := remote.NewImage(newTestImageName(), authn.DefaultKeychain) + h.AssertNil(t, err) + + labels, err := img.Labels() + h.AssertNil(t, err) + h.AssertEq(t, 0, len(labels)) + }) + }) }) when("#Label", func() {