| 206 | } |
| 207 | |
| 208 | func TestRESTLayoutURLs(t *testing.T) { |
| 209 | var tests = []struct { |
| 210 | l Layout |
| 211 | h backend.Handle |
| 212 | fn string |
| 213 | dir string |
| 214 | }{ |
| 215 | { |
| 216 | &RESTLayout{url: "https://hostname.foo"}, |
| 217 | backend.Handle{Type: backend.PackFile, Name: "foobar"}, |
| 218 | "https://hostname.foo/data/foobar", |
| 219 | "https://hostname.foo/data/", |
| 220 | }, |
| 221 | { |
| 222 | &RESTLayout{url: "https://hostname.foo:1234/prefix/repo"}, |
| 223 | backend.Handle{Type: backend.LockFile, Name: "foobar"}, |
| 224 | "https://hostname.foo:1234/prefix/repo/locks/foobar", |
| 225 | "https://hostname.foo:1234/prefix/repo/locks/", |
| 226 | }, |
| 227 | { |
| 228 | &RESTLayout{url: "https://hostname.foo:1234/prefix/repo"}, |
| 229 | backend.Handle{Type: backend.ConfigFile, Name: "foobar"}, |
| 230 | "https://hostname.foo:1234/prefix/repo/config", |
| 231 | "https://hostname.foo:1234/prefix/repo/", |
| 232 | }, |
| 233 | } |
| 234 | |
| 235 | for _, test := range tests { |
| 236 | t.Run(fmt.Sprintf("%T", test.l), func(t *testing.T) { |
| 237 | fn := test.l.Filename(test.h) |
| 238 | if fn != test.fn { |
| 239 | t.Fatalf("wrong filename, want %v, got %v", test.fn, fn) |
| 240 | } |
| 241 | |
| 242 | dir := test.l.Dirname(test.h) |
| 243 | if dir != test.dir { |
| 244 | t.Fatalf("wrong dirname, want %v, got %v", test.dir, dir) |
| 245 | } |
| 246 | }) |
| 247 | } |
| 248 | } |