當前位置: 首頁>>代碼示例>>Golang>>正文


Golang testutils.NewFakeDriver函數代碼示例

本文整理匯總了Golang中github.com/docker/docker/volume/testutils.NewFakeDriver函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewFakeDriver函數的具體用法?Golang NewFakeDriver怎麽用?Golang NewFakeDriver使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewFakeDriver函數的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestRemove

func TestRemove(t *testing.T) {
	volumedrivers.Register(vt.NewFakeDriver("fake"), "fake")
	volumedrivers.Register(vt.NewFakeDriver("noop"), "noop")
	defer volumedrivers.Unregister("fake")
	defer volumedrivers.Unregister("noop")
	s := New()

	// doing string compare here since this error comes directly from the driver
	expected := "no such volume"
	if err := s.Remove(vt.NoopVolume{}); err == nil || !strings.Contains(err.Error(), expected) {
		t.Fatalf("Expected error %q, got %v", expected, err)
	}

	v, err := s.CreateWithRef("fake1", "fake", "fake", nil)
	if err != nil {
		t.Fatal(err)
	}

	if err := s.Remove(v); !IsInUse(err) {
		t.Fatalf("Expected ErrVolumeInUse error, got %v", err)
	}
	s.Dereference(v, "fake")
	if err := s.Remove(v); err != nil {
		t.Fatal(err)
	}
	if l, _, _ := s.List(); len(l) != 0 {
		t.Fatalf("Expected 0 volumes in the store, got %v, %v", len(l), l)
	}
}
開發者ID:contiv,項目名稱:docker,代碼行數:29,代碼來源:store_test.go

示例2: TestList

func TestList(t *testing.T) {
	volumedrivers.Register(vt.NewFakeDriver("fake"), "fake")
	volumedrivers.Register(vt.NewFakeDriver("fake2"), "fake2")
	defer volumedrivers.Unregister("fake")
	defer volumedrivers.Unregister("fake2")

	s := New()
	if _, err := s.Create("test", "fake", nil); err != nil {
		t.Fatal(err)
	}
	if _, err := s.Create("test2", "fake2", nil); err != nil {
		t.Fatal(err)
	}

	ls, _, err := s.List()
	if err != nil {
		t.Fatal(err)
	}
	if len(ls) != 2 {
		t.Fatalf("expected 2 volumes, got: %d", len(ls))
	}

	// and again with a new store
	s = New()
	ls, _, err = s.List()
	if err != nil {
		t.Fatal(err)
	}
	if len(ls) != 2 {
		t.Fatalf("expected 2 volumes, got: %d", len(ls))
	}
}
開發者ID:contiv,項目名稱:docker,代碼行數:32,代碼來源:store_test.go

示例3: TestFilterByUsed

func TestFilterByUsed(t *testing.T) {
	volumedrivers.Register(vt.NewFakeDriver("fake"), "fake")
	volumedrivers.Register(vt.NewFakeDriver("noop"), "noop")

	s := New()
	if _, err := s.CreateWithRef("fake1", "fake", "volReference", nil); err != nil {
		t.Fatal(err)
	}
	if _, err := s.Create("fake2", "fake", nil); err != nil {
		t.Fatal(err)
	}

	vols, _, err := s.List()
	if err != nil {
		t.Fatal(err)
	}

	dangling := s.FilterByUsed(vols, false)
	if len(dangling) != 1 {
		t.Fatalf("expected 1 danging volume, got %v", len(dangling))
	}
	if dangling[0].Name() != "fake2" {
		t.Fatalf("expected danging volume fake2, got %s", dangling[0].Name())
	}

	used := s.FilterByUsed(vols, true)
	if len(used) != 1 {
		t.Fatalf("expected 1 used volume, got %v", len(used))
	}
	if used[0].Name() != "fake1" {
		t.Fatalf("expected used volume fake1, got %s", used[0].Name())
	}
}
開發者ID:contiv,項目名稱:docker,代碼行數:33,代碼來源:store_test.go

示例4: TestFilterByDriver

