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


Golang utils.TestDirectory函數代碼示例

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


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

示例1: TestGetVersion

func TestGetVersion(t *testing.T) {
	tmp, err := utils.TestDirectory("")
	if err != nil {
		t.Fatal(err)
	}
	defer os.RemoveAll(tmp)
	eng, err := engine.New(tmp)
	if err != nil {
		t.Fatal(err)
	}
	var called bool
	eng.Register("version", func(job *engine.Job) engine.Status {
		called = true
		v := &engine.Env{}
		v.SetJson("Version", "42.1")
		v.Set("ApiVersion", "1.1.1.1.1")
		v.Set("GoVersion", "2.42")
		v.Set("Os", "Linux")
		v.Set("Arch", "x86_64")
		if _, err := v.WriteTo(job.Stdout); err != nil {
			return job.Error(err)
		}
		return engine.StatusOK
	})

	r := httptest.NewRecorder()
	req, err := http.NewRequest("GET", "/version", nil)
	if err != nil {
		t.Fatal(err)
	}
	// FIXME getting the version should require an actual running Server
	if err := ServeRequest(eng, api.APIVERSION, r, req); err != nil {
		t.Fatal(err)
	}
	if !called {
		t.Fatalf("handler was not called")
	}
	out := engine.NewOutput()
	v, err := out.AddEnv()
	if err != nil {
		t.Fatal(err)
	}
	if _, err := io.Copy(out, r.Body); err != nil {
		t.Fatal(err)
	}
	out.Close()
	expected := "42.1"
	if result := v.Get("Version"); result != expected {
		t.Errorf("Expected version %s, %s found", expected, result)
	}
	expected = "application/json"
	if result := r.HeaderMap.Get("Content-Type"); result != expected {
		t.Errorf("Expected Content-Type %s, %s found", expected, result)
	}
}
開發者ID:np,項目名稱:docker,代碼行數:55,代碼來源:server_unit_test.go

示例2: tmpEngine

func tmpEngine(t *testing.T) *engine.Engine {
	tmp, err := utils.TestDirectory("")
	if err != nil {
		t.Fatal(err)
	}
	eng, err := engine.New(tmp)
	if err != nil {
		t.Fatal(err)
	}
	return eng
}
開發者ID:ChaosCloud,項目名稱:docker,代碼行數:11,代碼來源:server_unit_test.go

示例3: newTestEngine

func newTestEngine(t *testing.T) *Engine {
	tmp, err := utils.TestDirectory("")
	if err != nil {
		t.Fatal(err)
	}
	eng, err := New(tmp)
	if err != nil {
		t.Fatal(err)
	}
	return eng
}
開發者ID:johntdyer,項目名稱:golang-devops-stuff,代碼行數:11,代碼來源:helpers_test.go

示例4: TestLookupImage

func TestLookupImage(t *testing.T) {
	tmp, err := utils.TestDirectory("")
	if err != nil {
		t.Fatal(err)
	}
	defer os.RemoveAll(tmp)
	store := mkTestTagStore(tmp, t)
	defer store.graph.driver.Cleanup()

	if img, err := store.LookupImage(testImageName); err != nil {
		t.Fatal(err)
	} else if img == nil {
		t.Errorf("Expected 1 image, none found")
	}
	if img, err := store.LookupImage(testImageName + ":" + DEFAULTTAG); err != nil {
		t.Fatal(err)
	} else if img == nil {
		t.Errorf("Expected 1 image, none found")
	}

	if img, err := store.LookupImage(testImageName + ":" + "fail"); err == nil {
		t.Errorf("Expected error, none found")
	} else if img != nil {
		t.Errorf("Expected 0 image, 1 found")
	}

	if img, err := store.LookupImage("fail:fail"); err == nil {
		t.Errorf("Expected error, none found")
	} else if img != nil {
		t.Errorf("Expected 0 image, 1 found")
	}

	if img, err := store.LookupImage(testImageID); err != nil {
		t.Fatal(err)
	} else if img == nil {
		t.Errorf("Expected 1 image, none found")
	}

	if img, err := store.LookupImage(testImageName + ":" + testImageID); err != nil {
		t.Fatal(err)
	} else if img == nil {
		t.Errorf("Expected 1 image, none found")
	}
}
開發者ID:Emsu,項目名稱:docker,代碼行數:44,代碼來源:tags_unit_test.go

示例5: newTestDirectory

func newTestDirectory(templateDir string) (dir string, err error) {
	return utils.TestDirectory(templateDir)
}
開發者ID:krast,項目名稱:docker,代碼行數:3,代碼來源:utils_test.go

示例6: TestGetInfo

func TestGetInfo(t *testing.T) {
	tmp, err := utils.TestDirectory("")
	if err != nil {
		t.Fatal(err)
	}
	defer os.RemoveAll(tmp)
	eng, err := engine.New(tmp)
	if err != nil {
		t.Fatal(err)
	}

	var called bool
	eng.Register("info", func(job *engine.Job) engine.Status {
		called = true
		v := &engine.Env{}
		v.SetInt("Containers", 1)
		v.SetInt("Images", 42000)
		if _, err := v.WriteTo(job.Stdout); err != nil {
			return job.Error(err)
		}
		return engine.StatusOK
	})

	r := httptest.NewRecorder()
	req, err := http.NewRequest("GET", "/info", nil)
	if err != nil {
		t.Fatal(err)
	}
	// FIXME getting the version should require an actual running Server
	if err := ServeRequest(eng, api.APIVERSION, r, req); err != nil {
		t.Fatal(err)
	}
	if !called {
		t.Fatalf("handler was not called")
	}

	out := engine.NewOutput()
	i, err := out.AddEnv()
	if err != nil {
		t.Fatal(err)
	}
	if _, err := io.Copy(out, r.Body); err != nil {
		t.Fatal(err)
	}
	out.Close()
	{
		expected := 42000
		result := i.GetInt("Images")
		if expected != result {
			t.Fatalf("%#v\n", result)
		}
	}
	{
		expected := 1
		result := i.GetInt("Containers")
		if expected != result {
			t.Fatalf("%#v\n", result)
		}
	}
	{
		expected := "application/json"
		if result := r.HeaderMap.Get("Content-Type"); result != expected {
			t.Fatalf("%#v\n", result)
		}
	}
}
開發者ID:np,項目名稱:docker,代碼行數:66,代碼來源:server_unit_test.go


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