| 1 |
package cmd |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
|
| 6 |
"github.com/miniscruff/changie/core" |
| 7 |
"github.com/miniscruff/changie/then" |
| 8 |
) |
| 9 |
|
| 10 |
func initConfig() *core.Config { |
| 11 |
return &core.Config{ |
| 12 |
ChangesDir: ".changes", |
| 13 |
UnreleasedDir: "unreleased", |
| 14 |
HeaderPath: "header.tpl.md", |
| 15 |
ChangelogPath: "CHANGELOG.md", |
| 16 |
VersionExt: "md", |
| 17 |
VersionFormat: "", |
| 18 |
KindFormat: "", |
| 19 |
ChangeFormat: "", |
| 20 |
Kinds: []core.KindConfig{}, |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
func TestInitBuildsDefaultSkeleton(t *testing.T) { |
| 25 |
then.WithTempDir(t) |
| 26 |
|
| 27 |
cfg := initConfig() |
| 28 |
cmd := NewInit() |
| 29 |
err := cmd.Run(cmd.Command, nil) |
| 30 |
|
| 31 |
then.Nil(t, err) |
| 32 |
then.FileContents(t, defaultHeader, cfg.ChangesDir, cfg.HeaderPath) |
| 33 |
then.FileContents(t, defaultChangelog, cfg.ChangelogPath) |
| 34 |
then.FileContents(t, "", cfg.ChangesDir, cfg.UnreleasedDir, ".gitkeep") |
| 35 |
} |
| 36 |
|
| 37 |
func TestInitBuildsConfigIfConfigExistsIfForced(t *testing.T) { |
| 38 |
cfg := initConfig() |
| 39 |
then.WithTempDirConfig(t, cfg) |
| 40 |
|
| 41 |
cmd := NewInit() |
| 42 |
cmd.Force = true |
| 43 |
err := cmd.Run(cmd.Command, nil) |
| 44 |
|
| 45 |
then.Nil(t, err) |
| 46 |
then.FileContents(t, defaultHeader, cfg.ChangesDir, cfg.HeaderPath) |
| 47 |
then.FileContents(t, defaultChangelog, cfg.ChangelogPath) |
| 48 |
then.FileContents(t, "", cfg.ChangesDir, cfg.UnreleasedDir, ".gitkeep") |
| 49 |
} |
| 50 |
|
| 51 |
func TestErrorInitFileExists(t *testing.T) { |
| 52 |
cfg := initConfig() |
| 53 |
then.WithTempDirConfig(t, cfg) |
| 54 |
|
| 55 |
cmd := NewInit() |
| 56 |
err := cmd.Run(cmd.Command, nil) |
| 57 |
then.Err(t, errConfigExists, err) |
| 58 |
} |