func TestFilterByDriver(t *testing.T) {
	volumedrivers.Register(vt.NewFakeDriver("fake"), "fake")
	volumedrivers.Register(vt.NewFakeDriver("noop"), "noop")
	defer volumedrivers.Unregister("fake")
	defer volumedrivers.Unregister("noop")
	s := New()

	if _, err := s.Create("fake1", "fake", nil); err != nil {
		t.Fatal(err)
	}
	if _, err := s.Create("fake2", "fake", nil); err != nil {
		t.Fatal(err)
	}
	if _, err := s.Create("fake3", "noop", nil); err != nil {
		t.Fatal(err)
	}

	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)
	}
}
開發者ID:contiv,項目名稱:docker,代碼行數:25,代碼來源:store_test.go

示例5: TestFilterByDriver

func TestFilterByDriver(t *testing.T) {
	volumedrivers.Register(volumetestutils.NewFakeDriver("fake"), "fake")
	volumedrivers.Register(volumetestutils.NewFakeDriver("noop"), "noop")
	defer volumedrivers.Unregister("fake")
	defer volumedrivers.Unregister("noop")
	dir, err := ioutil.TempDir("", "test-filter-driver")
	if err != nil {
		t.Fatal(err)
	}
	s, err := New(dir)
	if err != nil {
		t.Fatal(err)
	}

	if _, err := s.Create("fake1", "fake", nil, nil); err != nil {
		t.Fatal(err)
	}
	if _, err := s.Create("fake2", "fake", nil, nil); err != nil {
		t.Fatal(err)
	}
	if _, err := s.Create("fake3", "noop", nil, nil); err != nil {
		t.Fatal(err)
	}

	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)
	}
}
開發者ID:docker,項目名稱:docker,代碼行數:32,代碼來源:store_test.go

示例6: TestCreate

func TestCreate(t *testing.T) {
	volumedrivers.Register(vt.NewFakeDriver("fake"), "fake")
	defer volumedrivers.Unregister("fake")
	s := New()
	v, err := s.Create("fake1", "fake", nil)
	if err != nil {
		t.Fatal(err)
	}
	if v.Name() != "fake1" {
		t.Fatalf("Expected fake1 volume, got %v", v)
	}
	if l, _, _ := s.List(); len(l) != 1 {
		t.Fatalf("Expected 1 volume in the store, got %v: %v", len(l), l)
	}

	if _, err := s.Create("none", "none", nil); err == nil {
		t.Fatalf("Expected unknown driver error, got nil")
	}

	_, err = s.Create("fakeerror", "fake", map[string]string{"error": "create error"})
	expected := &OpErr{Op: "create", Name: "fakeerror", Err: errors.New("create error")}
	if err != nil && err.Error() != expected.Error() {
		t.Fatalf("Expected create fakeError: create error, got %v", err)
	}
}
開發者ID:contiv,項目名稱:docker,代碼行數:25,代碼來源:store_test.go

示例7: TestCreate

func TestCreate(t *testing.T) {
	pluginStore := pluginstore.NewStore("/var/lib/docker")
	volumedrivers.RegisterPluginGetter(pluginStore)

	volumedrivers.Register(volumetestutils.NewFakeDriver("fake"), "fake")
	defer volumedrivers.Unregister("fake")
	s, err := New("")
	if err != nil {
		t.Fatal(err)
	}
	v, err := s.Create("fake1", "fake", nil, nil)
	if err != nil {
		t.Fatal(err)
	}
	if v.Name() != "fake1" {
		t.Fatalf("Expected fake1 volume, got %v", v)
	}
	if l, _, _ := s.List(); len(l) != 1 {
		t.Fatalf("Expected 1 volume in the store, got %v: %v", len(l), l)
	}

	if _, err := s.Create("none", "none", nil, nil); err == nil {
		t.Fatalf("Expected unknown driver error, got nil")
	}

	_, err = s.Create("fakeerror", "fake", map[string]string{"error": "create error"}, nil)
	expected := &OpErr{Op: "create", Name: "fakeerror", Err: errors.New("create error")}
	if err != nil && err.Error() != expected.Error() {
		t.Fatalf("Expected create fakeError: create error, got %v", err)
	}
}
開發者ID:harche,項目名稱:docker,代碼行數:31,代碼來源:store_test.go

示例8: TestDerefMultipleOfSameRef

