kubeclient 4.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of kubeclient might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/CHANGELOG.md +11 -1
- data/README.md +18 -0
- data/RELEASING.md +40 -40
- data/lib/kubeclient/common.rb +57 -22
- data/lib/kubeclient/entity_list.rb +7 -2
- data/lib/kubeclient/version.rb +1 -1
- data/test/config/allinone.kubeconfig +3 -3
- data/test/config/external-ca.pem +14 -14
- data/test/config/external-cert.pem +17 -17
- data/test/config/external-key.rsa +25 -25
- data/test/json/config.istio.io_api_resource_list.json +679 -0
- data/test/json/created_security_context_constraint.json +65 -0
- data/test/json/pods_1.json +265 -0
- data/test/json/pods_2.json +102 -0
- data/test/json/pods_410.json +9 -0
- data/test/json/security.openshift.io_api_resource_list.json +69 -0
- data/test/json/security_context_constraint_list.json +375 -0
- data/test/test_common.rb +21 -2
- data/test/test_component_status.rb +1 -2
- data/test/test_config.rb +4 -4
- data/test/test_endpoint.rb +27 -8
- data/test/test_helper.rb +5 -0
- data/test/test_kubeclient.rb +4 -9
- data/test/test_limit_range.rb +1 -3
- data/test/test_missing_methods.rb +30 -4
- data/test/test_namespace.rb +3 -6
- data/test/test_node.rb +2 -4
- data/test/test_persistent_volume.rb +1 -2
- data/test/test_persistent_volume_claim.rb +1 -3
- data/test/test_pod.rb +54 -2
- data/test/test_replication_controller.rb +2 -7
- data/test/test_resource_quota.rb +1 -3
- data/test/test_secret.rb +3 -12
- data/test/test_security_context_constraint.rb +62 -0
- data/test/test_service.rb +10 -31
- data/test/test_service_account.rb +1 -3
- data/test/test_watch.rb +7 -16
- metadata +19 -3
data/test/test_helper.rb
CHANGED
@@ -10,3 +10,8 @@ require 'kubeclient'
|
|
10
10
|
def open_test_file(name)
|
11
11
|
File.new(File.join(File.dirname(__FILE__), name.split('.').last, name))
|
12
12
|
end
|
13
|
+
|
14
|
+
def stub_core_api_list
|
15
|
+
stub_request(:get, %r{/api/v1$})
|
16
|
+
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200)
|
17
|
+
end
|
data/test/test_kubeclient.rb
CHANGED
@@ -208,6 +208,7 @@ class KubeclientTest < MiniTest::Test
|
|
208
208
|
|
209
209
|
refute_empty(services)
|
210
210
|
assert_instance_of(Kubeclient::Common::EntityList, services)
|
211
|
+
# Stripping of 'List' in collection.kind RecursiveOpenStruct mode only is historic.
|
211
212
|
assert_equal('Service', services.kind)
|
212
213
|
assert_equal(2, services.size)
|
213
214
|
assert_instance_of(Kubeclient::Resource, services[0])
|
@@ -234,6 +235,7 @@ class KubeclientTest < MiniTest::Test
|
|
234
235
|
|
235
236
|
response = client.get_services(as: :parsed)
|
236
237
|
assert_equal Hash, response.class
|
238
|
+
assert_equal 'ServiceList', response['kind']
|
237
239
|
assert_equal %w[metadata spec status], response['items'].first.keys
|
238
240
|
end
|
239
241
|
|
@@ -243,6 +245,7 @@ class KubeclientTest < MiniTest::Test
|
|
243
245
|
|
244
246
|
response = client.get_services(as: :parsed_symbolized)
|
245
247
|
assert_equal Hash, response.class
|
248
|
+
assert_equal 'ServiceList', response[:kind]
|
246
249
|
assert_equal %i[metadata spec status], response[:items].first.keys
|
247
250
|
end
|
248
251
|
|
@@ -469,10 +472,7 @@ class KubeclientTest < MiniTest::Test
|
|
469
472
|
end
|
470
473
|
|
471
474
|
def test_api_bearer_token_success
|
472
|
-
|
473
|
-
.to_return(
|
474
|
-
body: open_test_file('core_api_resource_list.json'), status: 200
|
475
|
-
)
|
475
|
+
stub_core_api_list
|
476
476
|
stub_request(:get, 'http://localhost:8080/api/v1/pods')
|
477
477
|
.with(headers: { Authorization: 'Bearer valid_token' })
|
478
478
|
.to_return(
|
@@ -839,11 +839,6 @@ class KubeclientTest < MiniTest::Test
|
|
839
839
|
.to_return(body: open_test_file('entity_list.json'), status: 200)
|
840
840
|
end
|
841
841
|
|
842
|
-
def stub_core_api_list
|
843
|
-
stub_request(:get, %r{/api/v1$})
|
844
|
-
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200)
|
845
|
-
end
|
846
|
-
|
847
842
|
def client
|
848
843
|
@client ||= Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
849
844
|
end
|
data/test/test_limit_range.rb
CHANGED
@@ -3,9 +3,7 @@ require_relative 'test_helper'
|
|
3
3
|
# LimitRange tests
|
4
4
|
class TestLimitRange < MiniTest::Test
|
5
5
|
def test_get_from_json_v1
|
6
|
-
|
7
|
-
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200)
|
8
|
-
|
6
|
+
stub_core_api_list
|
9
7
|
stub_request(:get, %r{/limitranges})
|
10
8
|
.to_return(body: open_test_file('limit_range.json'), status: 200)
|
11
9
|
|
@@ -3,10 +3,7 @@ require_relative 'test_helper'
|
|
3
3
|
# Test method_missing, respond_to? and respond_to_missing behaviour
|
4
4
|
class TestMissingMethods < MiniTest::Test
|
5
5
|
def test_missing
|
6
|
-
|
7
|
-
body: open_test_file('core_api_resource_list.json'),
|
8
|
-
status: 200
|
9
|
-
)
|
6
|
+
stub_core_api_list
|
10
7
|
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
11
8
|
assert_equal(true, client.respond_to?(:get_pod))
|
12
9
|
assert_equal(true, client.respond_to?(:get_pods))
|
@@ -31,6 +28,10 @@ class TestMissingMethods < MiniTest::Test
|
|
31
28
|
status: 404
|
32
29
|
) # If discovery fails we expect the below raise an exception
|
33
30
|
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
31
|
+
assert_raises(Kubeclient::HttpError) do
|
32
|
+
client.discover
|
33
|
+
end
|
34
|
+
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
34
35
|
assert_raises(Kubeclient::HttpError) do
|
35
36
|
client.method(:get_pods)
|
36
37
|
end
|
@@ -39,4 +40,29 @@ class TestMissingMethods < MiniTest::Test
|
|
39
40
|
client.respond_to?(:get_pods)
|
40
41
|
end
|
41
42
|
end
|
43
|
+
|
44
|
+
def test_irregular_names
|
45
|
+
stub_core_api_list
|
46
|
+
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
47
|
+
assert_equal(true, client.respond_to?(:get_endpoint))
|
48
|
+
assert_equal(true, client.respond_to?(:get_endpoints))
|
49
|
+
|
50
|
+
stub_request(:get, %r{/apis/security.openshift.io/v1$}).to_return(
|
51
|
+
body: open_test_file('security.openshift.io_api_resource_list.json'),
|
52
|
+
status: 200
|
53
|
+
)
|
54
|
+
client = Kubeclient::Client.new('http://localhost:8080/apis/security.openshift.io', 'v1')
|
55
|
+
assert_equal(true, client.respond_to?(:get_security_context_constraint))
|
56
|
+
assert_equal(true, client.respond_to?(:get_security_context_constraints))
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_lowercase_kind
|
60
|
+
stub_request(:get, %r{/apis/config.istio.io/v1alpha2$}).to_return(
|
61
|
+
body: open_test_file('config.istio.io_api_resource_list.json'),
|
62
|
+
status: 200
|
63
|
+
)
|
64
|
+
client = Kubeclient::Client.new('http://localhost:8080/apis/config.istio.io', 'v1alpha2')
|
65
|
+
assert_equal(true, client.respond_to?(:get_servicecontrolreport))
|
66
|
+
assert_equal(true, client.respond_to?(:get_servicecontrolreports))
|
67
|
+
end
|
42
68
|
end
|
data/test/test_namespace.rb
CHANGED
@@ -3,8 +3,7 @@ require_relative 'test_helper'
|
|
3
3
|
# Namespace entity tests
|
4
4
|
class TestNamespace < MiniTest::Test
|
5
5
|
def test_get_namespace_v1
|
6
|
-
|
7
|
-
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200)
|
6
|
+
stub_core_api_list
|
8
7
|
stub_request(:get, %r{/namespaces})
|
9
8
|
.to_return(body: open_test_file('namespace.json'), status: 200)
|
10
9
|
|
@@ -29,8 +28,7 @@ class TestNamespace < MiniTest::Test
|
|
29
28
|
our_namespace.metadata = {}
|
30
29
|
our_namespace.metadata.name = 'staging'
|
31
30
|
|
32
|
-
|
33
|
-
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200)
|
31
|
+
stub_core_api_list
|
34
32
|
stub_request(:delete, %r{/namespaces})
|
35
33
|
.to_return(body: open_test_file('namespace.json'), status: 200)
|
36
34
|
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
@@ -45,8 +43,7 @@ class TestNamespace < MiniTest::Test
|
|
45
43
|
end
|
46
44
|
|
47
45
|
def test_create_namespace
|
48
|
-
|
49
|
-
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200)
|
46
|
+
stub_core_api_list
|
50
47
|
stub_request(:post, %r{/namespaces})
|
51
48
|
.to_return(body: open_test_file('created_namespace.json'), status: 201)
|
52
49
|
|
data/test/test_node.rb
CHANGED
@@ -3,10 +3,9 @@ require_relative 'test_helper'
|
|
3
3
|
# Node entity tests
|
4
4
|
class TestNode < MiniTest::Test
|
5
5
|
def test_get_from_json_v1
|
6
|
+
stub_core_api_list
|
6
7
|
stub_request(:get, %r{/nodes})
|
7
8
|
.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
9
|
|
11
10
|
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
12
11
|
node = client.get_node('127.0.0.1')
|
@@ -32,10 +31,9 @@ class TestNode < MiniTest::Test
|
|
32
31
|
end
|
33
32
|
|
34
33
|
def test_get_from_json_v1_raw
|
34
|
+
stub_core_api_list
|
35
35
|
stub_request(:get, %r{/nodes})
|
36
36
|
.to_return(body: open_test_file('node.json'), status: 200)
|
37
|
-
stub_request(:get, %r{/api/v1$})
|
38
|
-
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200)
|
39
37
|
|
40
38
|
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
41
39
|
response = client.get_node('127.0.0.1', nil, as: :raw)
|
@@ -3,10 +3,9 @@ require_relative 'test_helper'
|
|
3
3
|
# PersistentVolume tests
|
4
4
|
class TestPersistentVolume < MiniTest::Test
|
5
5
|
def test_get_from_json_v1
|
6
|
+
stub_core_api_list
|
6
7
|
stub_request(:get, %r{/persistentvolumes})
|
7
8
|
.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
9
|
|
11
10
|
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
12
11
|
volume = client.get_persistent_volume('pv0001')
|
@@ -3,11 +3,9 @@ require_relative 'test_helper'
|
|
3
3
|
# PersistentVolumeClaim tests
|
4
4
|
class TestPersistentVolumeClaim < MiniTest::Test
|
5
5
|
def test_get_from_json_v1
|
6
|
+
stub_core_api_list
|
6
7
|
stub_request(:get, %r{/persistentvolumeclaims})
|
7
8
|
.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
9
|
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
12
10
|
claim = client.get_persistent_volume_claim('myclaim-1', 'default')
|
13
11
|
|
data/test/test_pod.rb
CHANGED
@@ -3,10 +3,9 @@ require_relative 'test_helper'
|
|
3
3
|
# Pod entity tests
|
4
4
|
class TestPod < MiniTest::Test
|
5
5
|
def test_get_from_json_v1
|
6
|
+
stub_core_api_list
|
6
7
|
stub_request(:get, %r{/pods})
|
7
8
|
.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
9
|
|
11
10
|
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
12
11
|
pod = client.get_pod('redis-master-pod', 'default')
|
@@ -26,4 +25,57 @@ class TestPod < MiniTest::Test
|
|
26
25
|
times: 1
|
27
26
|
)
|
28
27
|
end
|
28
|
+
|
29
|
+
def test_get_chunks
|
30
|
+
stub_core_api_list
|
31
|
+
stub_request(:get, %r{/pods})
|
32
|
+
.to_return(body: open_test_file('pods_1.json'), status: 200)
|
33
|
+
|
34
|
+
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
35
|
+
pods = client.get_pods(limit: 2)
|
36
|
+
|
37
|
+
assert_equal(2, pods.count)
|
38
|
+
assert_equal('eyJ2IjoibWV0YS5rOHMua', pods.continue)
|
39
|
+
|
40
|
+
continue = pods.continue
|
41
|
+
|
42
|
+
stub_request(:get, %r{/pods})
|
43
|
+
.to_return(body: open_test_file('pods_2.json'), status: 200)
|
44
|
+
|
45
|
+
pods = client.get_pods(limit: 2, continue: continue)
|
46
|
+
assert_equal(2, pods.count)
|
47
|
+
assert_nil(pods.continue)
|
48
|
+
|
49
|
+
assert_requested(
|
50
|
+
:get,
|
51
|
+
'http://localhost:8080/api/v1',
|
52
|
+
times: 1
|
53
|
+
)
|
54
|
+
assert_requested(
|
55
|
+
:get,
|
56
|
+
'http://localhost:8080/api/v1/pods?limit=2',
|
57
|
+
times: 1
|
58
|
+
)
|
59
|
+
assert_requested(
|
60
|
+
:get,
|
61
|
+
"http://localhost:8080/api/v1/pods?continue=#{continue}&limit=2",
|
62
|
+
times: 1
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_get_chunks_410_gone
|
67
|
+
stub_core_api_list
|
68
|
+
stub_request(:get, %r{/pods})
|
69
|
+
.to_return(body: open_test_file('pods_410.json'), status: 410)
|
70
|
+
|
71
|
+
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
72
|
+
|
73
|
+
err = assert_raises Kubeclient::HttpError do
|
74
|
+
client.get_pods(limit: 2, continue: 'eyJ2IjoibWV0YS5')
|
75
|
+
end
|
76
|
+
|
77
|
+
assert_equal(err.message,
|
78
|
+
"The provided from parameter is too old to display a consistent list result. \
|
79
|
+
You must start a new list without the from.")
|
80
|
+
end
|
29
81
|
end
|
@@ -3,9 +3,7 @@ require_relative 'test_helper'
|
|
3
3
|
# Replication Controller entity tests
|
4
4
|
class TestReplicationController < MiniTest::Test
|
5
5
|
def test_get_from_json_v1
|
6
|
-
|
7
|
-
.to_return(body: open_test_file('core_api_resource_list.json'),
|
8
|
-
status: 200)
|
6
|
+
stub_core_api_list
|
9
7
|
stub_request(:get, %r{/replicationcontrollers})
|
10
8
|
.to_return(body: open_test_file('replication_controller.json'),
|
11
9
|
status: 200)
|
@@ -26,10 +24,7 @@ class TestReplicationController < MiniTest::Test
|
|
26
24
|
end
|
27
25
|
|
28
26
|
def test_delete_replicaset_cascade
|
29
|
-
|
30
|
-
.to_return(body: open_test_file('core_api_resource_list.json'),
|
31
|
-
status: 200)
|
32
|
-
|
27
|
+
stub_core_api_list
|
33
28
|
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
34
29
|
opts = Kubeclient::Resource.new(
|
35
30
|
apiVersion: 'meta/v1',
|
data/test/test_resource_quota.rb
CHANGED
@@ -3,9 +3,7 @@ require_relative 'test_helper'
|
|
3
3
|
# ResourceQuota tests
|
4
4
|
class TestResourceQuota < MiniTest::Test
|
5
5
|
def test_get_from_json_v1
|
6
|
-
|
7
|
-
.to_return(body: open_test_file('core_api_resource_list.json'),
|
8
|
-
status: 200)
|
6
|
+
stub_core_api_list
|
9
7
|
stub_request(:get, %r{/resourcequotas})
|
10
8
|
.to_return(body: open_test_file('resource_quota.json'),
|
11
9
|
status: 200)
|
data/test/test_secret.rb
CHANGED
@@ -3,10 +3,7 @@ require_relative 'test_helper'
|
|
3
3
|
# Namespace entity tests
|
4
4
|
class TestSecret < MiniTest::Test
|
5
5
|
def test_get_secret_v1
|
6
|
-
|
7
|
-
.to_return(body: open_test_file('core_api_resource_list.json'),
|
8
|
-
status: 200)
|
9
|
-
|
6
|
+
stub_core_api_list
|
10
7
|
stub_request(:get, %r{/secrets})
|
11
8
|
.to_return(body: open_test_file('created_secret.json'),
|
12
9
|
status: 200)
|
@@ -26,10 +23,7 @@ class TestSecret < MiniTest::Test
|
|
26
23
|
end
|
27
24
|
|
28
25
|
def test_delete_secret_v1
|
29
|
-
|
30
|
-
.to_return(body: open_test_file('core_api_resource_list.json'),
|
31
|
-
status: 200)
|
32
|
-
|
26
|
+
stub_core_api_list
|
33
27
|
stub_request(:delete, %r{/secrets})
|
34
28
|
.to_return(status: 200, body: open_test_file('created_secret.json'))
|
35
29
|
|
@@ -43,10 +37,7 @@ class TestSecret < MiniTest::Test
|
|
43
37
|
end
|
44
38
|
|
45
39
|
def test_create_secret_v1
|
46
|
-
|
47
|
-
.to_return(body: open_test_file('core_api_resource_list.json'),
|
48
|
-
status: 200)
|
49
|
-
|
40
|
+
stub_core_api_list
|
50
41
|
stub_request(:post, %r{/secrets})
|
51
42
|
.to_return(body: open_test_file('created_secret.json'),
|
52
43
|
status: 201)
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
# kind: 'SecurityContextConstraints' entity tests.
|
4
|
+
# This is one of the unusual `kind`s that are already plural (https://github.com/kubernetes/kubernetes/issues/8115).
|
5
|
+
# We force singular in method names like 'create_endpoint',
|
6
|
+
# but `kind` should remain plural as in kubernetes.
|
7
|
+
class TestSecurityContextConstraints < MiniTest::Test
|
8
|
+
def test_create_security_context_constraint
|
9
|
+
stub_request(:get, %r{/apis/security.openshift.io/v1$}).to_return(
|
10
|
+
body: open_test_file('security.openshift.io_api_resource_list.json'),
|
11
|
+
status: 200
|
12
|
+
)
|
13
|
+
|
14
|
+
testing_scc = Kubeclient::Resource.new(
|
15
|
+
metadata: {
|
16
|
+
name: 'teleportation'
|
17
|
+
},
|
18
|
+
runAsUser: {
|
19
|
+
type: 'MustRunAs'
|
20
|
+
},
|
21
|
+
seLinuxContext: {
|
22
|
+
type: 'MustRunAs'
|
23
|
+
}
|
24
|
+
)
|
25
|
+
req_body = '{"metadata":{"name":"teleportation"},"runAsUser":{"type":"MustRunAs"},' \
|
26
|
+
'"seLinuxContext":{"type":"MustRunAs"},' \
|
27
|
+
'"kind":"SecurityContextConstraints","apiVersion":"security.openshift.io/v1"}'
|
28
|
+
|
29
|
+
stub_request(:post, 'http://localhost:8080/apis/security.openshift.io/v1/securitycontextconstraints')
|
30
|
+
.with(body: req_body)
|
31
|
+
.to_return(body: open_test_file('created_security_context_constraint.json'), status: 201)
|
32
|
+
|
33
|
+
client = Kubeclient::Client.new('http://localhost:8080/apis/security.openshift.io', 'v1')
|
34
|
+
created_scc = client.create_security_context_constraint(testing_scc)
|
35
|
+
assert_equal('SecurityContextConstraints', created_scc.kind)
|
36
|
+
assert_equal('security.openshift.io/v1', created_scc.apiVersion)
|
37
|
+
|
38
|
+
client = Kubeclient::Client.new('http://localhost:8080/apis/security.openshift.io', 'v1',
|
39
|
+
as: :parsed_symbolized)
|
40
|
+
created_scc = client.create_security_context_constraint(testing_scc)
|
41
|
+
assert_equal('SecurityContextConstraints', created_scc[:kind])
|
42
|
+
assert_equal('security.openshift.io/v1', created_scc[:apiVersion])
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_get_security_context_constraints
|
46
|
+
stub_request(:get, %r{/apis/security.openshift.io/v1$}).to_return(
|
47
|
+
body: open_test_file('security.openshift.io_api_resource_list.json'),
|
48
|
+
status: 200
|
49
|
+
)
|
50
|
+
stub_request(:get, %r{/securitycontextconstraints})
|
51
|
+
.to_return(body: open_test_file('security_context_constraint_list.json'), status: 200)
|
52
|
+
client = Kubeclient::Client.new('http://localhost:8080/apis/security.openshift.io', 'v1')
|
53
|
+
|
54
|
+
collection = client.get_security_context_constraints(as: :parsed_symbolized)
|
55
|
+
assert_equal('SecurityContextConstraintsList', collection[:kind])
|
56
|
+
assert_equal('security.openshift.io/v1', collection[:apiVersion])
|
57
|
+
|
58
|
+
# Stripping of 'List' in collection.kind RecursiveOpenStruct mode only is historic.
|
59
|
+
collection = client.get_security_context_constraints
|
60
|
+
assert_equal('SecurityContextConstraints', collection.kind)
|
61
|
+
end
|
62
|
+
end
|
data/test/test_service.rb
CHANGED
@@ -25,10 +25,7 @@ class TestService < MiniTest::Test
|
|
25
25
|
hash[:metadata][:labels][:name])
|
26
26
|
|
27
27
|
expected_url = 'http://localhost:8080/api/v1/namespaces/staging/services'
|
28
|
-
|
29
|
-
.to_return(body: open_test_file('core_api_resource_list.json'),
|
30
|
-
status: 200)
|
31
|
-
|
28
|
+
stub_core_api_list
|
32
29
|
stub_request(:post, expected_url)
|
33
30
|
.to_return(body: open_test_file('created_service.json'), status: 201)
|
34
31
|
|
@@ -67,9 +64,7 @@ class TestService < MiniTest::Test
|
|
67
64
|
}
|
68
65
|
|
69
66
|
expected_url = 'http://localhost:8080/api/v1/namespaces/staging/services'
|
70
|
-
|
71
|
-
.to_return(body: open_test_file('core_api_resource_list.json'),
|
72
|
-
status: 200)
|
67
|
+
stub_core_api_list
|
73
68
|
stub_request(:post, expected_url)
|
74
69
|
.to_return(body: open_test_file('created_service.json'), status: 201)
|
75
70
|
|
@@ -101,9 +96,7 @@ class TestService < MiniTest::Test
|
|
101
96
|
}]
|
102
97
|
}
|
103
98
|
|
104
|
-
|
105
|
-
.to_return(body: open_test_file('core_api_resource_list.json'),
|
106
|
-
status: 200)
|
99
|
+
stub_core_api_list
|
107
100
|
expected_url = 'http://localhost:8080/api/v1/namespaces/staging/services'
|
108
101
|
stub_request(:post, %r{namespaces/staging/services})
|
109
102
|
.to_return(body: open_test_file('created_service.json'), status: 201)
|
@@ -122,9 +115,7 @@ class TestService < MiniTest::Test
|
|
122
115
|
end
|
123
116
|
|
124
117
|
def test_conversion_from_json_v1
|
125
|
-
|
126
|
-
.to_return(body: open_test_file('core_api_resource_list.json'),
|
127
|
-
status: 200)
|
118
|
+
stub_core_api_list
|
128
119
|
stub_request(:get, %r{/services})
|
129
120
|
.to_return(body: open_test_file('service.json'),
|
130
121
|
status: 200)
|
@@ -160,9 +151,7 @@ class TestService < MiniTest::Test
|
|
160
151
|
our_service.labels.component = 'apiserver'
|
161
152
|
our_service.labels.provider = 'kubernetes'
|
162
153
|
|
163
|
-
|
164
|
-
.to_return(body: open_test_file('core_api_resource_list.json'),
|
165
|
-
status: 200)
|
154
|
+
stub_core_api_list
|
166
155
|
stub_request(:delete, %r{/namespaces/default/services})
|
167
156
|
.to_return(body: open_test_file('service.json'), status: 200)
|
168
157
|
|
@@ -176,9 +165,7 @@ class TestService < MiniTest::Test
|
|
176
165
|
end
|
177
166
|
|
178
167
|
def test_get_service_no_ns
|
179
|
-
|
180
|
-
.to_return(body: open_test_file('core_api_resource_list.json'),
|
181
|
-
status: 200)
|
168
|
+
stub_core_api_list
|
182
169
|
# when not specifying namespace for entities which
|
183
170
|
# are not node or namespace, the request will fail
|
184
171
|
stub_request(:get, %r{/services/redis-slave})
|
@@ -193,9 +180,7 @@ class TestService < MiniTest::Test
|
|
193
180
|
end
|
194
181
|
|
195
182
|
def test_get_service
|
196
|
-
|
197
|
-
.to_return(body: open_test_file('core_api_resource_list.json'),
|
198
|
-
status: 200)
|
183
|
+
stub_core_api_list
|
199
184
|
stub_request(:get, %r{/namespaces/development/services/redis-slave})
|
200
185
|
.to_return(body: open_test_file('service.json'),
|
201
186
|
status: 200)
|
@@ -217,9 +202,7 @@ class TestService < MiniTest::Test
|
|
217
202
|
service.metadata.name = name
|
218
203
|
service.metadata.namespace = 'development'
|
219
204
|
|
220
|
-
|
221
|
-
.to_return(body: open_test_file('core_api_resource_list.json'),
|
222
|
-
status: 200)
|
205
|
+
stub_core_api_list
|
223
206
|
expected_url = "http://localhost:8080/api/v1/namespaces/development/services/#{name}"
|
224
207
|
stub_request(:put, expected_url)
|
225
208
|
.to_return(body: open_test_file('service_update.json'), status: 201)
|
@@ -244,9 +227,7 @@ class TestService < MiniTest::Test
|
|
244
227
|
'namespace' => 'development'
|
245
228
|
}
|
246
229
|
|
247
|
-
|
248
|
-
.to_return(body: open_test_file('core_api_resource_list.json'),
|
249
|
-
status: 200)
|
230
|
+
stub_core_api_list
|
250
231
|
expected_url = "http://localhost:8080/api/v1/namespaces/development/services/#{name}"
|
251
232
|
stub_request(:put, expected_url)
|
252
233
|
.to_return(body: open_test_file('service_update.json'), status: 201)
|
@@ -270,9 +251,7 @@ class TestService < MiniTest::Test
|
|
270
251
|
service.metadata.name = name
|
271
252
|
service.metadata.namespace = 'development'
|
272
253
|
|
273
|
-
|
274
|
-
.to_return(body: open_test_file('core_api_resource_list.json'),
|
275
|
-
status: 200)
|
254
|
+
stub_core_api_list
|
276
255
|
expected_url = "http://localhost:8080/api/v1/namespaces/development/services/#{name}"
|
277
256
|
stub_request(:patch, expected_url)
|
278
257
|
.to_return(body: open_test_file('service_patch.json'), status: 200)
|