-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for NormalizePath and IsAbs
Signed-off-by: Gabriel Adrian Samfira <[email protected]>
- Loading branch information
1 parent
69f46a5
commit 36b3177
Showing
5 changed files
with
356 additions
and
6 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
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,90 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package system | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNormalizeWorkdir(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
currentWorkdir string | ||
newWorkDir string | ||
desiredResult string | ||
err string | ||
}{ | ||
{ | ||
name: "no current wd with relative wd", | ||
currentWorkdir: "", | ||
newWorkDir: "test", | ||
desiredResult: `/test`, | ||
err: "", | ||
}, | ||
{ | ||
name: "no current wd with absolute wd", | ||
currentWorkdir: "", | ||
newWorkDir: `/strippedWd`, | ||
desiredResult: `/strippedWd`, | ||
err: "", | ||
}, | ||
{ | ||
name: "current wd is absolute, new wd is relative", | ||
currentWorkdir: "/test", | ||
newWorkDir: `subdir`, | ||
desiredResult: `/test/subdir`, | ||
err: "", | ||
}, | ||
{ | ||
name: "current wd is absolute, new wd is relative one folder up", | ||
currentWorkdir: "/test", | ||
newWorkDir: `../subdir`, | ||
desiredResult: `/subdir`, | ||
err: "", | ||
}, | ||
{ | ||
name: "current wd is absolute, new wd is absolute", | ||
currentWorkdir: "/test", | ||
newWorkDir: `/current`, | ||
desiredResult: `/current`, | ||
err: "", | ||
}, | ||
{ | ||
name: "current wd is relative, new wd is relative", | ||
currentWorkdir: "test", | ||
newWorkDir: `current`, | ||
desiredResult: `/test/current`, | ||
err: "", | ||
}, | ||
{ | ||
name: "current wd is relative, no new wd", | ||
currentWorkdir: "test", | ||
newWorkDir: "", | ||
desiredResult: `/test`, | ||
err: "", | ||
}, | ||
{ | ||
name: "current wd is absolute, no new wd", | ||
currentWorkdir: "/test", | ||
newWorkDir: "", | ||
desiredResult: `/test`, | ||
err: "", | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
result, err := NormalizeWorkdir(tc.currentWorkdir, tc.newWorkDir) | ||
if tc.err != "" { | ||
require.EqualError(t, errors.Cause(err), tc.err) | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
require.Equal(t, tc.desiredResult, result) | ||
}) | ||
} | ||
} |
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