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


Golang testutil.CleanUp函數代碼示例

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


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

示例1: TestPostCreateWithNoServer

func TestPostCreateWithNoServer(t *testing.T) {
	testutil.CleanUp()
	defer testutil.CleanUp()

	mux := http.NewServeMux()
	server := httptest.NewServer(mux)
	defer server.Close()

	err := os.Setenv("QIITA_ACCESS_TOKEN", "XXXXXXXXXXXX")
	if err != nil {
		t.Fatal(err)
	}

	client := api.NewClient(func(subDomain, path string) (url string) {
		url = fmt.Sprintf("%s%s%s", server.URL, "/api/v2", path)
		return
	}, inf)

	testutil.ShouldExistFile(t, 0)

	post := model.NewPost("Example Title", nil, nil)
	err = post.Create(client, model.CreationOptions{})
	if err == nil {
		t.Fatal("error should occur")
	}

	testutil.ShouldExistFile(t, 0)
}
開發者ID:minodisk,項目名稱:qiitactl,代碼行數:28,代碼來源:post_test.go

示例2: TestFetchPostsWithResponseStatusError

func TestFetchPostsWithResponseStatusError(t *testing.T) {
	testutil.CleanUp()
	defer testutil.CleanUp()

	mux := http.NewServeMux()
	mux.HandleFunc("/api/v2/authenticated_user/items", func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(500)
	})

	server := httptest.NewServer(mux)
	defer server.Close()

	err := os.Setenv("QIITA_ACCESS_TOKEN", "XXXXXXXXXXXX")
	if err != nil {
		t.Fatal(err)
	}

	client := api.NewClient(func(subDomain, path string) (url string) {
		url = fmt.Sprintf("%s%s%s", server.URL, "/api/v2", path)
		return
	}, inf)

	_, err = model.FetchPosts(client, nil)
	if err == nil {
		t.Fatal("error should occur")
	}
	_, ok := err.(api.StatusError)
	if !ok {
		t.Fatalf("wrong type error: %s", reflect.TypeOf(err))
	}
}
開發者ID:minodisk,項目名稱:qiitactl,代碼行數:31,代碼來源:posts_test.go

示例3: TestPostDecodeWithWrongTitle

func TestPostDecodeWithWrongTitle(t *testing.T) {
	testutil.CleanUp()
	defer testutil.CleanUp()

	var post model.Post
	err := post.Decode([]byte(`<!--
id: abcdefghijklmnopqrst
url: http://example.com/mypost
created_at: 2013-12-10T12:29:14+09:00
updated_at: 2015-02-25T09:26:30+09:00
private: true
coediting: false
tags:
- TypeScript
- Docker:
  - 1.9
- Go:
  - 1.4.3
  - 1.5.3
team: null
-->

## Sub title
# Main title

Paragraph
`))
	if err == nil {
		t.Errorf("should return error with non-object element in tags")
	}
}
開發者ID:minodisk,項目名稱:qiitactl,代碼行數:31,代碼來源:post_test.go

示例4: TestPostCreateWithWrongResponseBody

func TestPostCreateWithWrongResponseBody(t *testing.T) {
	testutil.CleanUp()
	defer testutil.CleanUp()

	mux := http.NewServeMux()
	mux.HandleFunc("/api/v2/items", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "Non JSON format")
	})

	server := httptest.NewServer(mux)
	defer server.Close()

	err := os.Setenv("QIITA_ACCESS_TOKEN", "XXXXXXXXXXXX")
	if err != nil {
		t.Fatal(err)
	}

	client := api.NewClient(func(subDomain, path string) (url string) {
		url = fmt.Sprintf("%s%s%s", server.URL, "/api/v2", path)
		return
	}, inf)

	post := model.NewPost("Example Title", nil, nil)
	err = post.Create(client, model.CreationOptions{})
	if err == nil {
		t.Fatal("error should occur")
	}
}
開發者ID:minodisk,項目名稱:qiitactl,代碼行數:28,代碼來源:post_test.go

示例5: TestPostSaveDuplicationWithID

func TestPostSaveDuplicationWithID(t *testing.T) {
	testutil.CleanUp()
	defer testutil.CleanUp()

	testutil.ShouldExistFile(t, 0)

	func() {
		post := model.NewPost("Example Title", &model.Time{time.Date(2015, 11, 28, 13, 2, 37, 0, time.UTC)}, nil)
		post.ID = "abcdefghijklmnopqrst"
		err := post.Save(nil)
		if err != nil {
			t.Fatal(err)
		}
	}()

	func() {
		post := model.NewPost("Example Title", &model.Time{time.Date(2015, 11, 28, 13, 2, 37, 0, time.UTC)}, nil)
		post.ID = "abcdefghijklmnopqrst"
		err := post.Save(nil)
		if err != nil {
			t.Fatal(err)
		}
	}()

	testutil.ShouldExistFile(t, 1)
}
開發者ID:minodisk,項目名稱:qiitactl,代碼行數:26,代碼來源:post_test.go

