@@ -11,11 +11,11 @@ import (
11
11
"testing"
12
12
)
13
13
14
- func TestPathToPrefix ( t * testing. T ) {
15
- tests := [] struct {
16
- Path string
17
- Expected string
18
- }{ {"foo/bar/v1" , "foo/bar/v1" },
14
+ var escapeTests = [] struct {
15
+ Path string
16
+ Escaped string
17
+ }{
18
+ {"foo/bar/v1" , "foo/bar/v1" },
19
19
{"foo/bar/v.1" , "foo/bar/v%2e1" },
20
20
{"f.o.o/b.a.r/v1" , "f.o.o/b.a.r/v1" },
21
21
{"f.o.o/b.a.r/v.1" , "f.o.o/b.a.r/v%2e1" },
@@ -30,9 +30,38 @@ func TestPathToPrefix(t *testing.T) {
30
30
{"%foo%bar" , "%25foo%25bar" },
31
31
{"\x01 \x00 \x7F ☺" , "%01%00%7f%e2%98%ba" },
32
32
}
33
+
34
+ func TestPathToPrefix (t * testing.T ) {
35
+ for _ , tc := range escapeTests {
36
+ if got := PathToPrefix (tc .Path ); got != tc .Escaped {
37
+ t .Errorf ("expected PathToPrefix(%s) = %s, got %s" , tc .Path , tc .Escaped , got )
38
+ }
39
+ }
40
+ }
41
+
42
+ func TestPrefixToPath (t * testing.T ) {
43
+ for _ , tc := range escapeTests {
44
+ got , err := PrefixToPath (tc .Escaped )
45
+ if err != nil {
46
+ t .Errorf ("expected PrefixToPath(%s) err = nil, got %v" , tc .Escaped , err )
47
+ }
48
+ if got != tc .Path {
49
+ t .Errorf ("expected PrefixToPath(%s) = %s, got %s" , tc .Escaped , tc .Path , got )
50
+ }
51
+ }
52
+ }
53
+
54
+ func TestPrefixToPathError (t * testing.T ) {
55
+ tests := []string {
56
+ "foo%" ,
57
+ "foo%1" ,
58
+ "foo%%12" ,
59
+ "foo%1g" ,
60
+ }
33
61
for _ , tc := range tests {
34
- if got := PathToPrefix (tc .Path ); got != tc .Expected {
35
- t .Errorf ("expected PathToPrefix(%s) = %s, got %s" , tc .Path , tc .Expected , got )
62
+ _ , err := PrefixToPath (tc )
63
+ if err == nil {
64
+ t .Errorf ("expected PrefixToPath(%s) err != nil, got nil" , tc )
36
65
}
37
66
}
38
67
}
0 commit comments