kubeclient 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of kubeclient might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +73 -0
- data/kubeclient.gemspec +0 -1
- data/lib/kubeclient.rb +3 -24
- data/lib/kubeclient/common.rb +153 -63
- data/lib/kubeclient/config.rb +2 -1
- data/lib/kubeclient/version.rb +1 -1
- data/test/cassettes/kubernetes_guestbook.yml +34 -1
- data/test/json/bindings_list.json +10 -0
- data/test/json/config_map_list.json +9 -0
- data/test/json/core_api_resource_list.json +181 -0
- data/test/json/pod_template_list.json +9 -0
- data/test/json/processed_template.json +27 -0
- data/test/test_common.rb +32 -0
- data/test/test_component_status.rb +6 -0
- data/test/test_endpoint.rb +5 -1
- data/test/test_guestbook_go.rb +1 -1
- data/test/test_kubeclient.rb +80 -7
- data/test/test_limit_range.rb +4 -0
- data/test/test_missing_methods.rb +42 -0
- data/test/test_namespace.rb +11 -2
- data/test/test_node.rb +6 -0
- data/test/test_persistent_volume.rb +6 -0
- data/test/test_persistent_volume_claim.rb +6 -0
- data/test/test_pod.rb +6 -0
- data/test/test_process_template.rb +44 -0
- data/test/test_replication_controller.rb +3 -0
- data/test/test_resource_quota.rb +3 -0
- data/test/test_secret.rb +13 -1
- data/test/test_service.rb +38 -7
- data/test/test_service_account.rb +6 -0
- data/test/test_watch.rb +16 -1
- metadata +18 -16
data/test/test_limit_range.rb
CHANGED
@@ -3,6 +3,10 @@ require 'test_helper'
|
|
3
3
|
# LimitRange tests
|
4
4
|
class TestLimitRange < MiniTest::Test
|
5
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
|
+
|
6
10
|
stub_request(:get, %r{/limitranges})
|
7
11
|
.to_return(body: open_test_file('limit_range.json'),
|
8
12
|
status: 200)
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# Test method_missing, respond_to? and respond_to_missing behaviour
|
4
|
+
class TestMissingMethods < MiniTest::Test
|
5
|
+
def test_missing
|
6
|
+
stub_request(:get, %r{/api/v1$}).to_return(
|
7
|
+
body: open_test_file('core_api_resource_list.json'),
|
8
|
+
status: 200
|
9
|
+
)
|
10
|
+
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
11
|
+
assert_equal(true, client.respond_to?(:get_pod))
|
12
|
+
assert_equal(true, client.respond_to?(:get_pods))
|
13
|
+
assert_equal(false, client.respond_to?(:get_pie))
|
14
|
+
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1') # Reset discovery
|
15
|
+
assert_equal(false, client.respond_to?(:get_pie))
|
16
|
+
assert_equal(true, client.respond_to?(:get_pods))
|
17
|
+
assert_equal(true, client.respond_to?(:get_pod))
|
18
|
+
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1') # Reset discovery
|
19
|
+
assert_instance_of(Method, client.method(:get_pods))
|
20
|
+
assert_raises(NameError) do
|
21
|
+
client.method(:get_pies)
|
22
|
+
end
|
23
|
+
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1') # Reset discovery
|
24
|
+
assert_raises(NameError) do
|
25
|
+
client.method(:get_pies)
|
26
|
+
end
|
27
|
+
assert_instance_of(Method, client.method(:get_pods))
|
28
|
+
|
29
|
+
stub_request(:get, %r{/api/v1$}).to_return(
|
30
|
+
body: '',
|
31
|
+
status: 404
|
32
|
+
) # If discovery fails we expect the below raise an exception
|
33
|
+
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
34
|
+
assert_raises(KubeException) do
|
35
|
+
client.method(:get_pods)
|
36
|
+
end
|
37
|
+
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
38
|
+
assert_raises(KubeException) do
|
39
|
+
client.respond_to?(:get_pods)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/test/test_namespace.rb
CHANGED
@@ -3,6 +3,9 @@ require 'test_helper'
|
|
3
3
|
# Namespace entity tests
|
4
4
|
class TestNamespace < MiniTest::Test
|
5
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'),
|
8
|
+
status: 200)
|
6
9
|
stub_request(:get, %r{/namespaces})
|
7
10
|
.to_return(body: open_test_file('namespace.json'),
|
8
11
|
status: 200)
|
@@ -22,10 +25,13 @@ class TestNamespace < MiniTest::Test
|
|
22
25
|
end
|
23
26
|
|
24
27
|
def test_delete_namespace_v1
|
25
|
-
our_namespace = Kubeclient::
|
28
|
+
our_namespace = Kubeclient::Resource.new
|
26
29
|
our_namespace.metadata = {}
|
27
30
|
our_namespace.metadata.name = 'staging'
|
28
31
|
|
32
|
+
stub_request(:get, %r{/api/v1$})
|
33
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
34
|
+
status: 200)
|
29
35
|
stub_request(:delete, %r{/namespaces})
|
30
36
|
.to_return(status: 200)
|
31
37
|
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
@@ -37,11 +43,14 @@ class TestNamespace < MiniTest::Test
|
|
37
43
|
end
|
38
44
|
|
39
45
|
def test_create_namespace
|
46
|
+
stub_request(:get, %r{/api/v1$})
|
47
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
48
|
+
status: 200)
|
40
49
|
stub_request(:post, %r{/namespaces})
|
41
50
|
.to_return(body: open_test_file('created_namespace.json'),
|
42
51
|
status: 201)
|
43
52
|
|
44
|
-
namespace = Kubeclient::
|
53
|
+
namespace = Kubeclient::Resource.new
|
45
54
|
namespace.metadata = {}
|
46
55
|
namespace.metadata.name = 'development'
|
47
56
|
|
data/test/test_node.rb
CHANGED
@@ -6,6 +6,9 @@ class TestNode < MiniTest::Test
|
|
6
6
|
stub_request(:get, %r{/nodes})
|
7
7
|
.to_return(body: open_test_file('node.json'),
|
8
8
|
status: 200)
|
9
|
+
stub_request(:get, %r{/api/v1$})
|
10
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
11
|
+
status: 200)
|
9
12
|
|
10
13
|
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
11
14
|
node = client.get_node('127.0.0.1')
|
@@ -18,6 +21,9 @@ class TestNode < MiniTest::Test
|
|
18
21
|
assert_equal('v1', node.apiVersion)
|
19
22
|
assert_equal('2015-03-19T15:08:20+02:00', node.metadata.creationTimestamp)
|
20
23
|
|
24
|
+
assert_requested(:get,
|
25
|
+
'http://localhost:8080/api/v1',
|
26
|
+
times: 1)
|
21
27
|
assert_requested(:get,
|
22
28
|
'http://localhost:8080/api/v1/nodes/127.0.0.1',
|
23
29
|
times: 1)
|
@@ -6,6 +6,9 @@ class TestPersistentVolume < MiniTest::Test
|
|
6
6
|
stub_request(:get, %r{/persistentvolumes})
|
7
7
|
.to_return(body: open_test_file('persistent_volume.json'),
|
8
8
|
status: 200)
|
9
|
+
stub_request(:get, %r{/api/v1$})
|
10
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
11
|
+
status: 200)
|
9
12
|
|
10
13
|
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
11
14
|
volume = client.get_persistent_volume 'pv0001'
|
@@ -15,6 +18,9 @@ class TestPersistentVolume < MiniTest::Test
|
|
15
18
|
assert_equal('10Gi', volume.spec.capacity.storage)
|
16
19
|
assert_equal('/tmp/data01', volume.spec.hostPath.path)
|
17
20
|
|
21
|
+
assert_requested(:get,
|
22
|
+
'http://localhost:8080/api/v1',
|
23
|
+
times: 1)
|
18
24
|
assert_requested(:get,
|
19
25
|
'http://localhost:8080/api/v1/persistentvolumes/pv0001',
|
20
26
|
times: 1)
|
@@ -6,6 +6,9 @@ class TestPersistentVolumeClaim < MiniTest::Test
|
|
6
6
|
stub_request(:get, %r{/persistentvolumeclaims})
|
7
7
|
.to_return(body: open_test_file('persistent_volume_claim.json'),
|
8
8
|
status: 200)
|
9
|
+
stub_request(:get, %r{/api/v1$})
|
10
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
11
|
+
status: 200)
|
9
12
|
|
10
13
|
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
11
14
|
claim = client.get_persistent_volume_claim 'myclaim-1', 'default'
|
@@ -15,6 +18,9 @@ class TestPersistentVolumeClaim < MiniTest::Test
|
|
15
18
|
assert_equal('3Gi', claim.spec.resources.requests.storage)
|
16
19
|
assert_equal('pv0001', claim.spec.volumeName)
|
17
20
|
|
21
|
+
assert_requested(:get,
|
22
|
+
'http://localhost:8080/api/v1',
|
23
|
+
times: 1)
|
18
24
|
assert_requested(:get,
|
19
25
|
'http://localhost:8080/api/v1/namespaces/default/persistentvolumeclaims/myclaim-1',
|
20
26
|
times: 1)
|
data/test/test_pod.rb
CHANGED
@@ -6,6 +6,9 @@ class TestPod < MiniTest::Test
|
|
6
6
|
stub_request(:get, %r{/pods})
|
7
7
|
.to_return(body: open_test_file('pod.json'),
|
8
8
|
status: 200)
|
9
|
+
stub_request(:get, %r{/api/v1$})
|
10
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
11
|
+
status: 200)
|
9
12
|
|
10
13
|
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
11
14
|
pod = client.get_pod 'redis-master-pod', 'default'
|
@@ -14,6 +17,9 @@ class TestPod < MiniTest::Test
|
|
14
17
|
assert_equal('redis-master3', pod.metadata.name)
|
15
18
|
assert_equal('dockerfile/redis', pod.spec.containers[0]['image'])
|
16
19
|
|
20
|
+
assert_requested(:get,
|
21
|
+
'http://localhost:8080/api/v1',
|
22
|
+
times: 1)
|
17
23
|
assert_requested(:get,
|
18
24
|
'http://localhost:8080/api/v1/namespaces/default/pods/redis-master-pod',
|
19
25
|
times: 1)
|
@@ -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
|
@@ -3,6 +3,9 @@ require 'test_helper'
|
|
3
3
|
# Replication Controller entity tests
|
4
4
|
class TestReplicationController < MiniTest::Test
|
5
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)
|
6
9
|
stub_request(:get, %r{/replicationcontrollers})
|
7
10
|
.to_return(body: open_test_file('replication_controller.json'),
|
8
11
|
status: 200)
|
data/test/test_resource_quota.rb
CHANGED
@@ -3,6 +3,9 @@ require 'test_helper'
|
|
3
3
|
# ResourceQuota tests
|
4
4
|
class TestResourceQuota < MiniTest::Test
|
5
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)
|
6
9
|
stub_request(:get, %r{/resourcequotas})
|
7
10
|
.to_return(body: open_test_file('resource_quota.json'),
|
8
11
|
status: 200)
|
data/test/test_secret.rb
CHANGED
@@ -3,6 +3,10 @@ require 'test_helper'
|
|
3
3
|
# Namespace entity tests
|
4
4
|
class TestSecret < MiniTest::Test
|
5
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
|
+
|
6
10
|
stub_request(:get, %r{/secrets})
|
7
11
|
.to_return(body: open_test_file('created_secret.json'),
|
8
12
|
status: 200)
|
@@ -22,6 +26,10 @@ class TestSecret < MiniTest::Test
|
|
22
26
|
end
|
23
27
|
|
24
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
|
+
|
25
33
|
stub_request(:delete, %r{/secrets})
|
26
34
|
.to_return(status: 200)
|
27
35
|
|
@@ -34,11 +42,15 @@ class TestSecret < MiniTest::Test
|
|
34
42
|
end
|
35
43
|
|
36
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
|
+
|
37
49
|
stub_request(:post, %r{/secrets})
|
38
50
|
.to_return(body: open_test_file('created_secret.json'),
|
39
51
|
status: 201)
|
40
52
|
|
41
|
-
secret = Kubeclient::
|
53
|
+
secret = Kubeclient::Resource.new
|
42
54
|
secret.metadata = {}
|
43
55
|
secret.metadata.name = 'test-secret'
|
44
56
|
secret.metadata.namespace = 'dev'
|
data/test/test_service.rb
CHANGED
@@ -3,7 +3,7 @@ require 'test_helper'
|
|
3
3
|
# Service entity tests
|
4
4
|
class TestService < MiniTest::Test
|
5
5
|
def test_construct_our_own_service
|
6
|
-
our_service = Kubeclient::
|
6
|
+
our_service = Kubeclient::Resource.new
|
7
7
|
our_service.metadata = {}
|
8
8
|
our_service.metadata.name = 'guestbook'
|
9
9
|
our_service.metadata.namespace = 'staging'
|
@@ -24,6 +24,10 @@ class TestService < MiniTest::Test
|
|
24
24
|
hash[:metadata][:labels][:name]
|
25
25
|
|
26
26
|
expected_url = 'http://localhost:8080/api/v1/namespaces/staging/services'
|
27
|
+
stub_request(:get, %r{/api/v1$})
|
28
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
29
|
+
status: 200)
|
30
|
+
|
27
31
|
stub_request(:post, expected_url)
|
28
32
|
.to_return(body: open_test_file('created_service.json'), status: 201)
|
29
33
|
|
@@ -47,7 +51,7 @@ class TestService < MiniTest::Test
|
|
47
51
|
end
|
48
52
|
|
49
53
|
def test_construct_service_from_symbol_keys
|
50
|
-
service = Kubeclient::
|
54
|
+
service = Kubeclient::Resource.new
|
51
55
|
service.metadata = {
|
52
56
|
labels: { tier: 'frontend' },
|
53
57
|
name: 'test-service',
|
@@ -62,6 +66,9 @@ class TestService < MiniTest::Test
|
|
62
66
|
}
|
63
67
|
|
64
68
|
expected_url = 'http://localhost:8080/api/v1/namespaces/staging/services'
|
69
|
+
stub_request(:get, %r{/api/v1$})
|
70
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
71
|
+
status: 200)
|
65
72
|
stub_request(:post, expected_url)
|
66
73
|
.to_return(body: open_test_file('created_service.json'), status: 201)
|
67
74
|
|
@@ -79,7 +86,7 @@ class TestService < MiniTest::Test
|
|
79
86
|
end
|
80
87
|
|
81
88
|
def test_construct_service_from_string_keys
|
82
|
-
service = Kubeclient::
|
89
|
+
service = Kubeclient::Resource.new
|
83
90
|
service.metadata = {
|
84
91
|
'labels' => { 'tier' => 'frontend' },
|
85
92
|
'name' => 'test-service',
|
@@ -93,6 +100,9 @@ class TestService < MiniTest::Test
|
|
93
100
|
}]
|
94
101
|
}
|
95
102
|
|
103
|
+
stub_request(:get, %r{/api/v1$})
|
104
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
105
|
+
status: 200)
|
96
106
|
expected_url = 'http://localhost:8080/api/v1/namespaces/staging/services'
|
97
107
|
stub_request(:post, %r{namespaces/staging/services})
|
98
108
|
.to_return(body: open_test_file('created_service.json'), status: 201)
|
@@ -111,6 +121,9 @@ class TestService < MiniTest::Test
|
|
111
121
|
end
|
112
122
|
|
113
123
|
def test_conversion_from_json_v1
|
124
|
+
stub_request(:get, %r{/api/v1$})
|
125
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
126
|
+
status: 200)
|
114
127
|
stub_request(:get, %r{/services})
|
115
128
|
.to_return(body: open_test_file('service.json'),
|
116
129
|
status: 200)
|
@@ -139,13 +152,16 @@ class TestService < MiniTest::Test
|
|
139
152
|
end
|
140
153
|
|
141
154
|
def test_delete_service
|
142
|
-
our_service = Kubeclient::
|
155
|
+
our_service = Kubeclient::Resource.new
|
143
156
|
our_service.name = 'redis-service'
|
144
157
|
# TODO, new ports assignment to be added
|
145
158
|
our_service.labels = {}
|
146
159
|
our_service.labels.component = 'apiserver'
|
147
160
|
our_service.labels.provider = 'kubernetes'
|
148
161
|
|
162
|
+
stub_request(:get, %r{/api/v1$})
|
163
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
164
|
+
status: 200)
|
149
165
|
stub_request(:delete, %r{/namespaces/default/services})
|
150
166
|
.to_return(status: 200)
|
151
167
|
|
@@ -158,6 +174,9 @@ class TestService < MiniTest::Test
|
|
158
174
|
end
|
159
175
|
|
160
176
|
def test_get_service_no_ns
|
177
|
+
stub_request(:get, %r{/api/v1$})
|
178
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
179
|
+
status: 200)
|
161
180
|
# when not specifying namespace for entities which
|
162
181
|
# are not node or namespace, the request will fail
|
163
182
|
stub_request(:get, %r{/services/redis-slave})
|
@@ -172,6 +191,9 @@ class TestService < MiniTest::Test
|
|
172
191
|
end
|
173
192
|
|
174
193
|
def test_get_service
|
194
|
+
stub_request(:get, %r{/api/v1$})
|
195
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
196
|
+
status: 200)
|
175
197
|
stub_request(:get, %r{/namespaces/development/services/redis-slave})
|
176
198
|
.to_return(body: open_test_file('service.json'),
|
177
199
|
status: 200)
|
@@ -186,13 +208,16 @@ class TestService < MiniTest::Test
|
|
186
208
|
end
|
187
209
|
|
188
210
|
def test_update_service
|
189
|
-
service = Kubeclient::
|
211
|
+
service = Kubeclient::Resource.new
|
190
212
|
name = 'my_service'
|
191
213
|
|
192
214
|
service.metadata = {}
|
193
215
|
service.metadata.name = name
|
194
216
|
service.metadata.namespace = 'development'
|
195
217
|
|
218
|
+
stub_request(:get, %r{/api/v1$})
|
219
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
220
|
+
status: 200)
|
196
221
|
expected_url = "http://localhost:8080/api/v1/namespaces/development/services/#{name}"
|
197
222
|
stub_request(:put, expected_url)
|
198
223
|
.to_return(body: open_test_file('service_update.json'), status: 201)
|
@@ -208,7 +233,7 @@ class TestService < MiniTest::Test
|
|
208
233
|
end
|
209
234
|
|
210
235
|
def test_update_service_with_string_keys
|
211
|
-
service = Kubeclient::
|
236
|
+
service = Kubeclient::Resource.new
|
212
237
|
name = 'my_service'
|
213
238
|
|
214
239
|
service.metadata = {
|
@@ -216,6 +241,9 @@ class TestService < MiniTest::Test
|
|
216
241
|
'namespace' => 'development'
|
217
242
|
}
|
218
243
|
|
244
|
+
stub_request(:get, %r{/api/v1$})
|
245
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
246
|
+
status: 200)
|
219
247
|
expected_url = "http://localhost:8080/api/v1/namespaces/development/services/#{name}"
|
220
248
|
stub_request(:put, expected_url)
|
221
249
|
.to_return(body: open_test_file('service_update.json'), status: 201)
|
@@ -231,13 +259,16 @@ class TestService < MiniTest::Test
|
|
231
259
|
end
|
232
260
|
|
233
261
|
def test_patch_service
|
234
|
-
service = Kubeclient::
|
262
|
+
service = Kubeclient::Resource.new
|
235
263
|
name = 'my_service'
|
236
264
|
|
237
265
|
service.metadata = {}
|
238
266
|
service.metadata.name = name
|
239
267
|
service.metadata.namespace = 'development'
|
240
268
|
|
269
|
+
stub_request(:get, %r{/api/v1$})
|
270
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
271
|
+
status: 200)
|
241
272
|
expected_url = "http://localhost:8080/api/v1/namespaces/development/services/#{name}"
|
242
273
|
stub_request(:patch, expected_url)
|
243
274
|
.to_return(body: open_test_file('service_patch.json'), status: 200)
|
@@ -6,6 +6,9 @@ class TestServiceAccount < MiniTest::Test
|
|
6
6
|
stub_request(:get, %r{/serviceaccounts})
|
7
7
|
.to_return(body: open_test_file('service_account.json'),
|
8
8
|
status: 200)
|
9
|
+
stub_request(:get, %r{/api/v1$})
|
10
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
11
|
+
status: 200)
|
9
12
|
|
10
13
|
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
11
14
|
account = client.get_service_account 'default'
|
@@ -18,5 +21,8 @@ class TestServiceAccount < MiniTest::Test
|
|
18
21
|
assert_requested(:get,
|
19
22
|
'http://localhost:8080/api/v1/serviceaccounts/default',
|
20
23
|
times: 1)
|
24
|
+
assert_requested(:get,
|
25
|
+
'http://localhost:8080/api/v1',
|
26
|
+
times: 1)
|
21
27
|
end
|
22
28
|
end
|