Example #1
0
func TestIncrement(t *testing.T) {
	s := New()
	v := vt.NewFakeVolume("fake1")
	s.Increment(v)
	if l := s.List(); len(l) != 1 {
		t.Fatalf("Expected 1 volume, got %v, %v", len(l), l)
	}
	if c := s.Count(v); c != 1 {
		t.Fatalf("Expected 1 counter, got %v", c)
	}

	s.Increment(v)
	if l := s.List(); len(l) != 1 {
		t.Fatalf("Expected 1 volume, got %v, %v", len(l), l)
	}
	if c := s.Count(v); c != 2 {
		t.Fatalf("Expected 2 counter, got %v", c)
	}

	v2 := vt.NewFakeVolume("fake2")
	s.Increment(v2)
	if l := s.List(); len(l) != 2 {
		t.Fatalf("Expected 2 volume, got %v, %v", len(l), l)
	}
}
Example #2
0
func TestList(t *testing.T) {
	volumedrivers.Register(vt.FakeDriver{}, "fake")
	s := New()
	s.AddAll([]volume.Volume{vt.NewFakeVolume("fake1"), vt.NewFakeVolume("fake2")})
	l := s.List()
	if len(l) != 2 {
		t.Fatalf("Expected 2 volumes in the store, got %v: %v", len(l), l)
	}
}
Example #3
0
func TestFilterByDriver(t *testing.T) {
	s := New()

	s.Increment(vt.NewFakeVolume("fake1"))
	s.Increment(vt.NewFakeVolume("fake2"))
	s.Increment(vt.NoopVolume{})

	if l := s.FilterByDriver("fake"); len(l) != 2 {
		t.Fatalf("Expected 2 volumes, got %v, %v", len(l), l)
	}

	if l := s.FilterByDriver("noop"); len(l) != 1 {
		t.Fatalf("Expected 1 volume, got %v, %v", len(l), l)
	}
}
Example #4
0
func TestGet(t *testing.T) {
	volumedrivers.Register(vt.FakeDriver{}, "fake")
	s := New()
	s.AddAll([]volume.Volume{vt.NewFakeVolume("fake1"), vt.NewFakeVolume("fake2")})
	v, err := s.Get("fake1")
	if err != nil {
		t.Fatal(err)
	}
	if v.Name() != "fake1" {
		t.Fatalf("Expected fake1 volume, got %v", v)
	}

	if _, err := s.Get("fake4"); !IsNotExist(err) {
		t.Fatalf("Expected IsNotExist error, got %v", err)
	}
}