Skip to content

Commit

Permalink
added more tests for #Labels
Browse files Browse the repository at this point in the history
Signed-off-by: Jesse Brown <jabrown85@gmail.com>
  • Loading branch information
jabrown85 committed Aug 27, 2020
1 parent 85f09ca commit adc437f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
38 changes: 36 additions & 2 deletions local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)

Expand All @@ -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() {
Expand Down
34 changes: 32 additions & 2 deletions remote/remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)

Expand All @@ -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() {
Expand Down

0 comments on commit adc437f

Please sign in to comment.