This repository has been archived by the owner on Sep 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple approach to finding project root dir (#6)
- Loading branch information
Showing
4 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
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,42 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
func TestFindRoot(t *testing.T) { | ||
wd, err := os.Getwd() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
expect := filepath.Join(wd, "_testdata", "rootfind") | ||
|
||
got1, err := findProjectRoot(expect) | ||
if err != nil { | ||
t.Errorf("Unexpected error while finding root: %s", err) | ||
} else if expect != got1 { | ||
t.Errorf("findProjectRoot directly on root dir should have found %s, got %s", expect, got1) | ||
} | ||
|
||
got2, err := findProjectRoot(filepath.Join(expect, "subdir")) | ||
if err != nil { | ||
t.Errorf("Unexpected error while finding root: %s", err) | ||
} else if expect != got2 { | ||
t.Errorf("findProjectRoot on subdir should have found %s, got %s", expect, got2) | ||
} | ||
|
||
got3, err := findProjectRoot(filepath.Join(expect, "nonexistent")) | ||
if err != nil { | ||
t.Errorf("Unexpected error while finding root: %s", err) | ||
} else if expect != got3 { | ||
t.Errorf("findProjectRoot on nonexistent subdir should still work and give %s, got %s", expect, got3) | ||
} | ||
|
||
got4, err := findProjectRoot(filepath.Join(expect, ManifestName)) | ||
if err == nil { | ||
t.Errorf("Should have err'd when trying subdir of file, but returned %s", got4) | ||
} | ||
} |