API modified to use source; now supports EmptyDirectory

API is now modified to use a Source struct to handle multiple volumes.

Two volume types are supported now, HostDirectory and EmptyDirectory.
This commit is contained in:
Danny Jones
2014-07-16 12:32:59 -07:00
parent f1a7850454
commit bb2843498d
8 changed files with 104 additions and 41 deletions

View File

@@ -25,15 +25,16 @@ import (
func TestValidateVolumes(t *testing.T) {
successCase := []Volume{
{Name: "abc", HostDirectory: &HostDirectory{"/mnt/path1"}},
{Name: "123", HostDirectory: &HostDirectory{"/mnt/path2"}},
{Name: "abc-123", HostDirectory: &HostDirectory{"/mnt/path3"}},
{Name: "abc"},
{Name: "123", Source: &VolumeSource{HostDirectory: &HostDirectory{"/mnt/path2"}}},
{Name: "abc-123", Source: &VolumeSource{HostDirectory: &HostDirectory{"/mnt/path3"}}},
{Name: "empty", Source: &VolumeSource{EmptyDirectory: &EmptyDirectory{}}},
}
names, errs := validateVolumes(successCase)
if len(errs) != 0 {
t.Errorf("expected success: %v", errs)
}
if len(names) != 3 || !names.Has("abc") || !names.Has("123") || !names.Has("abc-123") {
if len(names) != 4 || !names.Has("abc") || !names.Has("123") || !names.Has("abc-123") || !names.Has("empty") {
t.Errorf("wrong names result: %v", names)
}
@@ -206,8 +207,8 @@ func TestValidateManifest(t *testing.T) {
{
Version: "v1beta1",
ID: "abc",
Volumes: []Volume{{Name: "vol1", HostDirectory: &HostDirectory{"/mnt/vol1"}},
{Name: "vol2", HostDirectory: &HostDirectory{"/mnt/vol2"}}},
Volumes: []Volume{{Name: "vol1", Source: &VolumeSource{HostDirectory: &HostDirectory{"/mnt/vol1"}}},
{Name: "vol2", Source: &VolumeSource{HostDirectory: &HostDirectory{"/mnt/vol2"}}}},
Containers: []Container{
{
Name: "abc",