-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Modified ApplyXxx functions to accept an io.Writer. Responsibility of creating the correct type of writer (e.g. stdout or file) is now within applyCmds. - Failed test assertions now display the real location when available
- Loading branch information
Showing
5 changed files
with
220 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package lib | ||
|
||
import ( | ||
"bytes" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestApplyBranch(t *testing.T) { | ||
clean() | ||
repo, err := createTestRepository(".tmp/repo") | ||
check(t, err) | ||
|
||
check(t, repo.InitModule("app-a")) | ||
check(t, repo.WriteContent("template.tmpl", ` | ||
{{- range $i, $mod := .Modules}} | ||
{{- $mod.Name }}, | ||
{{- end}} | ||
`)) | ||
check(t, repo.Commit("first")) | ||
|
||
check(t, repo.SwitchToBranch("feature")) | ||
check(t, repo.InitModule("app-b")) | ||
check(t, repo.Commit("second")) | ||
|
||
output := new(bytes.Buffer) | ||
check(t, ApplyBranch(".tmp/repo", "template.tmpl", "feature", output)) | ||
|
||
assert.Equal(t, "app-a,app-b,\n", output.String()) | ||
} | ||
|
||
func TestApplyCommit(t *testing.T) { | ||
clean() | ||
repo, err := createTestRepository(".tmp/repo") | ||
check(t, err) | ||
|
||
check(t, repo.InitModule("app-a")) | ||
check(t, repo.WriteContent("template.tmpl", ` | ||
{{- range $i, $mod := .Modules}} | ||
{{- $mod.Name }}, | ||
{{- end}} | ||
`)) | ||
check(t, repo.Commit("first")) | ||
|
||
check(t, repo.InitModule("app-b")) | ||
check(t, repo.Commit("second")) | ||
|
||
output := new(bytes.Buffer) | ||
check(t, ApplyCommit(".tmp/repo", repo.LastCommit.String(), "template.tmpl", output)) | ||
|
||
assert.Equal(t, "app-a,app-b,\n", output.String()) | ||
} | ||
|
||
func TestApplyLocal(t *testing.T) { | ||
clean() | ||
repo, err := createTestRepository(".tmp/repo") | ||
check(t, err) | ||
|
||
check(t, repo.InitModule("app-a")) | ||
check(t, repo.WriteContent("template.tmpl", ` | ||
{{- range $i, $mod := .Modules}} | ||
{{- $mod.Name }}, | ||
{{- end}} | ||
`)) | ||
check(t, repo.Commit("first")) | ||
|
||
check(t, repo.InitModule("app-b")) | ||
check(t, repo.Commit("second")) | ||
|
||
output := new(bytes.Buffer) | ||
check(t, ApplyLocal(".tmp/repo", "template.tmpl", output)) | ||
|
||
assert.Equal(t, "app-a,app-b,\n", output.String()) | ||
} | ||
|
||
func TestIncorrectTemplatePath(t *testing.T) { | ||
clean() | ||
repo, err := createTestRepository(".tmp/repo") | ||
check(t, err) | ||
|
||
check(t, repo.InitModule("app-a")) | ||
check(t, repo.WriteContent("template.tmpl", ` | ||
{{- range $i, $mod := .Modules}} | ||
{{- $mod.Name }}, | ||
{{- end}} | ||
`)) | ||
check(t, repo.Commit("first")) | ||
|
||
output := new(bytes.Buffer) | ||
err = ApplyCommit(".tmp/repo", repo.LastCommit.String(), "foo/template.tmpl", output) | ||
|
||
assert.EqualError(t, err, "mbt: the path 'foo' does not exist in the given tree") | ||
assert.Equal(t, "", output.String()) | ||
} | ||
|
||
func TestBadTemplate(t *testing.T) { | ||
clean() | ||
repo, err := createTestRepository(".tmp/repo") | ||
check(t, err) | ||
|
||
check(t, repo.InitModule("app-a")) | ||
check(t, repo.WriteContent("template.tmpl", ` | ||
{{- range $i, $mod := .Modules}} | ||
`)) | ||
check(t, repo.Commit("first")) | ||
|
||
output := new(bytes.Buffer) | ||
err = ApplyCommit(".tmp/repo", repo.LastCommit.String(), "template.tmpl", output) | ||
|
||
assert.EqualError(t, err, "mbt: template: template:2: unexpected EOF") | ||
assert.Equal(t, "", output.String()) | ||
} | ||
|
||
func TestEnvironmentVariables(t *testing.T) { | ||
clean() | ||
repo, err := createTestRepository(".tmp/repo") | ||
check(t, err) | ||
|
||
check(t, repo.InitModule("app-a")) | ||
check(t, repo.WriteContent("template.tmpl", "{{.Env.EXTERNAL_VALUE}}")) | ||
check(t, repo.Commit("first")) | ||
|
||
os.Setenv("EXTERNAL_VALUE", "FOO") | ||
|
||
output := new(bytes.Buffer) | ||
check(t, ApplyCommit(".tmp/repo", repo.LastCommit.String(), "template.tmpl", output)) | ||
|
||
assert.Equal(t, "FOO", output.String()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters