MCPcopy
hub / github.com/kubernetes/client-go / TestURLTemplate

Function TestURLTemplate

rest/request_test.go:341–506  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

339}
340
341func TestURLTemplate(t *testing.T) {
342 uri, _ := url.Parse("http://localhost/some/base/url/path")
343 testCases := []struct {
344 Request *Request
345 ExpectedFullURL string
346 ExpectedFinalURL string
347 }{
348 {
349 // non dynamic client
350 Request: NewRequest(nil, "POST", uri, "", ContentConfig{GroupVersion: &schema.GroupVersion{Group: "test"}}, Serializers{}, nil, nil, 0).
351 Prefix("api", "v1").Resource("r1").Namespace("ns").Name("nm").Param("p0", "v0"),
352 ExpectedFullURL: "http://localhost/some/base/url/path/api/v1/namespaces/ns/r1/nm?p0=v0",
353 ExpectedFinalURL: "http://localhost/some/base/url/path/api/v1/namespaces/%7Bnamespace%7D/r1/%7Bname%7D?p0=%7Bvalue%7D",
354 },
355 {
356 // non dynamic client with wrong api group
357 Request: NewRequest(nil, "POST", uri, "", ContentConfig{GroupVersion: &schema.GroupVersion{Group: "test"}}, Serializers{}, nil, nil, 0).
358 Prefix("pre1", "v1").Resource("r1").Namespace("ns").Name("nm").Param("p0", "v0"),
359 ExpectedFullURL: "http://localhost/some/base/url/path/pre1/v1/namespaces/ns/r1/nm?p0=v0",
360 ExpectedFinalURL: "http://localhost/%7Bprefix%7D",
361 },
362 {
363 // dynamic client with core group + namespace + resourceResource (with name)
364 // /api/$RESOURCEVERSION/namespaces/$NAMESPACE/$RESOURCE/%NAME
365 Request: NewRequest(nil, "DELETE", uri, "", ContentConfig{GroupVersion: &schema.GroupVersion{Group: "test"}}, Serializers{}, nil, nil, 0).
366 Prefix("/api/v1/namespaces/ns/r1/name1"),
367 ExpectedFullURL: "http://localhost/some/base/url/path/api/v1/namespaces/ns/r1/name1",
368 ExpectedFinalURL: "http://localhost/some/base/url/path/api/v1/namespaces/%7Bnamespace%7D/r1/%7Bname%7D",
369 },
370 {
371 // dynamic client with named group + namespace + resourceResource (with name)
372 // /apis/$NAMEDGROUPNAME/$RESOURCEVERSION/namespaces/$NAMESPACE/$RESOURCE/%NAME
373 Request: NewRequest(nil, "DELETE", uri, "", ContentConfig{GroupVersion: &schema.GroupVersion{Group: "test"}}, Serializers{}, nil, nil, 0).
374 Prefix("/apis/g1/v1/namespaces/ns/r1/name1"),
375 ExpectedFullURL: "http://localhost/some/base/url/path/apis/g1/v1/namespaces/ns/r1/name1",
376 ExpectedFinalURL: "http://localhost/some/base/url/path/apis/g1/v1/namespaces/%7Bnamespace%7D/r1/%7Bname%7D",
377 },
378 {
379 // dynamic client with core group + namespace + resourceResource (with NO name)
380 // /api/$RESOURCEVERSION/namespaces/$NAMESPACE/$RESOURCE
381 Request: NewRequest(nil, "DELETE", uri, "", ContentConfig{GroupVersion: &schema.GroupVersion{Group: "test"}}, Serializers{}, nil, nil, 0).
382 Prefix("/api/v1/namespaces/ns/r1"),
383 ExpectedFullURL: "http://localhost/some/base/url/path/api/v1/namespaces/ns/r1",
384 ExpectedFinalURL: "http://localhost/some/base/url/path/api/v1/namespaces/%7Bnamespace%7D/r1",
385 },
386 {
387 // dynamic client with named group + namespace + resourceResource (with NO name)
388 // /apis/$NAMEDGROUPNAME/$RESOURCEVERSION/namespaces/$NAMESPACE/$RESOURCE
389 Request: NewRequest(nil, "DELETE", uri, "", ContentConfig{GroupVersion: &schema.GroupVersion{Group: "test"}}, Serializers{}, nil, nil, 0).
390 Prefix("/apis/g1/v1/namespaces/ns/r1"),
391 ExpectedFullURL: "http://localhost/some/base/url/path/apis/g1/v1/namespaces/ns/r1",
392 ExpectedFinalURL: "http://localhost/some/base/url/path/apis/g1/v1/namespaces/%7Bnamespace%7D/r1",
393 },
394 {
395 // dynamic client with core group + resourceResource (with name)
396 // /api/$RESOURCEVERSION/$RESOURCE/%NAME
397 Request: NewRequest(nil, "DELETE", uri, "", ContentConfig{GroupVersion: &schema.GroupVersion{Group: "test"}}, Serializers{}, nil, nil, 0).
398 Prefix("/api/v1/r1/name1"),

Callers

nothing calls this directly

Calls 11

NewRequestFunction · 0.85
ParamMethod · 0.80
PrefixMethod · 0.80
URLMethod · 0.80
finalURLTemplateMethod · 0.80
NamespaceMethod · 0.65
ResourceMethod · 0.65
StringMethod · 0.65
ErrorfMethod · 0.65
ParseMethod · 0.45
NameMethod · 0.45

Tested by

no test coverage detected