Пример #1
0
// FetchPosts fetches your posts from Qiita to current working directory.
func (r FetchPostsRunner) Run(c api.Client, o GlobalOptions, w io.Writer) (err error) {
	posts, err := model.FetchPosts(c, nil)
	if err != nil {
		return
	}
	err = posts.Save()
	if err != nil {
		return
	}

	teams, err := model.FetchTeams(c)
	if err != nil {
		return
	}
	for _, team := range teams {
		var posts model.Posts
		posts, err = model.FetchPosts(c, &team)
		if err != nil {
			return
		}
		err = posts.Save()
		if err != nil {
			return
		}
	}
	return
}
Пример #2
0
func BenchmarkPostsSave(b *testing.B) {
	testutil.CleanUp()
	defer testutil.CleanUp()

	var posts model.Posts
	for i := 0; i < b.N; i++ {
		posts = append(posts, model.NewPost(fmt.Sprintf("Example Title %d", i), nil, nil))
	}

	b.ResetTimer()

	err := posts.Save()
	if err != nil {
		b.Fatal(err)
	}
}
Пример #3
0
func TestPostsSave(t *testing.T) {
	testutil.CleanUp()
	defer testutil.CleanUp()

	post0 := model.NewPost("Example Title 0", &model.Time{time.Date(2015, 11, 28, 13, 2, 37, 0, time.UTC)}, nil)
	post1 := model.NewPost("Example Title 1", &model.Time{time.Date(2016, 2, 1, 5, 21, 49, 0, time.UTC)}, nil)

	posts := model.Posts{post0, post1}
	err := posts.Save()
	if err != nil {
		t.Fatal(err)
	}

	func() {
		a, err := ioutil.ReadFile("mine/2015/11/28/Example Title 0.md")
		if err != nil {
			t.Fatal(err)
		}
		actual := string(a)
		expected := `<!--
id: ""
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 0

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

	func() {
		a, err := ioutil.ReadFile("mine/2016/02/01/Example Title 1.md")
		if err != nil {
			t.Fatal(err)
		}
		actual := string(a)
		expected := `<!--
id: ""
url: ""
created_at: 2016-02-01T14:21:49+09:00
updated_at: 2016-02-01T14:21:49+09:00
private: false
coediting: false
tags: []
team: null
-->

# Example Title 1

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