Skip to content

Commit

Permalink
Test lack of methods for processedtemplates pseudo-entity
Browse files Browse the repository at this point in the history
Openshift discovery lists both `templates` and `processedtemplates`
for same kind "Template": openshift/origin#21668

`templates` is a regular stored api object.

`processedtemplates` endpoint isn't a stored object,
its POST is a special input (template + params) -> output function.
That functionality is already covered in kubeclient by `process_template`
method.  It doesn't need regular create_, get_, watch_ etc methods.

This is already so because in all openshift versions, `templates` comes
after `processedtemplates` and replaces it in `@entities["template"]`.
  • Loading branch information
cben committed Dec 17, 2018
1 parent e686cc9 commit 6fa7034
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/json/template.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
75 changes: 75 additions & 0 deletions test/json/template.openshift.io_api_resource_list.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
]
}
35 changes: 35 additions & 0 deletions test/json/template_list.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
]
}
36 changes: 36 additions & 0 deletions test/test_process_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6fa7034

Please sign in to comment.