当前位置: 首页>>代码示例>>Golang>>正文


Golang testutil.ShouldExistFile函数代码示例

本文整理汇总了Golang中github.com/minodisk/qiitactl/testutil.ShouldExistFile函数的典型用法代码示例。如果您正苦于以下问题:Golang ShouldExistFile函数的具体用法?Golang ShouldExistFile怎么用?Golang ShouldExistFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ShouldExistFile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestFetchPostWithResponseStatusError

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

	mux := http.NewServeMux()
	mux.HandleFunc("/api/v2/items/4bd431809afb1bb99e4f", 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)

	testutil.ShouldExistFile(t, 0)

	_, err = model.FetchPost(client, nil, "4bd431809afb1bb99e4f")
	if err == nil {
		t.Fatal("error should occur")
	}
	_, ok := err.(api.StatusError)
	if !ok {
		t.Fatalf("wrong type error: %s", reflect.TypeOf(err))
	}

	testutil.ShouldExistFile(t, 0)
}
开发者ID:minodisk,项目名称:qiitactl,代码行数:35,代码来源:post_test.go

示例2: 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

示例3: 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

示例4: 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

示例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: 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

示例7: TestShowPosts

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

	mux := http.NewServeMux()
	handleAuthenticatedUserItems(mux)
	handleTeams(mux)
	serverMine := httptest.NewServer(mux)
	defer serverMine.Close()
	mux = http.NewServeMux()
	handleAuthenticatedUserItemsWithTeam(mux)
	serverTeam := httptest.NewServer(mux)
	defer serverTeam.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)
		case "increments":
			url = fmt.Sprintf("%s%s%s", serverTeam.URL, "/api/v2", path)
		default:
			log.Fatalf("wrong sub domain \"%s\"", subDomain)
		}
		return
	}, inf)

	testutil.ShouldExistFile(t, 0)

	buf := bytes.NewBuffer([]byte{})
	errBuf := bytes.NewBuffer([]byte{})
	app := command.New(inf, client, buf, errBuf)
	app.Run([]string{"qiitactl", "show", "posts"})
	e := errBuf.Bytes()
	if len(e) != 0 {
		t.Fatal(string(e))
	}

	testutil.ShouldExistFile(t, 0)

	if string(buf.Bytes()) != `Posts in Qiita:
4bd431809afb1bb99e4f 2000/01/01 Example Title
Posts in Qiita:Team (Increments Inc.):
4bd431809afb1bb99e4t 2015/09/25 Example Title in team
` {
		t.Errorf("written text is wrong: %s", buf.Bytes())
	}
}
开发者ID:minodisk,项目名称:qiitactl,代码行数:50,代码来源:post_test.go

示例8: TestPostSaveWithPath

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

	testutil.ShouldExistFile(t, 0)

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

	testutil.ShouldExistFile(t, 1)

	func() {
		a, err := ioutil.ReadFile("foo/bar.md")
		if err != nil {
			t.Fatal(err)
		}
		actual := string(a)
		expected := `<!--
id: abcdefghijklmnopqrst
url: ""
created_at: 2015-11-28T22:02:37+09:00
updated_at: 2015-11-28T22:02:37+09:00
private: false
coediting: false
tags: []
team: null
-->

# Example Title

`
		if actual != expected {
			t.Errorf("wrong content:\n%s", testutil.Diff(expected, actual))
		}
	}()
}
开发者ID:minodisk,项目名称:qiitactl,代码行数:41,代码来源:post_test.go

示例9: TestPostUpdateWithEmptyID

func TestPostUpdateWithEmptyID(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)

	post := model.NewPost("Example Title", nil, nil)
	err = post.Update(client)
	err, ok := err.(model.EmptyIDError)
	if !ok {
		t.Fatal("empty ID error should occur")
	}

	testutil.ShouldExistFile(t, 0)
}
开发者ID:minodisk,项目名称:qiitactl,代码行数:21,代码来源:post_test.go

示例10: TestFetchPostWithWrongID

