Skip to content

Commit

Permalink
Change local SetOS to accept only valid values
Browse files Browse the repository at this point in the history
- Keep as a noop setter for consitency remote
- Compare against default value to fail fast

Signed-off-by: Micah Young <ymicah@vmware.com>
  • Loading branch information
Micah Young committed Oct 15, 2020
1 parent ec9e535 commit bd9808c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
4 changes: 3 additions & 1 deletion local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ func (i *Image) SetLabel(key, val string) error {
}

func (i *Image) SetOS(osVal string) error {
i.inspect.Os = osVal
if osVal != i.inspect.Os {
return fmt.Errorf(`invalid os: must match the daemon: "%s"`, i.inspect.Os)
}
return nil
}

Expand Down
31 changes: 27 additions & 4 deletions local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,22 +706,46 @@ func testImage(t *testing.T, when spec.G, it spec.S) {
})
})

when("#SetOS #SetOSVersion #SetArchitecture", func() {
when("#SetOS", func() {
var repoName = newTestImageName()

it.After(func() {
h.AssertNil(t, h.DockerRmi(dockerClient, repoName))
})

it("sets the os/arch", func() {
it("allows noop sets for values that match the daemon", func() {
img, err := local.NewImage(repoName, dockerClient)
h.AssertNil(t, err)

//os has to match daemon
err = img.SetOS("fakeos")
h.AssertError(t, err, "invalid os: must match the daemon")

err = img.SetOS(daemonOS)
h.AssertNil(t, err)

h.AssertNil(t, img.Save())

inspect, _, err := dockerClient.ImageInspectWithRaw(context.TODO(), repoName)
h.AssertNil(t, err)

h.AssertEq(t, inspect.Os, daemonOS)
})
})

when("#SetOSVersion #SetArchitecture", func() {
var repoName = newTestImageName()

it.After(func() {
h.AssertNil(t, h.DockerRmi(dockerClient, repoName))
})

it("sets the os.version/arch", func() {
img, err := local.NewImage(repoName, dockerClient)
h.AssertNil(t, err)

err = img.SetOSVersion("1.2.3.4")
h.AssertNil(t, err)

err = img.SetArchitecture("arm64")
h.AssertNil(t, err)

Expand All @@ -730,7 +754,6 @@ func testImage(t *testing.T, when spec.G, it spec.S) {
inspect, _, err := dockerClient.ImageInspectWithRaw(context.TODO(), repoName)
h.AssertNil(t, err)

h.AssertEq(t, inspect.Os, daemonOS)
h.AssertEq(t, inspect.OsVersion, "1.2.3.4")
h.AssertEq(t, inspect.Architecture, "arm64")
})
Expand Down

0 comments on commit bd9808c

Please sign in to comment.