diff options
author | Martin Treusch von Buttlar <martin.tvb@vitraum.de> | 2017-05-20 10:14:13 +0200 |
---|---|---|
committer | Martin Treusch von Buttlar <martin.tvb@vitraum.de> | 2017-05-20 10:14:13 +0200 |
commit | 372ce32e444c34c9107b5da22c847eb368466cc9 (patch) | |
tree | cb3ce02d0e52d242fcb15e581702775a82128c4d /cmd/ponzu/new_test.go | |
parent | 0e98babf9b4f9084d7e29b0f484f64ba62dc265b (diff) |
add checks for 'ponzu new' fixes ponzu-cms/ponzu#146
Diffstat (limited to 'cmd/ponzu/new_test.go')
-rw-r--r-- | cmd/ponzu/new_test.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/cmd/ponzu/new_test.go b/cmd/ponzu/new_test.go new file mode 100644 index 0000000..a143d1a --- /dev/null +++ b/cmd/ponzu/new_test.go @@ -0,0 +1,51 @@ +package main + +import ( + "os" + "path/filepath" + "testing" +) + +func TestNewCheckNmkAbs(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 } + + testTable := []struct { + base, wd, a, + wantP string + wantE func(e error) bool + }{{ + base: filepath.Join(pwd, "test-fixtures", "new"), + wd: filepath.Join("src", "existing"), + a: ".", + wantP: filepath.Join(pwd, "test-fixtures", "new", "src", "existing"), + wantE: os.IsExist, + }, { + base: filepath.Join(pwd, "test-fixtures", "new"), + wd: filepath.Join(""), + a: "non-existing", + wantP: filepath.Join(pwd, "test-fixtures", "new", "src", "non-existing"), + wantE: isNil, + }} + + for _, test := range testTable { + os.Setenv("GOPATH", test.base) + err = os.Chdir(filepath.Join(test.base, test.wd)) + if err != nil { + t.Fatalf("could not setup base: %s", err) + } + got, gotE := checkNmkAbs(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) + } + } +} |