-
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.
Merge pull request #22 from hourglasshoro/bugfix/21_relative_path
Fixed a bug that prevented you from specifying a path with al…
- Loading branch information
Showing
3 changed files
with
55 additions
and
8 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
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,18 @@ | ||
package imput | ||
|
||
import ( | ||
"path" | ||
"path/filepath" | ||
) | ||
|
||
// Solve resolves the path of the root directory to be searched from the input source and currentDir | ||
func Solve(source string, currentDir string) (graphDir string) { | ||
if source != "" && !filepath.IsAbs(source) { | ||
graphDir = path.Join(currentDir, source) | ||
} else if filepath.IsAbs(source) { | ||
graphDir = source | ||
} else { | ||
graphDir = currentDir | ||
} | ||
return | ||
} |
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,32 @@ | ||
package imput | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
// Solve Test | ||
|
||
// TestSolveWithNoSource tests to validate when not specified in the -s option | ||
func TestSolveWithNoSource(t *testing.T) { | ||
source := "" | ||
actual := Solve(source, "/User/test//app") | ||
expected := "/User/test//app" | ||
assert.Equal(t, expected, actual) | ||
} | ||
|
||
// TestSolveWithNoSource tests to validate when a relative path is specified with the -s option | ||
func TestSolveWithRelativePath(t *testing.T) { | ||
source := "../app2" | ||
actual := Solve(source, "/User/test/app1") | ||
expected := "/User/test/app2" | ||
assert.Equal(t, expected, actual) | ||
} | ||
|
||
// TestSolveWithNoSource tests to validate when a absolute path is specified with the -s option | ||
func TestSolveWithAbsolutePath(t *testing.T) { | ||
source := "/User/test/app2" | ||
actual := Solve(source, "/app1") | ||
expected := "/User/test/app2" | ||
assert.Equal(t, expected, actual) | ||
} |