2015-01-23 13:58:28 -05:00
|
|
|
package volumes
|
|
|
|
|
2015-03-24 17:11:45 -04:00
|
|
|
import (
|
2015-04-15 15:14:54 -04:00
|
|
|
"os"
|
2015-03-24 17:11:45 -04:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/docker/pkg/stringutils"
|
|
|
|
)
|
2015-01-23 13:58:28 -05:00
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|
2015-03-24 17:11:45 -04:00
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
|
|
|
|
2015-04-15 15:14:54 -04:00
|
|
|
if !os.IsNotExist(err) {
|
|
|
|
t.Fatalf("Expected to get ErrNotExist error, got %s", err)
|
2015-03-24 17:11:45 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
|
|
|
|
2015-04-15 15:14:54 -04:00
|
|
|
if os.IsNotExist(err) {
|
|
|
|
t.Fatal("Expected to not get ErrNotExist")
|
2015-03-24 17:11:45 -04:00
|
|
|
}
|
|
|
|
}
|