示例6: TestPostDecodeWithMultiComment

func TestPostDecodeWithMultiComment(t *testing.T) {
	testutil.CleanUp()
	defer testutil.CleanUp()

	var post model.Post
	err := post.Decode([]byte(`<!--
id: ""
url: ""
created_at: 2016-02-17T13:08:30+09:00
updated_at: 2016-02-17T13:08:30+09:00
private: false
coediting: false
tags:
- Qiita
- Go
team: null
-->

# Example Title

<!--
This is not meta
-->

# This is not title of this post
`))
	if err != nil {
		t.Fatal(err)
	}
}
開發者ID:minodisk,項目名稱:qiitactl,代碼行數:30,代碼來源:post_test.go

示例7: TestFetchPostsWitWrongResponseBody

func TestFetchPostsWitWrongResponseBody(t *testing.T) {
	testutil.CleanUp()
	defer testutil.CleanUp()

	mux := http.NewServeMux()
	mux.HandleFunc("/api/v2/authenticated_user/items", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "Non JSON format")
	})

	server := httptest.NewServer(mux)
	defer server.Close()

	err := os.Setenv("QIITA_ACCESS_TOKEN", "XXXXXXXXXXXX")
	if err != nil {
		t.Fatal(err)
	}

	client := api.NewClient(func(subDomain, path string) (url string) {
		url = fmt.Sprintf("%s%s%s", server.URL, "/api/v2", path)
		return
	}, inf)

	_, err = model.FetchPosts(client, nil)
	if err == nil {
		t.Fatal("error should occur")
	}
}
開發者ID:minodisk,項目名稱:qiitactl,代碼行數:27,代碼來源:posts_test.go

示例8: TestGenerateUniqueFile

func TestGenerateUniqueFile(t *testing.T) {
	testutil.CleanUp()
	defer testutil.CleanUp()

	err := os.Setenv("QIITA_ACCESS_TOKEN", "XXXXXXXXXXXX")
	if err != nil {
		log.Fatal(err)
	}
	client := api.NewClient(nil, inf)

	testutil.ShouldExistFile(t, 0)

	app := command.New(inf, client, os.Stdout, os.Stderr)
	app.Run([]string{"qiitactl", "generate", "file", "Example Title"})
	app.Run([]string{"qiitactl", "generate", "file", "Example Title"})

	testutil.ShouldExistFile(t, 2)

	path := fmt.Sprintf("mine/%s/Example Title.md", time.Now().Format("2006/01/02"))
	_, err = os.Stat(path)
	if err != nil {
		t.Errorf("file should exist at %s", path)
	}
	path = fmt.Sprintf("mine/%s/Example Title-.md", time.Now().Format("2006/01/02"))
	_, err = os.Stat(path)
	if err != nil {
		t.Errorf("file should exist at %s", path)
	}
}
開發者ID:minodisk,項目名稱:qiitactl,代碼行數:29,代碼來源:file_test.go

示例9: TestPostDeleteWithWrongResponseBody

func TestPostDeleteWithWrongResponseBody(t *testing.T) {
	testutil.CleanUp()
	defer testutil.CleanUp()

	mux := http.NewServeMux()
	mux.HandleFunc("/api/v2/items/abcdefghijklmnopqrst", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "Non JSON format")
	})

	server := httptest.NewServer(mux)
	defer server.Close()

	err := os.Setenv("QIITA_ACCESS_TOKEN", "XXXXXXXXXXXX")
	if err != nil {
		t.Fatal(err)
	}

	client := api.NewClient(func(subDomain, path string) (url string) {
		url = fmt.Sprintf("%s%s%s", server.URL, "/api/v2", path)
		return
	}, inf)

	post := model.NewPost("Example Title", nil, nil)
	post.ID = "abcdefghijklmnopqrst"
	err = post.Delete(client)
	// Don't parse response body from DELETE method
	if err != nil {
		t.Fatal(err)
	}
}
開發者ID:minodisk,項目名稱:qiitactl,代碼行數:30,代碼來源:post_test.go

示例10: TestClientPost

func TestClientPost(t *testing.T) {
	testutil.CleanUp()
	defer testutil.CleanUp()

	err := os.Setenv("QIITA_ACCESS_TOKEN", "XXXXXXXXXXXX")
	if err != nil {
		log.Fatal(err)
	}
	client := api.NewClient(func(subDomain, path string) (url string) {
		url = fmt.Sprintf("%s%s%s", server.URL, "/api/v2", path)
		return
	}, inf)
	client.DebugMode(true)

	body, _, err := client.Post("", "/echo", "data")
	if err != nil {
		t.Fatal(err)
	}

	var b string
	err = json.Unmarshal(body, &b)
	if err != nil {
		t.Fatal(err)
	}
	if b != "data" {
		t.Errorf("wrong body: %s", b)
	}
}
開發者ID:minodisk,項目名稱:qiitactl,代碼行數:28,代碼來源:client_test.go