func TestFetchPostWithWrongID(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)

	buf := bytes.NewBuffer([]byte{})
	errBuf := bytes.NewBuffer([]byte{})
	app := command.New(inf, client, buf, errBuf)
	app.Run([]string{"qiitactl", "fetch", "post", "-i", "XXXXXXXXXXXXXXXXXXXX"})
	e := errBuf.Bytes()
	actual := string(e)
	expected := "404 Not Found\n"
	if actual != expected {
		t.Fatalf("error should occur when fetches post with wrong ID: %s", actual)
	}

	testutil.ShouldExistFile(t, 0)
}
开发者ID:minodisk,项目名称:qiitactl,代码行数:37,代码来源:post_test.go

示例11: TestUpdatePostWithNoServer

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

	mux := http.NewServeMux()
	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)

	err = os.MkdirAll("mine/2000/01/01", 0755)
	if err != nil {
		t.Fatal(err)
	}
	err = ioutil.WriteFile("mine/2000/01/01/Example Title.md", []byte(`<!--
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
- NewTag:
  - "1.0"
team: null
-->

# Example Edited Title

## Example Edited Body`), 0664)
	if err != nil {
		t.Fatal(err)
	}

	testutil.ShouldExistFile(t, 1)

	errBuf := bytes.NewBuffer([]byte{})
	app := command.New(inf, client, os.Stdout, errBuf)
	app.Run([]string{"qiitactl", "update", "post", "mine/2000/01/01/Example Title.md"})
	e := errBuf.Bytes()
	if len(e) == 0 {
		t.Fatal("error should occur")
	}

	testutil.ShouldExistFile(t, 1)
}
开发者ID:minodisk,项目名称:qiitactl,代码行数:61,代码来源:post_test.go

示例12: TestShowPostsErrors

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

	func() {
		mux := http.NewServeMux()
		handleTeams(mux)
		serverMine := httptest.NewServer(mux)
		defer serverMine.Close()
		mux = http.NewServeMux()
		handleAuthenticatedUserItemsWithTeam(mux)
		serverTeam := httptest.NewServer(mux)
		defer serverTeam.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)
			case "increments":
				url = fmt.Sprintf("%s%s%s", serverTeam.URL, "/api/v2", path)
			default:
				log.Fatalf("wrong sub domain \"%s\"", subDomain)
			}
			return
		}, inf)

		testutil.ShouldExistFile(t, 0)

		buf := bytes.NewBuffer([]byte{})
		errBuf := bytes.NewBuffer([]byte{})
		app := command.New(inf, client, buf, errBuf)
		app.Run([]string{"qiitactl", "show", "posts"})
		e := errBuf.Bytes()
		if len(e) == 0 {
			t.Fatal("error should occur")
		}
	}()

	func() {
		mux := http.NewServeMux()
		handleAuthenticatedUserItems(mux)
		serverMine := httptest.NewServer(mux)
		defer serverMine.Close()
		mux = http.NewServeMux()
		handleAuthenticatedUserItemsWithTeam(mux)
		serverTeam := httptest.NewServer(mux)
		defer serverTeam.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)
			case "increments":
				url = fmt.Sprintf("%s%s%s", serverTeam.URL, "/api/v2", path)
			default:
				log.Fatalf("wrong sub domain \"%s\"", subDomain)
			}
			return
		}, inf)

		testutil.ShouldExistFile(t, 0)

		buf := bytes.NewBuffer([]byte{})
		errBuf := bytes.NewBuffer([]byte{})
		app := command.New(inf, client, buf, errBuf)
		app.Run([]string{"qiitactl", "show", "posts"})
		e := errBuf.Bytes()
		if len(e) == 0 {
			t.Fatal("error should occur")
		}
	}()

	func() {
		mux := http.NewServeMux()
		handleAuthenticatedUserItems(mux)
		handleTeams(mux)
		serverMine := httptest.NewServer(mux)
		defer serverMine.Close()
		mux = http.NewServeMux()
		serverTeam := httptest.NewServer(mux)
		defer serverTeam.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)
			case "increments":
				url = fmt.Sprintf("%s%s%s", serverTeam.URL, "/api/v2", path)
			default:
				log.Fatalf("wrong sub domain \"%s\"", subDomain)
			}
