Skip to content

Commit

Permalink
Add test for GenerateFile with team
Browse files Browse the repository at this point in the history
  • Loading branch information
minodisk committed Feb 4, 2016
1 parent c691e66 commit 5fb83c3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
4 changes: 3 additions & 1 deletion command/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ func GenerateFile(c *cli.Context, client api.Client) (err error) {

var team *model.Team
if teamID != "" {
team.ID = teamID
team = &model.Team{
ID: teamID,
}
}
post := model.NewPost(title, nil, team)
err = post.Save()
Expand Down
32 changes: 28 additions & 4 deletions command/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/minodisk/qiitactl/testutil"
)

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

Expand All @@ -23,15 +23,39 @@ func TestGenerateFile(t *testing.T) {
t.Fatal(err)
}

matched, err := filepath.Glob(fmt.Sprintf("%s/*/*/*.md", model.DirMine))
matched, err := filepath.Glob("*/*/*/*.md")
if err != nil {
t.Fatal(err)
}
if len(matched) != 1 {
t.Fatalf("wrong number of files: %d", len(matched))
}
actual := matched[0]
expected := fmt.Sprintf("%s/%s-example-title.md", model.DirMine, time.Now().Format("2006/01/02"))
expected := fmt.Sprintf("mine/%s-example-title.md", time.Now().Format("2006/01/02"))
if actual != expected {
t.Errorf("wrong path: expected %s, but actual %s", expected, actual)
}
}

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

app := cli.GenerateApp(client, os.Stdout, os.Stderr)
err := app.Run([]string{"qiitactl", "generate", "file", "-t", "Example Title", "-T", "increments"})
if err != nil {
t.Fatal(err)
}

matched, err := filepath.Glob("*/*/*/*.md")
if err != nil {
t.Fatal(err)
}
if len(matched) != 1 {
t.Fatalf("wrong number of files: %d", len(matched))
}
actual := matched[0]
expected := fmt.Sprintf("increments/%s-example-title.md", time.Now().Format("2006/01/02"))
if actual != expected {
t.Errorf("wrong path: expected %s, but actual %s", expected, actual)
}
Expand All @@ -51,7 +75,7 @@ func TestGenerateUniqueFile(t *testing.T) {
t.Fatal(err)
}

matched, err := filepath.Glob(fmt.Sprintf("%s/*/*/*.md", model.DirMine))
matched, err := filepath.Glob("*/*/*/*.md")
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 5fb83c3

Please sign in to comment.