forked from magefile/mage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement importing magefiles (magefile#187)
implement mageimports
- Loading branch information
Showing
10 changed files
with
664 additions
and
133 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package mage | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
) | ||
|
||
func TestMageImportsList(t *testing.T) { | ||
stdout := &bytes.Buffer{} | ||
stderr := &bytes.Buffer{} | ||
inv := Invocation{ | ||
Dir: "./testdata/mageimport", | ||
Stdout: stdout, | ||
Stderr: stderr, | ||
List: true, | ||
} | ||
|
||
code := Invoke(inv) | ||
if code != 0 { | ||
t.Fatalf("expected to exit with code 0, but got %v, stderr:\n%s", code, stderr) | ||
} | ||
actual := stdout.String() | ||
expected := ` | ||
Targets: | ||
root | ||
zz:nS:deploy2 deploys stuff. | ||
zz:buildSubdir2 Builds stuff. | ||
nS:deploy deploys stuff. | ||
buildSubdir Builds stuff. | ||
`[1:] | ||
|
||
if actual != expected { | ||
t.Logf("expected: %q", expected) | ||
t.Logf(" actual: %q", actual) | ||
t.Fatalf("expected:\n%v\n\ngot:\n%v", expected, actual) | ||
} | ||
} | ||
|
||
func TestMageImportsRoot(t *testing.T) { | ||
stdout := &bytes.Buffer{} | ||
stderr := &bytes.Buffer{} | ||
inv := Invocation{ | ||
Dir: "./testdata/mageimport", | ||
Stdout: stdout, | ||
Stderr: stderr, | ||
Args: []string{"root"}, | ||
} | ||
|
||
code := Invoke(inv) | ||
if code != 0 { | ||
t.Fatalf("expected to exit with code 0, but got %v, stderr:\n%s", code, stderr) | ||
} | ||
actual := stdout.String() | ||
expected := "root\n" | ||
if actual != expected { | ||
t.Fatalf("expected: %q got: %q", expected, actual) | ||
} | ||
} | ||
|
||
func TestMageImportsNamedNS(t *testing.T) { | ||
stdout := &bytes.Buffer{} | ||
stderr := &bytes.Buffer{} | ||
inv := Invocation{ | ||
Dir: "./testdata/mageimport", | ||
Stdout: stdout, | ||
Stderr: stderr, | ||
Args: []string{"zz:nS:deploy2"}, | ||
} | ||
|
||
code := Invoke(inv) | ||
if code != 0 { | ||
t.Fatalf("expected to exit with code 0, but got %v, stderr:\n%s", code, stderr) | ||
} | ||
actual := stdout.String() | ||
expected := "deploy2\n" | ||
if actual != expected { | ||
t.Fatalf("expected: %q got: %q", expected, actual) | ||
} | ||
} | ||
|
||
func TestMageImportsNamedRoot(t *testing.T) { | ||
stdout := &bytes.Buffer{} | ||
stderr := &bytes.Buffer{} | ||
inv := Invocation{ | ||
Dir: "./testdata/mageimport", | ||
Stdout: stdout, | ||
Stderr: stderr, | ||
Args: []string{"zz:buildSubdir2"}, | ||
} | ||
|
||
code := Invoke(inv) | ||
if code != 0 { | ||
t.Fatalf("expected to exit with code 0, but got %v, stderr:\n%s", code, stderr) | ||
} | ||
actual := stdout.String() | ||
expected := "buildsubdir2\n" | ||
if actual != expected { | ||
t.Fatalf("expected: %q got: %q", expected, actual) | ||
} | ||
} | ||
|
||
func TestMageImportsRootImportNS(t *testing.T) { | ||
stdout := &bytes.Buffer{} | ||
stderr := &bytes.Buffer{} | ||
inv := Invocation{ | ||
Dir: "./testdata/mageimport", | ||
Stdout: stdout, | ||
Stderr: stderr, | ||
Args: []string{"nS:deploy"}, | ||
} | ||
|
||
code := Invoke(inv) | ||
if code != 0 { | ||
t.Fatalf("expected to exit with code 0, but got %v, stderr:\n%s", code, stderr) | ||
} | ||
actual := stdout.String() | ||
expected := "deploy\n" | ||
if actual != expected { | ||
t.Fatalf("expected: %q got: %q", expected, actual) | ||
} | ||
} | ||
|
||
func TestMageImportsRootImport(t *testing.T) { | ||
stdout := &bytes.Buffer{} | ||
stderr := &bytes.Buffer{} | ||
inv := Invocation{ | ||
Dir: "./testdata/mageimport", | ||
Stdout: stdout, | ||
Stderr: stderr, | ||
Args: []string{"buildSubdir"}, | ||
} | ||
|
||
code := Invoke(inv) | ||
if code != 0 { | ||
t.Fatalf("expected to exit with code 0, but got %v, stderr:\n%s", code, stderr) | ||
} | ||
actual := stdout.String() | ||
expected := "buildsubdir\n" | ||
if actual != expected { | ||
t.Fatalf("expected: %q got: %q", expected, actual) | ||
} | ||
} |
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
Oops, something went wrong.