//.........这里部分代码省略.........
开发者ID:minodisk,项目名称:qiitactl,代码行数:101,代码来源:post_test.go

示例13: TestPostUpdateInTeam

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

	mux := http.NewServeMux()
	mux.HandleFunc("/api/v2/items/abcdefghijklmnopqrst", func(w http.ResponseWriter, r *http.Request) {
		if r.Method != "PATCH" {
			w.WriteHeader(405)
			b, _ := json.Marshal(api.ResponseError{"method_not_allowed", "Method Not Allowed"})
			w.Write(b)
			return
		}

		defer r.Body.Close()

		b, err := ioutil.ReadAll(r.Body)
		if err != nil {
			testutil.ResponseError(w, 500, err)
			return
		}
		if string(b) == "" {
			testutil.ResponseAPIError(w, 500, api.ResponseError{
				Type:    "fatal",
				Message: "empty body",
			})
			return
		}

		var post model.Post
		err = json.Unmarshal(b, &post)
		if err != nil {
			testutil.ResponseError(w, 500, err)
			return
		}

		post.UpdatedAt = model.Time{Time: time.Date(2016, 2, 1, 12, 51, 42, 0, time.UTC)}
		b, err = json.Marshal(post)
		if err != nil {
			testutil.ResponseError(w, 500, err)
			return
		}

		_, err = w.Write(b)
		if err != nil {
			testutil.ResponseError(w, 500, err)
			return
		}
	})

	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) {
		if subDomain != "increments" {
			t.Fatalf("wrong sub domain: %s", subDomain)
			return
		}
		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)}, &model.Team{Active: true, ID: "increments", Name: "Increments Inc."})
	post.ID = "abcdefghijklmnopqrst"

	prevPath := post.Path
	if err != nil {
		t.Fatal(err)
	}

	err = post.Update(client)
	if err != nil {
		t.Fatal(err)
	}

	postPath := post.Path
	if err != nil {
		t.Fatal(err)
	}
	if postPath != prevPath {
		t.Errorf("wrong path: expected %s, but actual %s", prevPath, postPath)
	}

	if !post.UpdatedAt.Equal(time.Date(2016, 2, 1, 12, 51, 42, 0, time.UTC)) {
		t.Errorf("wrong UpdatedAt: %s", post.UpdatedAt)
	}

	testutil.ShouldExistFile(t, 0)
}
开发者ID:minodisk,项目名称:qiitactl,代码行数:95,代码来源:post_test.go

示例14: TestPostSaveWithTeam

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

	testutil.ShouldExistFile(t, 0)

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

	testutil.ShouldExistFile(t, 1)

	func() {
		a, err := ioutil.ReadFile("increments/2015/11/28/Example Title.md")
		if err != nil {
			t.Fatal(err)
		}
		actual := string(a)
		expected := `<!--
id: abcdefghijklmnopqrst
url: ""
created_at: 2015-11-28T22:02:37+09:00
updated_at: 2015-11-28T22:02:37+09:00
private: false
coediting: false
tags: []
team:
  active: true
  id: increments
  name: Increments Inc.
-->

# Example Title

`
		if actual != expected {
			t.Errorf("wrong content:\n%s", testutil.Diff(expected, actual))
		}
	}()

	post.Title = "Example Edited Title"
	post.CreatedAt = model.Time{time.Date(2015, 12, 28, 13, 2, 37, 0, time.UTC)}
	post.UpdatedAt = post.CreatedAt
	err = post.Save(nil)
	if err != nil {
		t.Fatal(err)
	}

	testutil.ShouldExistFile(t, 1)

	func() {
		_, err := os.Stat("increments/2015/12/28/Example Edited Title.md")
		if err == nil {
			t.Errorf("filename based on edited post shouldn't exist: %s", "mine/2015/12/28/Example Edited Title.md")
		}
	}()

	func() {
		a, err := ioutil.ReadFile("increments/2015/11/28/Example Title.md")
		if err != nil {
			t.Fatal(err)
		}
		actual := string(a)
		expected := `<!--
id: abcdefghijklmnopqrst
url: ""
created_at: 2015-12-28T22:02:37+09:00
updated_at: 2015-12-28T22:02:37+09:00
private: false
coediting: false
tags: []
team:
  active: true
  id: increments
  name: Increments Inc.
-->

# Example Edited Title

`
		if actual != expected {
			t.Errorf("wrong content:\n%s", testutil.Diff(expected, actual))
		}
	}()
}
开发者ID:minodisk,项目名称:qiitactl,代码行数:88,代码来源:post_test.go

