1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/volumes/volume_test.go
Antonio Murdaca 7afb234741 Fix TestInitializeCannotStatPathFileNameTooLong
Signed-off-by: Antonio Murdaca <me@runcom.ninja>
2015-04-15 21:15:05 +02:00

55 lines
1.2 KiB
Go

package volumes
import (
"os"
"testing"
"github.com/docker/docker/pkg/stringutils"
)
func TestContainers(t *testing.T) {
v := &Volume{containers: make(map[string]struct{})}
id := "1234"
v.AddContainer(id)
if v.Containers()[0] != id {
t.Fatalf("adding a container ref failed")
}
v.RemoveContainer(id)
if len(v.Containers()) != 0 {
t.Fatalf("removing container failed")
}
}
// os.Stat(v.Path) is returning ErrNotExist, initialize catch it and try to
// mkdir v.Path but it dies and correctly returns the error
func TestInitializeCannotMkdirOnNonExistentPath(t *testing.T) {
v := &Volume{Path: "nonexistentpath"}
err := v.initialize()
if err == nil {
t.Fatal("Expected not to initialize volume with a non existent path")
}
if !os.IsNotExist(err) {
t.Fatalf("Expected to get ErrNotExist error, got %s", err)
}
}
// os.Stat(v.Path) is NOT returning ErrNotExist so skip and return error from
// initialize
func TestInitializeCannotStatPathFileNameTooLong(t *testing.T) {
// ENAMETOOLONG
v := &Volume{Path: stringutils.GenerateRandomAlphaOnlyString(300)}
err := v.initialize()
if err == nil {
t.Fatal("Expected not to initialize volume with a non existent path")
}
if os.IsNotExist(err) {
t.Fatal("Expected to not get ErrNotExist")
}
}