diff --git a/test/json/template.json b/test/json/template.json new file mode 100644 index 00000000..85d8bad7 --- /dev/null +++ b/test/json/template.json @@ -0,0 +1,27 @@ +{ + "apiVersion": "template.openshift.io/v1", + "kind": "Template", + "metadata": { + "creationTimestamp": "2018-12-17T16:11:36Z", + "name": "my-template", + "namespace": "default", + "resourceVersion": "21954", + "selfLink": "/apis/template.openshift.io/v1/namespaces/default/templates/my-template", + "uid": "6e03e3e6-0216-11e9-b1e0-68f728fac3ab" + }, + "objects": [ + { + "apiVersion": "v1", + "kind": "Service", + "metadata": { + "name": "${NAME_PREFIX}my-service" + } + } + ], + "parameters": [ + { + "description": "Prefix for names", + "name": "NAME_PREFIX" + } + ] +} diff --git a/test/json/template.openshift.io_api_resource_list.json b/test/json/template.openshift.io_api_resource_list.json new file mode 100644 index 00000000..1ba147f7 --- /dev/null +++ b/test/json/template.openshift.io_api_resource_list.json @@ -0,0 +1,75 @@ +{ + "kind": "APIResourceList", + "apiVersion": "v1", + "groupVersion": "template.openshift.io/v1", + "resources": [ + { + "name": "brokertemplateinstances", + "singularName": "", + "namespaced": false, + "kind": "BrokerTemplateInstance", + "verbs": [ + "create", + "delete", + "deletecollection", + "get", + "list", + "patch", + "update", + "watch" + ] + }, + { + "name": "processedtemplates", + "singularName": "", + "namespaced": true, + "kind": "Template", + "verbs": [ + "create" + ] + }, + { + "name": "templateinstances", + "singularName": "", + "namespaced": true, + "kind": "TemplateInstance", + "verbs": [ + "create", + "delete", + "deletecollection", + "get", + "list", + "patch", + "update", + "watch" + ] + }, + { + "name": "templateinstances/status", + "singularName": "", + "namespaced": true, + "kind": "TemplateInstance", + "verbs": [ + "get", + "patch", + "update" + ] + }, + { + "name": "templates", + "singularName": "", + "namespaced": true, + "kind": "Template", + "verbs": [ + "create", + "delete", + "deletecollection", + "get", + "list", + "patch", + "update", + "watch" + ] + } + ] +} \ No newline at end of file diff --git a/test/json/template_list.json b/test/json/template_list.json new file mode 100644 index 00000000..a0f84ad3 --- /dev/null +++ b/test/json/template_list.json @@ -0,0 +1,35 @@ +{ + "kind": "TemplateList", + "apiVersion": "template.openshift.io/v1", + "metadata": { + "selfLink": "/apis/template.openshift.io/v1/namespaces/default/templates", + "resourceVersion": "22758" + }, + "items": [ + { + "metadata": { + "name": "my-template", + "namespace": "default", + "selfLink": "/apis/template.openshift.io/v1/namespaces/default/templates/my-template", + "uid": "6e03e3e6-0216-11e9-b1e0-68f728fac3ab", + "resourceVersion": "21954", + "creationTimestamp": "2018-12-17T16:11:36Z" + }, + "objects": [ + { + "apiVersion": "v1", + "kind": "Service", + "metadata": { + "name": "${NAME_PREFIX}my-service" + } + } + ], + "parameters": [ + { + "name": "NAME_PREFIX", + "description": "Prefix for names" + } + ] + } + ] +} diff --git a/test/test_process_template.rb b/test/test_process_template.rb index a22bf975..e3b4670f 100644 --- a/test/test_process_template.rb +++ b/test/test_process_template.rb @@ -41,4 +41,40 @@ def test_process_template data['metadata']['namespace'] == 'default' end end + + # Ensure _template and _templates methods hit `/templates` rather than + # `/processedtemplates` URL. + def test_templates_methods + stub_request(:get, %r{/apis/template\.openshift\.io/v1$}).to_return( + body: open_test_file('template.openshift.io_api_resource_list.json'), + status: 200 + ) + client = Kubeclient::Client.new('http://localhost:8080/apis/template.openshift.io', 'v1') + + expected_url = 'http://localhost:8080/apis/template.openshift.io/v1/namespaces/default/templates' + stub_request(:get, expected_url) + .to_return(body: open_test_file('template_list.json'), status: 200) + client.get_templates(namespace: 'default') + assert_requested(:get, expected_url, times: 1) + + expected_url = 'http://localhost:8080/apis/template.openshift.io/v1/namespaces/default/templates/my-template' + stub_request(:get, expected_url) + .to_return(body: open_test_file('template.json'), status: 200) + client.get_template('my-template', 'default') + assert_requested(:get, expected_url, times: 1) + end + + def test_no_processedtemplates_methods + stub_request(:get, %r{/apis/template\.openshift\.io/v1$}).to_return( + body: open_test_file('template.openshift.io_api_resource_list.json'), + status: 200 + ) + client = Kubeclient::Client.new('http://localhost:8080/apis/template.openshift.io', 'v1') + client.discover + + refute_respond_to(client, :get_processedtemplates) + refute_respond_to(client, :get_processedtemplate) + refute_respond_to(client, :get_processed_templates) + refute_respond_to(client, :get_processed_template) + end end