示例15: TestFetchPost

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

	mux := http.NewServeMux()
	mux.HandleFunc("/api/v2/items/4bd431809afb1bb99e4f", func(w http.ResponseWriter, r *http.Request) {
		if r.Method != "GET" {
			w.WriteHeader(405)
			b, _ := json.Marshal(api.ResponseError{"method_not_allowed", "Method Not Allowed"})
			w.Write(b)
			return
		}

		body := `{
			"rendered_body": "<h2>Example body</h2>",
			"body": "## Example body",
			"coediting": false,
			"created_at": "2000-01-01T00:00:00+00:00",
			"id": "4bd431809afb1bb99e4f",
			"private": false,
			"tags": [
				{
					"name": "Ruby",
					"versions": [
						"0.0.1"
					]
				}
			],
			"title": "Example title",
			"updated_at": "2000-01-01T00:00:00+00:00",
			"url": "https://qiita.com/yaotti/items/4bd431809afb1bb99e4f",
			"user": {
				"description": "Hello, world.",
				"facebook_id": "yaotti",
				"followees_count": 100,
				"followers_count": 200,
				"github_login_name": "yaotti",
				"id": "yaotti",
				"items_count": 300,
				"linkedin_id": "yaotti",
				"location": "Tokyo, Japan",
				"name": "Hiroshige Umino",
				"organization": "Increments Inc",
				"permanent_id": 1,
				"profile_image_url": "https://si0.twimg.com/profile_images/2309761038/1ijg13pfs0dg84sk2y0h_normal.jpeg",
				"twitter_screen_name": "yaotti",
				"website_url": "http://yaotti.hatenablog.com"
			}
		}`
		w.Write([]byte(body))
	})

	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)

	team := model.Team{
		Active: true,
		ID:     "increments",
		Name:   "Increments Inc",
	}
	post, err := model.FetchPost(client, &team, "4bd431809afb1bb99e4f")
	if err != nil {
		t.Fatal(err)
	}

	if post.RenderedBody != "<h2>Example body</h2>" {
		t.Errorf("wrong RenderedBody: %s", post.RenderedBody)
	}
	if post.Body != "## Example body" {
		t.Errorf("wrong Body: %s", post.Body)
	}
	if post.Coediting != false {
		t.Errorf("wrong Coediting: %b", post.Coediting)
	}
	if !post.CreatedAt.Equal(time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC)) {
		t.Errorf("wrong CreatedAt: %s", post.CreatedAt)
	}
	if post.ID != "4bd431809afb1bb99e4f" {
		t.Errorf("wrong ID: %s", post.ID)
	}
	if post.Private != false {
		t.Errorf("wrong Private: %b", post.Private)
	}
	if post.Title != "Example title" {
		t.Errorf("wrong Title: %s", post.Title)
	}
	if !post.UpdatedAt.Equal(time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC)) {
		t.Errorf("wrong UpdatedAt: %s", post.UpdatedAt)
//.........这里部分代码省略.........
开发者ID:minodisk,项目名称:qiitactl,代码行数:101,代码来源:post_test.go


注:本文中的github.com/minodisk/qiitactl/testutil.ShouldExistFile函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。