diff options
author | Steve Manuel <nilslice@gmail.com> | 2017-05-22 21:04:27 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-22 21:04:27 -0700 |
commit | 0b7f607b347e46c823774dabf4969758470ae6fd (patch) | |
tree | 9e5d292acba06e4d4b4e4e3009c7a6b7796f6035 /cmd/ponzu/new_test.go | |
parent | 66c3ad778ccf54566086d535a6ebe4805bf4241f (diff) | |
parent | 7276d308986bfcbd2bbe3d22e2887b622fab52e7 (diff) |
Merge pull request #148 from ponzu-cms/ponzu-dev
[cli] use spf13/cobra for command line interface
Diffstat (limited to 'cmd/ponzu/new_test.go')
-rw-r--r-- | cmd/ponzu/new_test.go | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/cmd/ponzu/new_test.go b/cmd/ponzu/new_test.go new file mode 100644 index 0000000..76cacb1 --- /dev/null +++ b/cmd/ponzu/new_test.go @@ -0,0 +1,66 @@ +package main + +import ( + "os" + "path/filepath" + "testing" +) + +func TestNewName2Path(t *testing.T) { + savedGOPATH := os.Getenv("GOPATH") + defer os.Setenv("GOPATH", savedGOPATH) + pwd, err := os.Getwd() + if err != nil { + t.Fatalf("Could not determine current working directory: %s", err) + } + + isNil := func(e error) bool { return e == nil } + isNonNil := func(e error) bool { return e != nil } + + baseDir := filepath.Join(pwd, "test-fixtures", "new") + + testTable := []struct { + gopath, wd, a, + wantP string + wantE func(e error) bool + }{{ + gopath: baseDir, + wd: filepath.Join("src", "existing"), + a: ".", + wantP: filepath.Join(pwd, "test-fixtures", "new", "src", "existing"), + wantE: os.IsExist, + }, { + gopath: baseDir, + wd: filepath.Join(""), + a: "non-existing", + wantP: filepath.Join(pwd, "test-fixtures", "new", "src", "non-existing"), + wantE: isNil, + }, { + gopath: baseDir, + wd: filepath.Join(""), + a: ".", + wantP: "", + wantE: isNonNil, + }, { + gopath: baseDir, + wd: "..", + a: ".", + wantP: "", + wantE: isNonNil, + }} + + for _, test := range testTable { + os.Setenv("GOPATH", test.gopath) + err = os.Chdir(filepath.Join(test.gopath, test.wd)) + if err != nil { + t.Fatalf("could not setup base: %s", err) + } + got, gotE := name2path(test.a) + if got != test.wantP { + t.Errorf("got '%s', want: '%s'", got, test.wantP) + } + if !test.wantE(gotE) { + t.Errorf("got error '%s'", gotE) + } + } +} |