From 5395191c27b9b2ccda76a6f4e6327e32215796ff Mon Sep 17 00:00:00 2001 From: Vaughn Dice Date: Fri, 24 Apr 2020 12:08:50 -0600 Subject: [PATCH] add config modification test Signed-off-by: Vaughn Dice --- driver/docker/docker_test.go | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/driver/docker/docker_test.go b/driver/docker/docker_test.go index c39eef82..5ef9a3ad 100644 --- a/driver/docker/docker_test.go +++ b/driver/docker/docker_test.go @@ -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) @@ -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 @@ -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) + }) }