Skip to content
Permalink
Browse files

Add specific mock for TestValidateMount

Create a new mock specific for the test `TestValidateMount` which
returns `exist` to `false` only when it's equal to
`testSourcePathDoesNotExist` so that the validation is done correctly.

Signed-off-by: Steve Azzopardi <sazzopardi@gitlab.com>
  • Loading branch information
steveazz committed Jan 9, 2019
1 parent ab1cd4c commit f1c6708078115ce633516f72eb3f0bfaa1c1aa42
Showing with 22 additions and 6 deletions.
  1. +16 −2 volume/mounts/validate_test.go
  2. +3 −2 volume/mounts/validate_unix_test.go
  3. +3 −2 volume/mounts/validate_windows_test.go
@@ -11,7 +11,21 @@ import (
"github.com/docker/docker/api/types/mount"
)

type testValidateMountFiProvider struct{}

func (testValidateMountFiProvider) fileInfo(path string) (exist, isDir bool, err error) {
if path == testSourcePathDoesNotExist {
return false, false, nil
}

return true, true, nil
}

func TestValidateMount(t *testing.T) {
previousProvider := currentFileInfoProvider
defer func() { currentFileInfoProvider = previousProvider }()
currentFileInfoProvider = testValidateMountFiProvider{}

testDir, err := ioutil.TempDir("", "test-validate-mount")
if err != nil {
t.Fatal(err)
@@ -31,7 +45,7 @@ func TestValidateMount(t *testing.T) {

{mount.Mount{Type: mount.TypeBind, Source: testDir, Target: testDestinationPath}, nil},
{mount.Mount{Type: "invalid", Target: testDestinationPath}, errors.New("mount type unknown")},
{mount.Mount{Type: mount.TypeBind, Source: testSourcePath, Target: testDestinationPath}, errBindSourceDoesNotExist(testSourcePath)},
{mount.Mount{Type: mount.TypeBind, Source: testSourcePathDoesNotExist, Target: testDestinationPath}, errBindSourceDoesNotExist(testSourcePathDoesNotExist)},
}

lcowCases := []struct {
@@ -44,7 +58,7 @@ func TestValidateMount(t *testing.T) {
{mount.Mount{Type: mount.TypeBind}, errMissingField("Target")},
{mount.Mount{Type: mount.TypeBind, Target: "/foo"}, errMissingField("Source")},
{mount.Mount{Type: mount.TypeBind, Target: "/foo", Source: "c:\\foo", VolumeOptions: &mount.VolumeOptions{}}, errExtraField("VolumeOptions")},
{mount.Mount{Type: mount.TypeBind, Source: "c:\\foo", Target: "/foo"}, errBindSourceDoesNotExist("c:\\foo")},
{mount.Mount{Type: mount.TypeBind, Source: testSourcePathDoesNotExist, Target: "/foo"}, errBindSourceDoesNotExist(testSourcePathDoesNotExist)},
{mount.Mount{Type: mount.TypeBind, Source: testDir, Target: "/foo"}, nil},
{mount.Mount{Type: "invalid", Target: "/foo"}, errors.New("mount type unknown")},
}
@@ -3,6 +3,7 @@
package mounts // import "github.com/docker/docker/volume/mounts"

var (
testDestinationPath = "/foo"
testSourcePath = "/foo"
testDestinationPath = "/foo"
testSourcePath = "/foo"
testSourcePathDoesNotExist = `/not/exists'`
)
@@ -1,6 +1,7 @@
package mounts // import "github.com/docker/docker/volume/mounts"

var (
testDestinationPath = `c:\foo`
testSourcePath = `c:\foo`
testDestinationPath = `c:\foo`
testSourcePath = `c:\foo`
testSourcePathDoesNotExist = `c:\not\exists'`
)

0 comments on commit f1c6708

Please sign in to comment.
You can’t perform that action at this time.