Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(docker.go): container config fields on Driver no longer pointers #206

Merged
merged 4 commits into from
May 2, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add config modification test
Signed-off-by: Vaughn Dice <[email protected]>
  • Loading branch information
vdice committed Apr 24, 2020
commit 5395191c27b9b2ccda76a6f4e6327e32215796ff
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{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 this is much cleaner to work with


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)
})
}