示例11: TestPostDeleteWithNoServer

func TestPostDeleteWithNoServer(t *testing.T) {
	testutil.CleanUp()
	defer testutil.CleanUp()

	mux := http.NewServeMux()
	server := httptest.NewServer(mux)
	defer server.Close()

	err := os.Setenv("QIITA_ACCESS_TOKEN", "XXXXXXXXXXXX")
	if err != nil {
		t.Fatal(err)
	}

	client := api.NewClient(func(subDomain, path string) (url string) {
		url = fmt.Sprintf("%s%s%s", server.URL, "/api/v2", path)
		return
	}, inf)

	testutil.ShouldExistFile(t, 0)

	post := model.NewPost("Example Title", &model.Time{time.Date(2000, 1, 1, 9, 0, 0, 0, time.UTC)}, nil)
	post.ID = "abcdefghijklmnopqrst"
	err = post.Delete(client)
	if err == nil {
		t.Fatal("error should occur")
	}

	testutil.ShouldExistFile(t, 0)
}
開發者ID:minodisk,項目名稱:qiitactl,代碼行數:29,代碼來源:post_test.go

示例12: TestFetchPostWithID

func TestFetchPostWithID(t *testing.T) {
	testutil.CleanUp()
	defer testutil.CleanUp()

	mux := http.NewServeMux()
	handleItem(mux)
	serverMine := httptest.NewServer(mux)
	defer serverMine.Close()
	err := os.Setenv("QIITA_ACCESS_TOKEN", "XXXXXXXXXXXX")
	if err != nil {
		log.Fatal(err)
	}
	client := api.NewClient(func(subDomain, path string) (url string) {
		switch subDomain {
		case "":
			url = fmt.Sprintf("%s%s%s", serverMine.URL, "/api/v2", path)
		default:
			log.Fatalf("wrong sub domain \"%s\"", subDomain)
		}
		return
	}, inf)

	testutil.ShouldExistFile(t, 0)

	errBuf := bytes.NewBuffer([]byte{})
	app := command.New(inf, client, os.Stdout, errBuf)
	app.Run([]string{"qiitactl", "fetch", "post", "-i", "4bd431809afb1bb99e4f"})
	e := errBuf.Bytes()
	if len(e) != 0 {
		t.Fatal(string(e))
	}

	testutil.ShouldExistFile(t, 1)

	b, err := ioutil.ReadFile("mine/2000/01/01/Example Title.md")
	if err != nil {
		t.Fatal(err)
	}
	actual := string(b)
	expected := `<!--
id: 4bd431809afb1bb99e4f
url: https://qiita.com/yaotti/items/4bd431809afb1bb99e4f
created_at: 2000-01-01T09:00:00+09:00
updated_at: 2000-01-01T09:00:00+09:00
private: false
coediting: false
tags:
- Ruby:
  - 0.0.1
team: null
-->

# Example Title

## Example body`
	if actual != expected {
		t.Errorf("wrong body:\n%s", testutil.Diff(expected, actual))
	}
}
開發者ID:minodisk,項目名稱:qiitactl,代碼行數:59,代碼來源:post_test.go

示例13: TestNewPostWithFileWithNoFile

func TestNewPostWithFileWithNoFile(t *testing.T) {
	testutil.CleanUp()
	defer testutil.CleanUp()

	_, err := model.NewPostWithFile("mine/2013/12/10-main-title.md")
	if err == nil {
		t.Fatal("error should occur")
	}
}
開發者ID:minodisk,項目名稱:qiitactl,代碼行數:9,代碼來源:post_test.go

示例14: TestResponseError

func TestResponseError(t *testing.T) {
	testutil.CleanUp()
	defer testutil.CleanUp()

	err := api.ResponseError{
		Type:    "not_found",
		Message: "Not found",
	}
	if err.Error() != "Not found" {
		t.Errorf("wrong Error: %s", err.Error())
	}
}
開發者ID:minodisk,項目名稱:qiitactl,代碼行數:12,代碼來源:client_test.go

示例15: TestStatusError

func TestStatusError(t *testing.T) {
	testutil.CleanUp()
	defer testutil.CleanUp()

	err := api.StatusError{
		Code:    404,
		Message: "404 Not Found",
	}
	if err.Error() != "404 Not Found" {
		t.Errorf("wrong Error: %s", err.Error())
	}
}
開發者ID:minodisk,項目名稱:qiitactl,代碼行數:12,代碼來源:client_test.go


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