Beispiel #1
0
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")
	}
}
Beispiel #2
0
func TestNewPostWithFileWithWrongFormattedFile(t *testing.T) {
	testutil.CleanUp()
	defer testutil.CleanUp()

	err := os.MkdirAll("mine/2013/12", 0755)
	if err != nil {
		t.Fatal(err)
	}
	err = ioutil.WriteFile("mine/2013/12/10-main-title.md", []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
Paragraph
`), 0644)
	if err != nil {
		t.Fatal(err)
	}

	_, err = model.NewPostWithFile("mine/2013/12/10-main-title.md")
	if err == nil {
		t.Fatal("error should occur")
	}
}
Beispiel #3
0
func TestNewPostWithFile(t *testing.T) {
	testutil.CleanUp()
	defer testutil.CleanUp()

	err := os.MkdirAll("mine/2013/12", 0755)
	if err != nil {
		t.Fatal(err)
	}
	err = ioutil.WriteFile("mine/2013/12/10-main-title.md", []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
-->

# Main title

## Sub title
Paragraph
`), 0644)
	if err != nil {
		t.Fatal(err)
	}

	post, err := model.NewPostWithFile("mine/2013/12/10-main-title.md")
	if err != nil {
		t.Fatal(err)
	}
	if post.Meta.ID != "abcdefghijklmnopqrst" {
		t.Errorf("wrong Id")
	}
	if post.Meta.URL != "http://example.com/mypost" {
		t.Errorf("wrong Url")
	}
	if !post.Meta.CreatedAt.Equal(time.Date(2013, 12, 10, 3, 29, 14, 0, time.UTC)) {
		t.Errorf("wrong CreatedAt")
	}
	if !post.Meta.UpdatedAt.Equal(time.Date(2015, 02, 25, 0, 26, 30, 0, time.UTC)) {
		t.Errorf("wrong UpdatedAt")
	}
	if post.Meta.Private != true {
		t.Errorf("wrong Private")
	}
	if post.Meta.Coediting != false {
		t.Errorf("wrong Coediting")
	}
	if len(post.Meta.Tags) != 3 {
		t.Errorf("wrong Tags length: %d", len(post.Meta.Tags))
	} else {
		for _, tag := range post.Meta.Tags {
			switch tag.Name {
			case "TypeScript":
				if len(tag.Versions) != 0 {
					t.Errorf("wrong Tag with no version: %+v", tag)
				}
			case "Docker":
				if len(tag.Versions) != 1 || tag.Versions[0] != "1.9" {
					t.Errorf("wrong Tag with single version: %+v", tag)
				}
			case "Go":
				if len(tag.Versions) != 2 || tag.Versions[0] != "1.4.3" || tag.Versions[1] != "1.5.3" {
					t.Errorf("wrong Tag with multi versions: %+v", tag)
				}
			}
		}
	}
	if post.Title != "Main title" {
		t.Errorf("wrong Title")
	}
	if post.Body != "## Sub title\nParagraph" {
		t.Errorf("wrong Body: %s", post.Body)
	}
}