archiver/Globbing_linux_test.go
2024-09-26 11:33:03 +02:00

26 lines
830 B
Go

package archiver
import "testing"
func TestGetGlobRoot(t *testing.T) {
assertThat(t, getGlobRoot("/foo/bar/baz"), "/foo/bar/baz")
assertThat(t, getGlobRoot("/foo/bar/*/baz"), "/foo/bar")
assertThat(t, getGlobRoot("/foo/bar/*"), "/foo/bar")
assertThat(t, getGlobRoot("foo/bar/*"), "foo/bar")
assertThat(t, getGlobRoot("./foo/bar/*"), "./foo/bar")
}
func TestGetGlobbedDir(t *testing.T) {
assertThat(t, extractGlobbedDir("/foo/bar/baz", "/foo/bar/baz/myFile.txt"), "")
assertThat(t, extractGlobbedDir("/foo/bar/*", "/foo/bar/myDir/myFile.txt"), "myDir")
assertThat(t, extractGlobbedDir("/foo/bar/*/baz", "/foo/bar/myDir/baz/myFile.txt"), "myDir/baz")
}
func assertThat[E comparable](t *testing.T, actual E, expected E) {
t.Helper()
if actual != expected {
t.Errorf("actual %v, expected %v", actual, expected)
}
}