Skip to content

Commit

Permalink
add config modification test
Browse files Browse the repository at this point in the history
Signed-off-by: Vaughn Dice <[email protected]>
  • Loading branch information
vdice committed Apr 24, 2020
1 parent 9b6875f commit 5395191
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions driver/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import (

"github.com/cnabio/cnab-go/driver"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/strslice"
"github.com/stretchr/testify/assert"
)

func TestDriver_GetConfigurationOptions(t *testing.T) {
d := &Driver{}
is := assert.New(t)
is.NotNil(d)
is.True(d.Handles(driver.ImageTypeDocker))

t.Run("empty configuration options", func(t *testing.T) {
d := &Driver{}
is.NotNil(d)
is.True(d.Handles(driver.ImageTypeDocker))

err := d.ApplyConfigurationOptions()
is.NoError(err)

Expand All @@ -28,6 +30,8 @@ func TestDriver_GetConfigurationOptions(t *testing.T) {
})

t.Run("configuration options", func(t *testing.T) {
d := &Driver{}

d.AddConfigurationOptions(func(cfg *container.Config, hostCfg *container.HostConfig) error {
cfg.User = "cnabby"
hostCfg.Privileged = true
Expand All @@ -52,4 +56,30 @@ func TestDriver_GetConfigurationOptions(t *testing.T) {
is.NoError(err)
is.Equal(expectedHostCfg, hostCfg)
})

t.Run("configuration options - no unintentional modification", func(t *testing.T) {
d := &Driver{}

d.AddConfigurationOptions(func(cfg *container.Config, hostCfg *container.HostConfig) error {
hostCfg.CapAdd = strslice.StrSlice{"SUPER_POWERS"}
return nil
})

err := d.ApplyConfigurationOptions()
is.NoError(err)

expectedHostCfg := container.HostConfig{
CapAdd: strslice.StrSlice{"SUPER_POWERS"},
}

hostCfg, err := d.GetContainerHostConfig()
is.NoError(err)
is.Equal(expectedHostCfg, hostCfg)

hostCfg.CapAdd[0] = "NORMAL_POWERS"

hostCfg, err = d.GetContainerHostConfig()
is.NoError(err)
is.Equal(expectedHostCfg, hostCfg)
})
}

0 comments on commit 5395191

Please sign in to comment.