ruboty-k8s 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kubeclient/.gitignore +15 -0
- data/lib/kubeclient/.rubocop.yml +16 -0
- data/lib/kubeclient/.travis.yml +12 -0
- data/lib/kubeclient/Gemfile +4 -0
- data/lib/kubeclient/LICENSE.txt +22 -0
- data/lib/kubeclient/README.md +428 -0
- data/lib/kubeclient/Rakefile +12 -0
- data/lib/kubeclient/kubeclient.gemspec +31 -0
- data/lib/kubeclient/lib/kubeclient/common.rb +512 -0
- data/lib/kubeclient/lib/kubeclient/config.rb +126 -0
- data/lib/kubeclient/lib/kubeclient/entity_list.rb +16 -0
- data/lib/kubeclient/lib/kubeclient/kube_exception.rb +14 -0
- data/lib/kubeclient/lib/kubeclient/missing_kind_compatibility.rb +68 -0
- data/lib/kubeclient/lib/kubeclient/version.rb +4 -0
- data/lib/kubeclient/lib/kubeclient/watch_notice.rb +7 -0
- data/lib/kubeclient/lib/kubeclient/watch_stream.rb +80 -0
- data/lib/kubeclient/lib/kubeclient.rb +32 -0
- data/lib/kubeclient/test/cassettes/kubernetes_guestbook.yml +879 -0
- data/lib/kubeclient/test/config/allinone.kubeconfig +20 -0
- data/lib/kubeclient/test/config/external-ca.pem +18 -0
- data/lib/kubeclient/test/config/external-cert.pem +19 -0
- data/lib/kubeclient/test/config/external-key.rsa +27 -0
- data/lib/kubeclient/test/config/external.kubeconfig +20 -0
- data/lib/kubeclient/test/config/nouser.kubeconfig +16 -0
- data/lib/kubeclient/test/config/userauth.kubeconfig +28 -0
- data/lib/kubeclient/test/json/bindings_list.json +10 -0
- data/lib/kubeclient/test/json/component_status.json +17 -0
- data/lib/kubeclient/test/json/component_status_list.json +52 -0
- data/lib/kubeclient/test/json/config_map_list.json +9 -0
- data/lib/kubeclient/test/json/core_api_resource_list.json +181 -0
- data/lib/kubeclient/test/json/core_api_resource_list_without_kind.json +129 -0
- data/lib/kubeclient/test/json/core_oapi_resource_list_without_kind.json +197 -0
- data/lib/kubeclient/test/json/created_endpoint.json +28 -0
- data/lib/kubeclient/test/json/created_namespace.json +20 -0
- data/lib/kubeclient/test/json/created_secret.json +16 -0
- data/lib/kubeclient/test/json/created_service.json +31 -0
- data/lib/kubeclient/test/json/empty_pod_list.json +9 -0
- data/lib/kubeclient/test/json/endpoint_list.json +48 -0
- data/lib/kubeclient/test/json/entity_list.json +56 -0
- data/lib/kubeclient/test/json/event_list.json +35 -0
- data/lib/kubeclient/test/json/limit_range.json +23 -0
- data/lib/kubeclient/test/json/limit_range_list.json +31 -0
- data/lib/kubeclient/test/json/namespace.json +13 -0
- data/lib/kubeclient/test/json/namespace_exception.json +8 -0
- data/lib/kubeclient/test/json/namespace_list.json +32 -0
- data/lib/kubeclient/test/json/node.json +29 -0
- data/lib/kubeclient/test/json/node_list.json +37 -0
- data/lib/kubeclient/test/json/persistent_volume.json +37 -0
- data/lib/kubeclient/test/json/persistent_volume_claim.json +32 -0
- data/lib/kubeclient/test/json/persistent_volume_claim_list.json +40 -0
- data/lib/kubeclient/test/json/persistent_volume_claims_nil_items.json +8 -0
- data/lib/kubeclient/test/json/persistent_volume_list.json +45 -0
- data/lib/kubeclient/test/json/pod.json +92 -0
- data/lib/kubeclient/test/json/pod_list.json +79 -0
- data/lib/kubeclient/test/json/pod_template_list.json +9 -0
- data/lib/kubeclient/test/json/processed_template.json +27 -0
- data/lib/kubeclient/test/json/replication_controller.json +57 -0
- data/lib/kubeclient/test/json/replication_controller_list.json +66 -0
- data/lib/kubeclient/test/json/resource_quota.json +46 -0
- data/lib/kubeclient/test/json/resource_quota_list.json +54 -0
- data/lib/kubeclient/test/json/secret_list.json +44 -0
- data/lib/kubeclient/test/json/service.json +33 -0
- data/lib/kubeclient/test/json/service_account.json +25 -0
- data/lib/kubeclient/test/json/service_account_list.json +82 -0
- data/lib/kubeclient/test/json/service_illegal_json_404.json +1 -0
- data/lib/kubeclient/test/json/service_list.json +97 -0
- data/lib/kubeclient/test/json/service_patch.json +25 -0
- data/lib/kubeclient/test/json/service_update.json +22 -0
- data/lib/kubeclient/test/json/versions_list.json +6 -0
- data/lib/kubeclient/test/json/watch_stream.json +3 -0
- data/lib/kubeclient/test/test_common.rb +32 -0
- data/lib/kubeclient/test/test_component_status.rb +30 -0
- data/lib/kubeclient/test/test_config.rb +72 -0
- data/lib/kubeclient/test/test_endpoint.rb +35 -0
- data/lib/kubeclient/test/test_guestbook_go.rb +238 -0
- data/lib/kubeclient/test/test_helper.rb +10 -0
- data/lib/kubeclient/test/test_kubeclient.rb +611 -0
- data/lib/kubeclient/test/test_limit_range.rb +27 -0
- data/lib/kubeclient/test/test_missing_methods.rb +42 -0
- data/lib/kubeclient/test/test_namespace.rb +61 -0
- data/lib/kubeclient/test/test_node.rb +33 -0
- data/lib/kubeclient/test/test_persistent_volume.rb +30 -0
- data/lib/kubeclient/test/test_persistent_volume_claim.rb +30 -0
- data/lib/kubeclient/test/test_pod.rb +29 -0
- data/lib/kubeclient/test/test_pod_log.rb +50 -0
- data/lib/kubeclient/test/test_process_template.rb +44 -0
- data/lib/kubeclient/test/test_replication_controller.rb +27 -0
- data/lib/kubeclient/test/test_resource_list_without_kind.rb +78 -0
- data/lib/kubeclient/test/test_resource_quota.rb +25 -0
- data/lib/kubeclient/test/test_secret.rb +70 -0
- data/lib/kubeclient/test/test_service.rb +293 -0
- data/lib/kubeclient/test/test_service_account.rb +28 -0
- data/lib/kubeclient/test/test_watch.rb +119 -0
- data/lib/kubeclient/test/txt/pod_log.txt +6 -0
- data/lib/kubeclient/test/valid_token_file +1 -0
- data/lib/ruboty/k8s/version.rb +1 -1
- metadata +96 -1
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# Namespace entity tests
|
4
|
+
class TestNamespace < MiniTest::Test
|
5
|
+
def test_get_namespace_v1
|
6
|
+
stub_request(:get, %r{/api/v1$})
|
7
|
+
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200)
|
8
|
+
stub_request(:get, %r{/namespaces})
|
9
|
+
.to_return(body: open_test_file('namespace.json'), status: 200)
|
10
|
+
|
11
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
12
|
+
namespace = client.get_namespace 'staging'
|
13
|
+
|
14
|
+
assert_instance_of(Kubeclient::Namespace, namespace)
|
15
|
+
assert_equal('e388bc10-c021-11e4-a514-3c970e4a436a', namespace.metadata.uid)
|
16
|
+
assert_equal('staging', namespace.metadata.name)
|
17
|
+
assert_equal('1168', namespace.metadata.resourceVersion)
|
18
|
+
assert_equal('v1', namespace.apiVersion)
|
19
|
+
|
20
|
+
assert_requested(
|
21
|
+
:get,
|
22
|
+
'http://localhost:8080/api/v1/namespaces/staging',
|
23
|
+
times: 1
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_delete_namespace_v1
|
28
|
+
our_namespace = Kubeclient::Resource.new
|
29
|
+
our_namespace.metadata = {}
|
30
|
+
our_namespace.metadata.name = 'staging'
|
31
|
+
|
32
|
+
stub_request(:get, %r{/api/v1$})
|
33
|
+
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200)
|
34
|
+
stub_request(:delete, %r{/namespaces})
|
35
|
+
.to_return(status: 200)
|
36
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
37
|
+
client.delete_namespace our_namespace.metadata.name
|
38
|
+
|
39
|
+
assert_requested(
|
40
|
+
:delete,
|
41
|
+
'http://localhost:8080/api/v1/namespaces/staging',
|
42
|
+
times: 1
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_create_namespace
|
47
|
+
stub_request(:get, %r{/api/v1$})
|
48
|
+
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200)
|
49
|
+
stub_request(:post, %r{/namespaces})
|
50
|
+
.to_return(body: open_test_file('created_namespace.json'), status: 201)
|
51
|
+
|
52
|
+
namespace = Kubeclient::Resource.new
|
53
|
+
namespace.metadata = {}
|
54
|
+
namespace.metadata.name = 'development'
|
55
|
+
|
56
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/'
|
57
|
+
created_namespace = client.create_namespace namespace
|
58
|
+
assert_instance_of(Kubeclient::Namespace, created_namespace)
|
59
|
+
assert_equal(namespace.metadata.name, created_namespace.metadata.name)
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# Node entity tests
|
4
|
+
class TestNode < MiniTest::Test
|
5
|
+
def test_get_from_json_v1
|
6
|
+
stub_request(:get, %r{/nodes})
|
7
|
+
.to_return(body: open_test_file('node.json'), status: 200)
|
8
|
+
stub_request(:get, %r{/api/v1$})
|
9
|
+
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200)
|
10
|
+
|
11
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
12
|
+
node = client.get_node('127.0.0.1')
|
13
|
+
|
14
|
+
assert_instance_of(Kubeclient::Node, node)
|
15
|
+
|
16
|
+
assert_equal('041143c5-ce39-11e4-ac24-3c970e4a436a', node.metadata.uid)
|
17
|
+
assert_equal('127.0.0.1', node.metadata.name)
|
18
|
+
assert_equal('1724', node.metadata.resourceVersion)
|
19
|
+
assert_equal('v1', node.apiVersion)
|
20
|
+
assert_equal('2015-03-19T15:08:20+02:00', node.metadata.creationTimestamp)
|
21
|
+
|
22
|
+
assert_requested(
|
23
|
+
:get,
|
24
|
+
'http://localhost:8080/api/v1',
|
25
|
+
times: 1
|
26
|
+
)
|
27
|
+
assert_requested(
|
28
|
+
:get,
|
29
|
+
'http://localhost:8080/api/v1/nodes/127.0.0.1',
|
30
|
+
times: 1
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# PersistentVolume tests
|
4
|
+
class TestPersistentVolume < MiniTest::Test
|
5
|
+
def test_get_from_json_v1
|
6
|
+
stub_request(:get, %r{/persistentvolumes})
|
7
|
+
.to_return(body: open_test_file('persistent_volume.json'), status: 200)
|
8
|
+
stub_request(:get, %r{/api/v1$})
|
9
|
+
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200)
|
10
|
+
|
11
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
12
|
+
volume = client.get_persistent_volume 'pv0001'
|
13
|
+
|
14
|
+
assert_instance_of(Kubeclient::PersistentVolume, volume)
|
15
|
+
assert_equal('pv0001', volume.metadata.name)
|
16
|
+
assert_equal('10Gi', volume.spec.capacity.storage)
|
17
|
+
assert_equal('/tmp/data01', volume.spec.hostPath.path)
|
18
|
+
|
19
|
+
assert_requested(
|
20
|
+
:get,
|
21
|
+
'http://localhost:8080/api/v1',
|
22
|
+
times: 1
|
23
|
+
)
|
24
|
+
assert_requested(
|
25
|
+
:get,
|
26
|
+
'http://localhost:8080/api/v1/persistentvolumes/pv0001',
|
27
|
+
times: 1
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# PersistentVolumeClaim tests
|
4
|
+
class TestPersistentVolumeClaim < MiniTest::Test
|
5
|
+
def test_get_from_json_v1
|
6
|
+
stub_request(:get, %r{/persistentvolumeclaims})
|
7
|
+
.to_return(body: open_test_file('persistent_volume_claim.json'), status: 200)
|
8
|
+
stub_request(:get, %r{/api/v1$})
|
9
|
+
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200)
|
10
|
+
|
11
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
12
|
+
claim = client.get_persistent_volume_claim 'myclaim-1', 'default'
|
13
|
+
|
14
|
+
assert_instance_of(Kubeclient::PersistentVolumeClaim, claim)
|
15
|
+
assert_equal('myclaim-1', claim.metadata.name)
|
16
|
+
assert_equal('3Gi', claim.spec.resources.requests.storage)
|
17
|
+
assert_equal('pv0001', claim.spec.volumeName)
|
18
|
+
|
19
|
+
assert_requested(
|
20
|
+
:get,
|
21
|
+
'http://localhost:8080/api/v1',
|
22
|
+
times: 1
|
23
|
+
)
|
24
|
+
assert_requested(
|
25
|
+
:get,
|
26
|
+
'http://localhost:8080/api/v1/namespaces/default/persistentvolumeclaims/myclaim-1',
|
27
|
+
times: 1
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# Pod entity tests
|
4
|
+
class TestPod < MiniTest::Test
|
5
|
+
def test_get_from_json_v1
|
6
|
+
stub_request(:get, %r{/pods})
|
7
|
+
.to_return(body: open_test_file('pod.json'), status: 200)
|
8
|
+
stub_request(:get, %r{/api/v1$})
|
9
|
+
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200)
|
10
|
+
|
11
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
12
|
+
pod = client.get_pod 'redis-master-pod', 'default'
|
13
|
+
|
14
|
+
assert_instance_of(Kubeclient::Pod, pod)
|
15
|
+
assert_equal('redis-master3', pod.metadata.name)
|
16
|
+
assert_equal('dockerfile/redis', pod.spec.containers[0]['image'])
|
17
|
+
|
18
|
+
assert_requested(
|
19
|
+
:get,
|
20
|
+
'http://localhost:8080/api/v1',
|
21
|
+
times: 1
|
22
|
+
)
|
23
|
+
assert_requested(
|
24
|
+
:get,
|
25
|
+
'http://localhost:8080/api/v1/namespaces/default/pods/redis-master-pod',
|
26
|
+
times: 1
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# Pod log tests
|
4
|
+
class TestPodLog < MiniTest::Test
|
5
|
+
def test_get_pod_log
|
6
|
+
stub_request(:get, %r{/namespaces/default/pods/[a-z0-9-]+/log})
|
7
|
+
.to_return(body: open_test_file('pod_log.txt'),
|
8
|
+
status: 200)
|
9
|
+
|
10
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
11
|
+
retrieved_log = client.get_pod_log('redis-master-pod', 'default')
|
12
|
+
|
13
|
+
assert_equal(open_test_file('pod_log.txt').read, retrieved_log)
|
14
|
+
|
15
|
+
assert_requested(:get,
|
16
|
+
'http://localhost:8080/api/v1/namespaces/default/pods/redis-master-pod/log',
|
17
|
+
times: 1)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_get_pod_log_container
|
21
|
+
stub_request(:get, %r{/namespaces/default/pods/[a-z0-9-]+/log})
|
22
|
+
.to_return(body: open_test_file('pod_log.txt'),
|
23
|
+
status: 200)
|
24
|
+
|
25
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
26
|
+
retrieved_log = client.get_pod_log('redis-master-pod', 'default', container: 'ruby')
|
27
|
+
|
28
|
+
assert_equal(open_test_file('pod_log.txt').read, retrieved_log)
|
29
|
+
|
30
|
+
assert_requested(:get,
|
31
|
+
'http://localhost:8080/api/v1/namespaces/default/pods/redis-master-pod/log?container=ruby',
|
32
|
+
times: 1)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_watch_pod_log
|
36
|
+
expected_lines = open_test_file('pod_log.txt').read.split("\n")
|
37
|
+
|
38
|
+
stub_request(:get, %r{/namespaces/default/pods/[a-z0-9-]+/log\?.*follow})
|
39
|
+
.to_return(body: open_test_file('pod_log.txt'),
|
40
|
+
status: 200)
|
41
|
+
|
42
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
43
|
+
|
44
|
+
stream = client.watch_pod_log('redis-master-pod', 'default')
|
45
|
+
stream.to_enum.with_index do |notice, index|
|
46
|
+
assert_instance_of(String, notice)
|
47
|
+
assert_equal(expected_lines[index], notice)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# Process Template tests
|
4
|
+
class TestProcessTemplate < MiniTest::Test
|
5
|
+
def test_process_template
|
6
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
7
|
+
template = {}
|
8
|
+
template[:metadata] = {}
|
9
|
+
template[:metadata][:name] = 'my-template'
|
10
|
+
template[:metadata][:namespace] = 'default'
|
11
|
+
template[:kind] = 'Template'
|
12
|
+
template[:apiVersion] = 'v1'
|
13
|
+
service = {}
|
14
|
+
service[:metadata] = {}
|
15
|
+
service[:metadata][:name] = '${NAME_PREFIX}my-service'
|
16
|
+
service[:kind] = 'Service'
|
17
|
+
service[:apiVersion] = 'v1'
|
18
|
+
template[:objects] = [service]
|
19
|
+
param = { name: 'NAME_PREFIX', value: 'test/' }
|
20
|
+
template[:parameters] = [param]
|
21
|
+
|
22
|
+
req_body = '{"metadata":{"name":"my-template","namespace":"default"},' \
|
23
|
+
'"kind":"Template","apiVersion":"v1","objects":[{"metadata":' \
|
24
|
+
'{"name":"${NAME_PREFIX}my-service"},"kind":"Service","apiVersion":"v1"}],' \
|
25
|
+
'"parameters":[{"name":"NAME_PREFIX","value":"test/"}]}'
|
26
|
+
|
27
|
+
expected_url = 'http://localhost:8080/api/v1/namespaces/default/processedtemplates'
|
28
|
+
stub_request(:post, expected_url)
|
29
|
+
.with(body: req_body, headers: { 'Content-Type' => 'application/json' })
|
30
|
+
.to_return(body: open_test_file('processed_template.json'), status: 200)
|
31
|
+
|
32
|
+
processed_template = client.process_template template
|
33
|
+
|
34
|
+
assert_equal('test/my-service', processed_template['objects'].first['metadata']['name'])
|
35
|
+
|
36
|
+
assert_requested(:post, expected_url, times: 1) do |req|
|
37
|
+
data = JSON.parse(req.body)
|
38
|
+
data['kind'] == 'Template' &&
|
39
|
+
data['apiVersion'] == 'v1' &&
|
40
|
+
data['metadata']['name'] == 'my-template' &&
|
41
|
+
data['metadata']['namespace'] == 'default'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# Replication Controller entity tests
|
4
|
+
class TestReplicationController < MiniTest::Test
|
5
|
+
def test_get_from_json_v1
|
6
|
+
stub_request(:get, %r{/api/v1$})
|
7
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
8
|
+
status: 200)
|
9
|
+
stub_request(:get, %r{/replicationcontrollers})
|
10
|
+
.to_return(body: open_test_file('replication_controller.json'),
|
11
|
+
status: 200)
|
12
|
+
|
13
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
14
|
+
rc = client.get_replication_controller 'frontendController', 'default'
|
15
|
+
|
16
|
+
assert_instance_of(Kubeclient::ReplicationController, rc)
|
17
|
+
assert_equal('guestbook-controller', rc.metadata.name)
|
18
|
+
assert_equal('c71aa4c0-a240-11e4-a265-3c970e4a436a', rc.metadata.uid)
|
19
|
+
assert_equal('default', rc.metadata.namespace)
|
20
|
+
assert_equal(3, rc.spec.replicas)
|
21
|
+
assert_equal('guestbook', rc.spec.selector.name)
|
22
|
+
|
23
|
+
assert_requested(:get,
|
24
|
+
'http://localhost:8080/api/v1/namespaces/default/replicationcontrollers/frontendController',
|
25
|
+
times: 1)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# Core api resource list without kind tests
|
4
|
+
class TestResourceListWithoutKind < MiniTest::Test
|
5
|
+
def test_get_from_json_api_v1
|
6
|
+
stub_request(:get, %r{/api/v1$})
|
7
|
+
.to_return(body: open_test_file('core_api_resource_list_without_kind.json'),
|
8
|
+
status: 200)
|
9
|
+
|
10
|
+
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
11
|
+
client.discover
|
12
|
+
|
13
|
+
[
|
14
|
+
{
|
15
|
+
entity: 'pod',
|
16
|
+
type: 'Pod',
|
17
|
+
name: 'pods',
|
18
|
+
methods: %w(pod pods)
|
19
|
+
},
|
20
|
+
{
|
21
|
+
entity: 'node',
|
22
|
+
type: 'Node',
|
23
|
+
name: 'nodes',
|
24
|
+
methods: %w(node nodes)
|
25
|
+
},
|
26
|
+
{
|
27
|
+
entity: 'service',
|
28
|
+
type: 'Service',
|
29
|
+
name: 'services',
|
30
|
+
methods: %w(service services)
|
31
|
+
}
|
32
|
+
].each { |h| assert_entities(client.instance_variable_get(:@entities)[h[:entity]], h) }
|
33
|
+
|
34
|
+
assert_requested(:get,
|
35
|
+
'http://localhost:8080/api/v1',
|
36
|
+
times: 1)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_get_from_json_oapi_v1
|
40
|
+
stub_request(:get, %r{/oapi/v1$})
|
41
|
+
.to_return(body: open_test_file('core_oapi_resource_list_without_kind.json'),
|
42
|
+
status: 200)
|
43
|
+
|
44
|
+
client = Kubeclient::Client.new('http://localhost:8080/oapi/', 'v1')
|
45
|
+
client.discover
|
46
|
+
|
47
|
+
[
|
48
|
+
{
|
49
|
+
entity: 'template',
|
50
|
+
type: 'Template',
|
51
|
+
name: 'templates',
|
52
|
+
methods: %w(template templates)
|
53
|
+
},
|
54
|
+
{
|
55
|
+
entity: 'build',
|
56
|
+
type: 'Build',
|
57
|
+
name: 'builds',
|
58
|
+
methods: %w(build builds)
|
59
|
+
},
|
60
|
+
{
|
61
|
+
entity: 'project',
|
62
|
+
type: 'Project',
|
63
|
+
name: 'projects',
|
64
|
+
methods: %w(project projects)
|
65
|
+
}
|
66
|
+
].each { |h| assert_entities(client.instance_variable_get(:@entities)[h[:entity]], h) }
|
67
|
+
|
68
|
+
assert_requested(:get,
|
69
|
+
'http://localhost:8080/oapi/v1',
|
70
|
+
times: 1)
|
71
|
+
end
|
72
|
+
|
73
|
+
def assert_entities(entity, h)
|
74
|
+
assert_equal(entity.entity_type, h[:type])
|
75
|
+
assert_equal(entity.resource_name, h[:name])
|
76
|
+
assert_equal(entity.method_names, h[:methods])
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# ResourceQuota tests
|
4
|
+
class TestResourceQuota < MiniTest::Test
|
5
|
+
def test_get_from_json_v1
|
6
|
+
stub_request(:get, %r{/api/v1$})
|
7
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
8
|
+
status: 200)
|
9
|
+
stub_request(:get, %r{/resourcequotas})
|
10
|
+
.to_return(body: open_test_file('resource_quota.json'),
|
11
|
+
status: 200)
|
12
|
+
|
13
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
14
|
+
quota = client.get_resource_quota 'quota', 'quota-example'
|
15
|
+
|
16
|
+
assert_instance_of(Kubeclient::ResourceQuota, quota)
|
17
|
+
assert_equal('quota', quota.metadata.name)
|
18
|
+
assert_equal('20', quota.spec.hard.cpu)
|
19
|
+
assert_equal('10', quota.spec.hard.secrets)
|
20
|
+
|
21
|
+
assert_requested(:get,
|
22
|
+
'http://localhost:8080/api/v1/namespaces/quota-example/resourcequotas/quota',
|
23
|
+
times: 1)
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# Namespace entity tests
|
4
|
+
class TestSecret < MiniTest::Test
|
5
|
+
def test_get_secret_v1
|
6
|
+
stub_request(:get, %r{/api/v1$})
|
7
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
8
|
+
status: 200)
|
9
|
+
|
10
|
+
stub_request(:get, %r{/secrets})
|
11
|
+
.to_return(body: open_test_file('created_secret.json'),
|
12
|
+
status: 200)
|
13
|
+
|
14
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
15
|
+
secret = client.get_secret 'test-secret', 'dev'
|
16
|
+
|
17
|
+
assert_instance_of(Kubeclient::Secret, secret)
|
18
|
+
assert_equal('4e38a198-2bcb-11e5-a483-0e840567604d', secret.metadata.uid)
|
19
|
+
assert_equal('test-secret', secret.metadata.name)
|
20
|
+
assert_equal('v1', secret.apiVersion)
|
21
|
+
assert_equal('Y2F0J3MgYXJlIGF3ZXNvbWUK', secret.data['super-secret'])
|
22
|
+
|
23
|
+
assert_requested(:get,
|
24
|
+
'http://localhost:8080/api/v1/namespaces/dev/secrets/test-secret',
|
25
|
+
times: 1)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_delete_secret_v1
|
29
|
+
stub_request(:get, %r{/api/v1$})
|
30
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
31
|
+
status: 200)
|
32
|
+
|
33
|
+
stub_request(:delete, %r{/secrets})
|
34
|
+
.to_return(status: 200)
|
35
|
+
|
36
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
37
|
+
client.delete_secret 'test-secret', 'dev'
|
38
|
+
|
39
|
+
assert_requested(:delete,
|
40
|
+
'http://localhost:8080/api/v1/namespaces/dev/secrets/test-secret',
|
41
|
+
times: 1)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_create_secret_v1
|
45
|
+
stub_request(:get, %r{/api/v1$})
|
46
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
47
|
+
status: 200)
|
48
|
+
|
49
|
+
stub_request(:post, %r{/secrets})
|
50
|
+
.to_return(body: open_test_file('created_secret.json'),
|
51
|
+
status: 201)
|
52
|
+
|
53
|
+
secret = Kubeclient::Resource.new
|
54
|
+
secret.metadata = {}
|
55
|
+
secret.metadata.name = 'test-secret'
|
56
|
+
secret.metadata.namespace = 'dev'
|
57
|
+
secret.data = {}
|
58
|
+
secret.data['super-secret'] = 'Y2F0J3MgYXJlIGF3ZXNvbWUK'
|
59
|
+
|
60
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/'
|
61
|
+
created_secret = client.create_secret secret
|
62
|
+
assert_instance_of(Kubeclient::Secret, created_secret)
|
63
|
+
assert_equal(secret.metadata.name, created_secret.metadata.name)
|
64
|
+
assert_equal(secret.metadata.namespace, created_secret.metadata.namespace)
|
65
|
+
assert_equal(
|
66
|
+
secret.data['super-secret'],
|
67
|
+
created_secret.data['super-secret']
|
68
|
+
)
|
69
|
+
end
|
70
|
+
end
|