Skip to content

Commit

Permalink
Add test for findClosestParentPath to check for figtree regression
Browse files Browse the repository at this point in the history
I inadvertently 'upgraded' to coryb/figtree v1.0.0, and it caused an
error in findCLosestParentPath, due to figtree.FindParentPaths having
a different function signature in v1.0.0

No idea why a regular compile isn't picking this up - but when
explicitly testing like this, we get the error detailed in #277:

```
Mikes-MBP:jira mike$ go test ./...
?       github.com/go-jira/jira [no test files]
jiracli/util.go:29:34: too many arguments in call to figtree.FindParentPaths
        have (string, string, string)
        want (string)
jiracli/util.go:29:34: too many arguments in call to figtree.FindParentPaths
        have (string, string, string)
        want (string)
FAIL    github.com/go-jira/jira/jiracli [build failed]
ok      github.com/go-jira/jira/jiradata        (cached)
Mikes-MBP:jira mike$
```
  • Loading branch information
mikepea committed Sep 16, 2019
1 parent 27f57b2 commit c442e2c
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions jiracli/util_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package jiracli

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
)

func realPath(path string) string {
cpath, err := filepath.EvalSymlinks(path)
if err != nil {
log.Fatal(err)
}
return cpath
}

func comparePaths(p1 string, p2 string) bool {
if realPath(p1) == realPath(p2) {
return true
}
return false
}

func TestFindClosestParentPath(t *testing.T) {
dir, err := ioutil.TempDir("", "testFindParentPath")
if err != nil {
log.Fatal(err)
}
defer os.RemoveAll(dir)

origDir, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
defer os.Chdir(origDir)

t1 := filepath.Join(dir, "/.test1")
t2 := filepath.Join(t1, "/.test2")
t3 := filepath.Join(t2, "/.test1")
err = os.MkdirAll(t3, os.ModePerm)
if err != nil {
log.Fatal(err)
}
os.Chdir(t3)

path1, err := findClosestParentPath(".test1")
if err != nil {
t.Errorf("findClosestParentPath should not have errored: %s", err)
}
if ok := comparePaths(path1, t3); !ok {
t.Errorf("%s != %s", path1, t3)
}

path2, err := findClosestParentPath(".test2")
if err != nil {
t.Errorf("findClosestParentPath should not have errored: %s", err)
}
if ok := comparePaths(path2, t2); !ok {
t.Errorf("%s != %s", path2, t2)
}

path3, err := findClosestParentPath(".test3")
if err.Error() != ".test3 not found in parent directory hierarchy" {
t.Errorf("incorrect error from findClosestParentPath: %s", err)
}
if path3 != "" {
t.Errorf("path3 should be empty, but is not: %s", path3)
}

}

0 comments on commit c442e2c

Please sign in to comment.