func TestDerefMultipleOfSameRef(t *testing.T) {
	volumedrivers.Register(volumetestutils.NewFakeDriver("fake"), "fake")
	dir, err := ioutil.TempDir("", "test-same-deref")
	if err != nil {
		t.Fatal(err)
	}

	s, err := New(dir)
	if err != nil {
		t.Fatal(err)
	}

	v, err := s.CreateWithRef("fake1", "fake", "volReference", nil, nil)
	if err != nil {
		t.Fatal(err)
	}

	if _, err := s.GetWithRef("fake1", "fake", "volReference"); err != nil {
		t.Fatal(err)
	}

	s.Dereference(v, "volReference")
	if err := s.Remove(v); err != nil {
		t.Fatal(err)
	}
}
開發者ID:docker,項目名稱:docker,代碼行數:26,代碼來源:store_test.go

示例9: TestList

func TestList(t *testing.T) {
	volumedrivers.Register(volumetestutils.NewFakeDriver("fake"), "fake")
	volumedrivers.Register(volumetestutils.NewFakeDriver("fake2"), "fake2")
	defer volumedrivers.Unregister("fake")
	defer volumedrivers.Unregister("fake2")
	dir, err := ioutil.TempDir("", "test-list")
	if err != nil {
		t.Fatal(err)
	}
	defer os.RemoveAll(dir)

	s, err := New(dir)
	if err != nil {
		t.Fatal(err)
	}
	if _, err := s.Create("test", "fake", nil, nil); err != nil {
		t.Fatal(err)
	}
	if _, err := s.Create("test2", "fake2", nil, nil); err != nil {
		t.Fatal(err)
	}

	ls, _, err := s.List()
	if err != nil {
		t.Fatal(err)
	}
	if len(ls) != 2 {
		t.Fatalf("expected 2 volumes, got: %d", len(ls))
	}
	if err := s.Shutdown(); err != nil {
		t.Fatal(err)
	}

	// and again with a new store
	s, err = New(dir)
	if err != nil {
		t.Fatal(err)
	}
	ls, _, err = s.List()
	if err != nil {
		t.Fatal(err)
	}
	if len(ls) != 2 {
		t.Fatalf("expected 2 volumes, got: %d", len(ls))
	}
}
開發者ID:docker,項目名稱:docker,代碼行數:46,代碼來源:store_test.go

示例10: TestGetDriver

func TestGetDriver(t *testing.T) {
	_, err := GetDriver("missing")
	if err == nil {
		t.Fatal("Expected error, was nil")
	}
	Register(volumetestutils.NewFakeDriver("fake"), "fake")

	d, err := GetDriver("fake")
	if err != nil {
		t.Fatal(err)
	}
	if d.Name() != "fake" {
		t.Fatalf("Expected fake driver, got %s\n", d.Name())
	}
}
開發者ID:docker,項目名稱:docker,代碼行數:15,代碼來源:extpoint_test.go

示例11: TestGetDriver

func TestGetDriver(t *testing.T) {
	pluginStore := pluginstore.NewStore("/var/lib/docker")
	RegisterPluginGetter(pluginStore)

	_, err := GetDriver("missing")
	if err == nil {
		t.Fatal("Expected error, was nil")
	}
	Register(volumetestutils.NewFakeDriver("fake"), "fake")

	d, err := GetDriver("fake")
	if err != nil {
		t.Fatal(err)
	}
	if d.Name() != "fake" {
		t.Fatalf("Expected fake driver, got %s\n", d.Name())
	}
}
開發者ID:SUSE,項目名稱:docker.mirror,代碼行數:18,代碼來源:extpoint_test.go

示例12: TestDerefMultipleOfSameRef

func TestDerefMultipleOfSameRef(t *testing.T) {
	volumedrivers.Register(vt.NewFakeDriver("fake"), "fake")

	s := New()
	v, err := s.CreateWithRef("fake1", "fake", "volReference", nil)
	if err != nil {
		t.Fatal(err)
	}

	if _, err := s.GetWithRef("fake1", "fake", "volReference"); err != nil {
		t.Fatal(err)
	}

	s.Dereference(v, "volReference")
	if err := s.Remove(v); err != nil {
		t.Fatal(err)
	}
}
開發者ID:contiv,項目名稱:docker,代碼行數:18,代碼來源:store_test.go


注:本文中的github.com/docker/docker/volume/testutils.NewFakeDriver函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。