-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fork opencontainers/runtime-tools to allow us more control
We are the only tools that are using runtime-tools, rather then having to go through the vendoring process, I want to move this under containers/common. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
- Loading branch information
Showing
39 changed files
with
1,886 additions
and
555 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
File renamed without changes.
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,237 @@ | ||
package filepath | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"runtime" | ||
"testing" | ||
) | ||
|
||
func TestAbs(t *testing.T) { | ||
for _, test := range []struct { | ||
os string | ||
path string | ||
cwd string | ||
expected string | ||
}{ | ||
{ | ||
os: "linux", | ||
path: "/", | ||
cwd: "/cwd", | ||
expected: "/", | ||
}, | ||
{ | ||
os: "linux", | ||
path: "/a", | ||
cwd: "/cwd", | ||
expected: "/a", | ||
}, | ||
{ | ||
os: "linux", | ||
path: "/a/", | ||
cwd: "/cwd", | ||
expected: "/a", | ||
}, | ||
{ | ||
os: "linux", | ||
path: "//a", | ||
cwd: "/cwd", | ||
expected: "/a", | ||
}, | ||
{ | ||
os: "linux", | ||
path: ".", | ||
cwd: "/cwd", | ||
expected: "/cwd", | ||
}, | ||
{ | ||
os: "linux", | ||
path: "./c", | ||
cwd: "/a/b", | ||
expected: "/a/b/c", | ||
}, | ||
{ | ||
os: "linux", | ||
path: ".//c", | ||
cwd: "/a/b", | ||
expected: "/a/b/c", | ||
}, | ||
{ | ||
os: "linux", | ||
path: "../a", | ||
cwd: "/cwd", | ||
expected: "/a", | ||
}, | ||
{ | ||
os: "linux", | ||
path: "../../b", | ||
cwd: "/cwd", | ||
expected: "/b", | ||
}, | ||
{ | ||
os: "windows", | ||
path: "c:\\", | ||
cwd: "/cwd", | ||
expected: "c:\\", | ||
}, | ||
{ | ||
os: "windows", | ||
path: "c:\\a", | ||
cwd: "c:\\cwd", | ||
expected: "c:\\a", | ||
}, | ||
{ | ||
os: "windows", | ||
path: "c:\\a\\", | ||
cwd: "c:\\cwd", | ||
expected: "c:\\a", | ||
}, | ||
{ | ||
os: "windows", | ||
path: "c:\\\\a", | ||
cwd: "c:\\cwd", | ||
expected: "c:\\a", | ||
}, | ||
{ | ||
os: "windows", | ||
path: ".", | ||
cwd: "c:\\cwd", | ||
expected: "c:\\cwd", | ||
}, | ||
{ | ||
os: "windows", | ||
path: ".\\c", | ||
cwd: "c:\\a\\b", | ||
expected: "c:\\a\\b\\c", | ||
}, | ||
{ | ||
os: "windows", | ||
path: ".\\\\c", | ||
cwd: "c:\\a\\b", | ||
expected: "c:\\a\\b\\c", | ||
}, | ||
{ | ||
os: "windows", | ||
path: "..\\a", | ||
cwd: "c:\\cwd", | ||
expected: "c:\\a", | ||
}, | ||
{ | ||
os: "windows", | ||
path: "..\\..\\b", | ||
cwd: "c:\\cwd", | ||
expected: "c:\\b", | ||
}, | ||
} { | ||
t.Run( | ||
fmt.Sprintf("Abs(%q,%q,%q)", test.os, test.path, test.cwd), | ||
func(t *testing.T) { | ||
os := test.os //nolint | ||
path := test.path //nolint | ||
cwd := test.cwd //nolint | ||
expected := test.expected //nolint | ||
abs, err := Abs(os, path, cwd) | ||
if err != nil { | ||
t.Error(err) | ||
} else if abs != expected { | ||
t.Errorf("unexpected result: %q (expected %q)", abs, expected) | ||
} | ||
}, | ||
) | ||
} | ||
} | ||
|
||
func TestIsAbs(t *testing.T) { | ||
for _, test := range []struct { | ||
os string | ||
path string | ||
expected bool | ||
}{ | ||
{ | ||
os: "linux", | ||
path: "/", | ||
expected: true, | ||
}, | ||
{ | ||
os: "linux", | ||
path: "/a", | ||
expected: true, | ||
}, | ||
{ | ||
os: "linux", | ||
path: "//", | ||
expected: true, | ||
}, | ||
{ | ||
os: "linux", | ||
path: "//a", | ||
expected: true, | ||
}, | ||
{ | ||
os: "linux", | ||
path: ".", | ||
expected: false, | ||
}, | ||
{ | ||
os: "linux", | ||
path: "./a", | ||
expected: false, | ||
}, | ||
{ | ||
os: "linux", | ||
path: ".//a", | ||
expected: false, | ||
}, | ||
{ | ||
os: "linux", | ||
path: "../a", | ||
expected: false, | ||
}, | ||
{ | ||
os: "linux", | ||
path: "../../a", | ||
expected: false, | ||
}, | ||
{ | ||
os: "windows", | ||
path: "c:\\", | ||
expected: true, | ||
}, | ||
{ | ||
os: "windows", | ||
path: "c:\\a", | ||
expected: true, | ||
}, | ||
{ | ||
os: "windows", | ||
path: ".", | ||
expected: false, | ||
}, | ||
{ | ||
os: "windows", | ||
path: ".\\a", | ||
expected: false, | ||
}, | ||
{ | ||
os: "windows", | ||
path: "..\\a", | ||
expected: false, | ||
}, | ||
} { | ||
t.Run( | ||
fmt.Sprintf("IsAbs(%q,%q)", test.os, test.path), | ||
func(t *testing.T) { | ||
abs := IsAbs(test.os, test.path) //nolint | ||
if abs != test.expected { //nolint | ||
t.Errorf("unexpected result: %t (expected %t)", abs, test.expected) //nolint | ||
} | ||
if runtime.GOOS == test.os { //nolint | ||
stdAbs := filepath.IsAbs(test.path) //nolint | ||
if abs != stdAbs { | ||
t.Errorf("non-standard result: %t (%t is standard)", abs, stdAbs) | ||
} | ||
} | ||
}, | ||
) | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.