github.com/puellanivis/breton@v0.2.16/lib/files/path_test.go (about) 1 package files 2 3 import ( 4 "context" 5 "net/url" 6 "runtime" 7 "testing" 8 ) 9 10 func TestPathWindows(t *testing.T) { 11 if runtime.GOOS != "windows" { 12 return 13 } 14 15 p := makePath("C:\\") 16 if !isPath(p) { 17 t.Fatalf("makePath returned something not an isPath, got %#v", p) 18 } 19 20 if path := getPath(p); path != "C:\\" { 21 t.Errorf("getPath(makePath) not inverting, got %s", path) 22 } 23 24 ctx := WithRootURL(context.Background(), p) 25 26 filename := makePath("filename") 27 if path := resolveFilename(ctx, filename); getPath(path) != "C:\\filename" { 28 t.Errorf("resolveFilename with %q and %q gave %#v instead", filename, p, path) 29 } 30 } 31 32 func TestPathPOSIX(t *testing.T) { 33 if runtime.GOOS == "windows" { 34 return 35 } 36 37 p := makePath("/asdf") 38 if !isPath(p) { 39 t.Fatalf("makePath returned something not an isPath, got %#v", p) 40 } 41 42 if path := getPath(p); path != "/asdf" { 43 t.Errorf("getPath(makePath) not inverting, got %s", path) 44 } 45 46 ctx := WithRootURL(context.Background(), p) 47 48 filename := makePath("filename") 49 if path := resolveFilename(ctx, filename); getPath(path) != "/asdf/filename" { 50 t.Errorf("resolveFilename with %q and %q gave %#v instead", filename, p, path) 51 } 52 } 53 54 func TestPathURL(t *testing.T) { 55 p, err := url.Parse("scheme://username:password@hostname:12345/path/?query#fragment") 56 if err != nil { 57 t.Fatal(err) 58 } 59 60 if isPath(p) { 61 t.Fatalf("url.Parse with scheme returned something that is an isPath, got %#v", p) 62 } 63 64 ctx := WithRootURL(context.Background(), p) 65 66 filename := makePath("filename") 67 if path := resolveFilename(ctx, filename); path.String() != "scheme://username:password@hostname:12345/path/filename" { 68 t.Errorf("resolveFilename with %q and %q gave %#v instead", filename, p, path) 69 } 70 71 p, err = url.Parse("file:///c:/Windows/") 72 if err != nil { 73 t.Fatal(err) 74 } 75 76 if isPath(p) { 77 t.Fatalf("url.Parse with scheme returned something that is an isPath, got %#v", p) 78 } 79 80 ctx = WithRootURL(context.Background(), p) 81 82 if path := resolveFilename(ctx, filename); path.String() != "file:///c:/Windows/filename" { 83 t.Errorf("resolveFilename with %q and %q gave %#v instead", filename, p, path) 84 } 85 }