dkron-rb 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +65 -0
- data/LICENSE +201 -0
- data/README.md +98 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config.json +5 -0
- data/dkron-rb-0.0.1.gem +0 -0
- data/dkron-rb-0.0.2.gem +0 -0
- data/dkron-rb.gemspec +55 -0
- data/docs/Agent.md +7 -0
- data/docs/DefaultApi.md +131 -0
- data/docs/Execution.md +13 -0
- data/docs/ExecutionsApi.md +55 -0
- data/docs/InlineResponse200.md +10 -0
- data/docs/Job.md +24 -0
- data/docs/JobsApi.md +237 -0
- data/docs/MainApi.md +90 -0
- data/docs/Member.md +18 -0
- data/docs/MembersApi.md +49 -0
- data/docs/Serf.md +7 -0
- data/docs/Status.md +7 -0
- data/docs/Tags.md +7 -0
- data/git_push.sh +67 -0
- data/lib/dkron-rb.rb +47 -0
- data/lib/dkron-rb/api/default_api.rb +193 -0
- data/lib/dkron-rb/api/executions_api.rb +91 -0
- data/lib/dkron-rb/api/jobs_api.rb +315 -0
- data/lib/dkron-rb/api/members_api.rb +87 -0
- data/lib/dkron-rb/api_client.rb +378 -0
- data/lib/dkron-rb/api_error.rb +47 -0
- data/lib/dkron-rb/configuration.rb +207 -0
- data/lib/dkron-rb/cron.rb +152 -0
- data/lib/dkron-rb/models/agent.rb +152 -0
- data/lib/dkron-rb/models/execution.rb +250 -0
- data/lib/dkron-rb/models/inline_response_200.rb +181 -0
- data/lib/dkron-rb/models/job.rb +369 -0
- data/lib/dkron-rb/models/member.rb +301 -0
- data/lib/dkron-rb/models/serf.rb +152 -0
- data/lib/dkron-rb/models/status.rb +190 -0
- data/lib/dkron-rb/models/tags.rb +152 -0
- data/lib/dkron-rb/numeric_seconds.rb +48 -0
- data/lib/dkron-rb/version.rb +26 -0
- data/lib/dkron.rb +9 -0
- data/pkg/dkron-rb-0.9.2.gem +0 -0
- data/seeds.rb +18 -0
- data/spec/api/default_api_spec.rb +80 -0
- data/spec/api/executions_api_spec.rb +51 -0
- data/spec/api/jobs_api_spec.rb +114 -0
- data/spec/api/main_api_spec.rb +65 -0
- data/spec/api/members_api_spec.rb +50 -0
- data/spec/api_client_spec.rb +237 -0
- data/spec/configuration_spec.rb +53 -0
- data/spec/models/agent_spec.rb +36 -0
- data/spec/models/execution_spec.rb +96 -0
- data/spec/models/inline_response_200_spec.rb +66 -0
- data/spec/models/job_spec.rb +186 -0
- data/spec/models/member_spec.rb +146 -0
- data/spec/models/serf_spec.rb +36 -0
- data/spec/models/status_spec.rb +36 -0
- data/spec/models/tags_spec.rb +36 -0
- data/spec/spec_helper.rb +122 -0
- metadata +309 -0
@@ -0,0 +1,80 @@
|
|
1
|
+
=begin
|
2
|
+
Dkron REST API
|
3
|
+
|
4
|
+
You can communicate with Dkron using a RESTful JSON API over HTTP. Dkron nodes usually listen on port `8080` for API requests. All examples in this section assume that you've found a running leader at `localhost:8080`.\n\nDkron implements a RESTful JSON API over HTTP to communicate with software clients. Dkron listens in port `8080` by default. All examples in this section assume that you're using the default port.\n\nDefault API responses are unformatted JSON add the `pretty=true` param to format the response.\n
|
5
|
+
|
6
|
+
OpenAPI spec version: 0.9.0
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'spec_helper'
|
14
|
+
require 'json'
|
15
|
+
|
16
|
+
# Unit tests for Dkron::DefaultApi
|
17
|
+
# Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
|
18
|
+
# Please update as you see appropriate
|
19
|
+
describe 'DefaultApi' do
|
20
|
+
before do
|
21
|
+
# run before each test
|
22
|
+
@instance = Dkron::DefaultApi.new
|
23
|
+
end
|
24
|
+
|
25
|
+
after do
|
26
|
+
# run after each test
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'test an instance of DefaultApi' do
|
30
|
+
it 'should create an instact of DefaultApi' do
|
31
|
+
@instance.should be_a(Dkron::DefaultApi)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# unit tests for get_leader
|
36
|
+
#
|
37
|
+
# List members.\n
|
38
|
+
# @param [Hash] opts the optional parameters
|
39
|
+
# @return [Member]
|
40
|
+
describe 'get_leader test' do
|
41
|
+
it "should work" do
|
42
|
+
# assertion here
|
43
|
+
# should be_a()
|
44
|
+
# should be_nil
|
45
|
+
# should ==
|
46
|
+
# should_not ==
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# unit tests for leave
|
51
|
+
#
|
52
|
+
# Force the node to leave the cluster.\n
|
53
|
+
# @param [Hash] opts the optional parameters
|
54
|
+
# @return [Array<Member>]
|
55
|
+
describe 'leave test' do
|
56
|
+
it "should work" do
|
57
|
+
# assertion here
|
58
|
+
# should be_a()
|
59
|
+
# should be_nil
|
60
|
+
# should ==
|
61
|
+
# should_not ==
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# unit tests for status
|
66
|
+
#
|
67
|
+
# Gets `Status` object.\n
|
68
|
+
# @param [Hash] opts the optional parameters
|
69
|
+
# @return [Status]
|
70
|
+
describe 'status test' do
|
71
|
+
it "should work" do
|
72
|
+
# assertion here
|
73
|
+
# should be_a()
|
74
|
+
# should be_nil
|
75
|
+
# should ==
|
76
|
+
# should_not ==
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
=begin
|
2
|
+
Dkron REST API
|
3
|
+
|
4
|
+
You can communicate with Dkron using a RESTful JSON API over HTTP. Dkron nodes usually listen on port `8080` for API requests. All examples in this section assume that you've found a running leader at `localhost:8080`.\n\nDkron implements a RESTful JSON API over HTTP to communicate with software clients. Dkron listens in port `8080` by default. All examples in this section assume that you're using the default port.\n\nDefault API responses are unformatted JSON add the `pretty=true` param to format the response.\n
|
5
|
+
|
6
|
+
OpenAPI spec version: 0.9.0
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'spec_helper'
|
14
|
+
require 'json'
|
15
|
+
|
16
|
+
# Unit tests for Dkron::ExecutionsApi
|
17
|
+
# Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
|
18
|
+
# Please update as you see appropriate
|
19
|
+
describe 'ExecutionsApi' do
|
20
|
+
before do
|
21
|
+
# run before each test
|
22
|
+
@instance = Dkron::ExecutionsApi.new
|
23
|
+
end
|
24
|
+
|
25
|
+
after do
|
26
|
+
# run after each test
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'test an instance of ExecutionsApi' do
|
30
|
+
it 'should create an instact of ExecutionsApi' do
|
31
|
+
@instance.should be_a(Dkron::ExecutionsApi)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# unit tests for list_executions_by_job
|
36
|
+
#
|
37
|
+
# List executions.\n
|
38
|
+
# @param job_name The job that owns the executions to be fetched.
|
39
|
+
# @param [Hash] opts the optional parameters
|
40
|
+
# @return [Array<Execution>]
|
41
|
+
describe 'list_executions_by_job test' do
|
42
|
+
it "should work" do
|
43
|
+
# assertion here
|
44
|
+
# should be_a()
|
45
|
+
# should be_nil
|
46
|
+
# should ==
|
47
|
+
# should_not ==
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
=begin
|
2
|
+
Dkron REST API
|
3
|
+
|
4
|
+
You can communicate with Dkron using a RESTful JSON API over HTTP. Dkron nodes usually listen on port `8080` for API requests. All examples in this section assume that you've found a running leader at `localhost:8080`.\n\nDkron implements a RESTful JSON API over HTTP to communicate with software clients. Dkron listens in port `8080` by default. All examples in this section assume that you're using the default port.\n\nDefault API responses are unformatted JSON add the `pretty=true` param to format the response.\n
|
5
|
+
|
6
|
+
OpenAPI spec version: 0.9.0
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'spec_helper'
|
14
|
+
require 'json'
|
15
|
+
|
16
|
+
# Unit tests for Dkron::JobsApi
|
17
|
+
# Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
|
18
|
+
# Please update as you see appropriate
|
19
|
+
describe 'JobsApi' do
|
20
|
+
before do
|
21
|
+
# run before each test
|
22
|
+
@instance = Dkron::JobsApi.new
|
23
|
+
end
|
24
|
+
|
25
|
+
after do
|
26
|
+
# run after each test
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'test an instance of JobsApi' do
|
30
|
+
it 'should create an instact of JobsApi' do
|
31
|
+
@instance.should be_a(Dkron::JobsApi)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# unit tests for create_or_update_job
|
36
|
+
#
|
37
|
+
# Create or updates a new job.\n
|
38
|
+
# @param body Updated job object
|
39
|
+
# @param [Hash] opts the optional parameters
|
40
|
+
# @return [Job]
|
41
|
+
describe 'create_or_update_job test' do
|
42
|
+
it "should work" do
|
43
|
+
# assertion here
|
44
|
+
# should be_a()
|
45
|
+
# should be_nil
|
46
|
+
# should ==
|
47
|
+
# should_not ==
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# unit tests for delete_job
|
52
|
+
#
|
53
|
+
# Delete a job.\n
|
54
|
+
# @param job_name The job that needs to be deleted.
|
55
|
+
# @param [Hash] opts the optional parameters
|
56
|
+
# @return [Job]
|
57
|
+
describe 'delete_job test' do
|
58
|
+
it "should work" do
|
59
|
+
# assertion here
|
60
|
+
# should be_a()
|
61
|
+
# should be_nil
|
62
|
+
# should ==
|
63
|
+
# should_not ==
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# unit tests for get_jobs
|
68
|
+
#
|
69
|
+
# List jobs.\n
|
70
|
+
# @param [Hash] opts the optional parameters
|
71
|
+
# @return [Array<Job>]
|
72
|
+
describe 'get_jobs test' do
|
73
|
+
it "should work" do
|
74
|
+
# assertion here
|
75
|
+
# should be_a()
|
76
|
+
# should be_nil
|
77
|
+
# should ==
|
78
|
+
# should_not ==
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# unit tests for run_job
|
83
|
+
#
|
84
|
+
# Executes a job.\n
|
85
|
+
# @param job_name The job that needs to be run.
|
86
|
+
# @param [Hash] opts the optional parameters
|
87
|
+
# @return [Job]
|
88
|
+
describe 'run_job test' do
|
89
|
+
it "should work" do
|
90
|
+
# assertion here
|
91
|
+
# should be_a()
|
92
|
+
# should be_nil
|
93
|
+
# should ==
|
94
|
+
# should_not ==
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# unit tests for show_job_by_name
|
99
|
+
#
|
100
|
+
# Show a job.\n
|
101
|
+
# @param job_name The job that needs to be fetched.
|
102
|
+
# @param [Hash] opts the optional parameters
|
103
|
+
# @return [Job]
|
104
|
+
describe 'show_job_by_name test' do
|
105
|
+
it "should work" do
|
106
|
+
# assertion here
|
107
|
+
# should be_a()
|
108
|
+
# should be_nil
|
109
|
+
# should ==
|
110
|
+
# should_not ==
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
=begin
|
2
|
+
Dkron REST API
|
3
|
+
|
4
|
+
You can communicate with Dkron using a RESTful JSON API over HTTP. Dkron nodes usually listen on port `8080` for API requests. All examples in this section assume that you've found a running leader at `localhost:8080`.\n\nDkron implements a RESTful JSON API over HTTP to communicate with software clients. Dkron listens in port `8080` by default. All examples in this section assume that you're using the default port.\n\nDefault API responses are unformatted JSON add the `pretty=true` param to format the response.\n
|
5
|
+
|
6
|
+
OpenAPI spec version: 0.7.2
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'spec_helper'
|
14
|
+
require 'json'
|
15
|
+
|
16
|
+
# Unit tests for Dkron::MainApi
|
17
|
+
# Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
|
18
|
+
# Please update as you see appropriate
|
19
|
+
describe 'MainApi' do
|
20
|
+
before do
|
21
|
+
# run before each test
|
22
|
+
@instance = Dkron::MainApi.new
|
23
|
+
end
|
24
|
+
|
25
|
+
after do
|
26
|
+
# run after each test
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'test an instance of MainApi' do
|
30
|
+
it 'should create an instact of MainApi' do
|
31
|
+
@instance.should be_a(Dkron::MainApi)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# unit tests for get_leader
|
36
|
+
#
|
37
|
+
# List members.\n
|
38
|
+
# @param [Hash] opts the optional parameters
|
39
|
+
# @return [Member]
|
40
|
+
describe 'get_leader test' do
|
41
|
+
it "should work" do
|
42
|
+
# assertion here
|
43
|
+
# should be_a()
|
44
|
+
# should be_nil
|
45
|
+
# should ==
|
46
|
+
# should_not ==
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# unit tests for status
|
51
|
+
#
|
52
|
+
# Gets `Status` object.\n
|
53
|
+
# @param [Hash] opts the optional parameters
|
54
|
+
# @return [InlineResponse200]
|
55
|
+
describe 'status test' do
|
56
|
+
it "should work" do
|
57
|
+
# assertion here
|
58
|
+
# should be_a()
|
59
|
+
# should be_nil
|
60
|
+
# should ==
|
61
|
+
# should_not ==
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
=begin
|
2
|
+
Dkron REST API
|
3
|
+
|
4
|
+
You can communicate with Dkron using a RESTful JSON API over HTTP. Dkron nodes usually listen on port `8080` for API requests. All examples in this section assume that you've found a running leader at `localhost:8080`.\n\nDkron implements a RESTful JSON API over HTTP to communicate with software clients. Dkron listens in port `8080` by default. All examples in this section assume that you're using the default port.\n\nDefault API responses are unformatted JSON add the `pretty=true` param to format the response.\n
|
5
|
+
|
6
|
+
OpenAPI spec version: 0.9.0
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'spec_helper'
|
14
|
+
require 'json'
|
15
|
+
|
16
|
+
# Unit tests for Dkron::MembersApi
|
17
|
+
# Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
|
18
|
+
# Please update as you see appropriate
|
19
|
+
describe 'MembersApi' do
|
20
|
+
before do
|
21
|
+
# run before each test
|
22
|
+
@instance = Dkron::MembersApi.new
|
23
|
+
end
|
24
|
+
|
25
|
+
after do
|
26
|
+
# run after each test
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'test an instance of MembersApi' do
|
30
|
+
it 'should create an instact of MembersApi' do
|
31
|
+
@instance.should be_a(Dkron::MembersApi)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# unit tests for get_member
|
36
|
+
#
|
37
|
+
# List members.\n
|
38
|
+
# @param [Hash] opts the optional parameters
|
39
|
+
# @return [Array<Member>]
|
40
|
+
describe 'get_member test' do
|
41
|
+
it "should work" do
|
42
|
+
# assertion here
|
43
|
+
# should be_a()
|
44
|
+
# should be_nil
|
45
|
+
# should ==
|
46
|
+
# should_not ==
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,237 @@
|
|
1
|
+
=begin
|
2
|
+
#Dkron REST API
|
3
|
+
|
4
|
+
#You can communicate with Dkron using a RESTful JSON API over HTTP. Dkron nodes usually listen on port `8080` for API requests. All examples in this section assume that you've found a running leader at `localhost:8080`. Dkron implements a RESTful JSON API over HTTP to communicate with software clients. Dkron listens in port `8080` by default. All examples in this section assume that you're using the default port. Default API responses are unformatted JSON add the `pretty=true` param to format the response.
|
5
|
+
|
6
|
+
OpenAPI spec version: 0.9.0
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
|
10
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
11
|
+
you may not use this file except in compliance with the License.
|
12
|
+
You may obtain a copy of the License at
|
13
|
+
|
14
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
15
|
+
|
16
|
+
Unless required by applicable law or agreed to in writing, software
|
17
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
18
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19
|
+
See the License for the specific language governing permissions and
|
20
|
+
limitations under the License.
|
21
|
+
|
22
|
+
=end
|
23
|
+
|
24
|
+
require 'spec_helper'
|
25
|
+
|
26
|
+
describe Dkron::ApiClient do
|
27
|
+
context 'initialization' do
|
28
|
+
context 'URL stuff' do
|
29
|
+
context 'host' do
|
30
|
+
it 'removes http from host' do
|
31
|
+
Dkron.configure { |c| c.host = 'http://example.com' }
|
32
|
+
expect(Dkron::Configuration.default.host).to eq('example.com')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'removes https from host' do
|
36
|
+
Dkron.configure { |c| c.host = 'https://wookiee.com' }
|
37
|
+
expect(Dkron::ApiClient.default.config.host).to eq('wookiee.com')
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'removes trailing path from host' do
|
41
|
+
Dkron.configure { |c| c.host = 'hobo.com/v4' }
|
42
|
+
expect(Dkron::Configuration.default.host).to eq('hobo.com')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'base_path' do
|
47
|
+
it "prepends a slash to base_path" do
|
48
|
+
Dkron.configure { |c| c.base_path = 'v4/dog' }
|
49
|
+
expect(Dkron::Configuration.default.base_path).to eq('/v4/dog')
|
50
|
+
end
|
51
|
+
|
52
|
+
it "doesn't prepend a slash if one is already there" do
|
53
|
+
Dkron.configure { |c| c.base_path = '/v4/dog' }
|
54
|
+
expect(Dkron::Configuration.default.base_path).to eq('/v4/dog')
|
55
|
+
end
|
56
|
+
|
57
|
+
it "ends up as a blank string if nil" do
|
58
|
+
Dkron.configure { |c| c.base_path = nil }
|
59
|
+
expect(Dkron::Configuration.default.base_path).to eq('')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "params_encoding in #build_request" do
|
66
|
+
let(:config) { Dkron::Configuration.new }
|
67
|
+
let(:api_client) { Dkron::ApiClient.new(config) }
|
68
|
+
|
69
|
+
it "defaults to nil" do
|
70
|
+
expect(Dkron::Configuration.default.params_encoding).to eq(nil)
|
71
|
+
expect(config.params_encoding).to eq(nil)
|
72
|
+
|
73
|
+
request = api_client.build_request(:get, '/test')
|
74
|
+
expect(request.options[:params_encoding]).to eq(nil)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "can be customized" do
|
78
|
+
config.params_encoding = :multi
|
79
|
+
request = api_client.build_request(:get, '/test')
|
80
|
+
expect(request.options[:params_encoding]).to eq(:multi)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "timeout in #build_request" do
|
85
|
+
let(:config) { Dkron::Configuration.new }
|
86
|
+
let(:api_client) { Dkron::ApiClient.new(config) }
|
87
|
+
|
88
|
+
it "defaults to 0" do
|
89
|
+
expect(Dkron::Configuration.default.timeout).to eq(0)
|
90
|
+
expect(config.timeout).to eq(0)
|
91
|
+
|
92
|
+
request = api_client.build_request(:get, '/test')
|
93
|
+
expect(request.options[:timeout]).to eq(0)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "can be customized" do
|
97
|
+
config.timeout = 100
|
98
|
+
request = api_client.build_request(:get, '/test')
|
99
|
+
expect(request.options[:timeout]).to eq(100)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "#deserialize" do
|
104
|
+
it "handles Array<Integer>" do
|
105
|
+
api_client = Dkron::ApiClient.new
|
106
|
+
headers = {'Content-Type' => 'application/json'}
|
107
|
+
response = double('response', headers: headers, body: '[12, 34]')
|
108
|
+
data = api_client.deserialize(response, 'Array<Integer>')
|
109
|
+
expect(data).to be_instance_of(Array)
|
110
|
+
expect(data).to eq([12, 34])
|
111
|
+
end
|
112
|
+
|
113
|
+
it "handles Array<Array<Integer>>" do
|
114
|
+
api_client = Dkron::ApiClient.new
|
115
|
+
headers = {'Content-Type' => 'application/json'}
|
116
|
+
response = double('response', headers: headers, body: '[[12, 34], [56]]')
|
117
|
+
data = api_client.deserialize(response, 'Array<Array<Integer>>')
|
118
|
+
expect(data).to be_instance_of(Array)
|
119
|
+
expect(data).to eq([[12, 34], [56]])
|
120
|
+
end
|
121
|
+
|
122
|
+
it "handles Hash<String, String>" do
|
123
|
+
api_client = Dkron::ApiClient.new
|
124
|
+
headers = {'Content-Type' => 'application/json'}
|
125
|
+
response = double('response', headers: headers, body: '{"message": "Hello"}')
|
126
|
+
data = api_client.deserialize(response, 'Hash<String, String>')
|
127
|
+
expect(data).to be_instance_of(Hash)
|
128
|
+
expect(data).to eq({:message => 'Hello'})
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "#object_to_hash" do
|
133
|
+
it "ignores nils and includes empty arrays" do
|
134
|
+
# uncomment below to test object_to_hash for model
|
135
|
+
#api_client = Dkron::ApiClient.new
|
136
|
+
#_model = Dkron::ModelName.new
|
137
|
+
# update the model attribute below
|
138
|
+
#_model.id = 1
|
139
|
+
# update the expected value (hash) below
|
140
|
+
#expected = {id: 1, name: '', tags: []}
|
141
|
+
#expect(api_client.object_to_hash(_model)).to eq(expected)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "#build_collection_param" do
|
146
|
+
let(:param) { ['aa', 'bb', 'cc'] }
|
147
|
+
let(:api_client) { Dkron::ApiClient.new }
|
148
|
+
|
149
|
+
it "works for csv" do
|
150
|
+
expect(api_client.build_collection_param(param, :csv)).to eq('aa,bb,cc')
|
151
|
+
end
|
152
|
+
|
153
|
+
it "works for ssv" do
|
154
|
+
expect(api_client.build_collection_param(param, :ssv)).to eq('aa bb cc')
|
155
|
+
end
|
156
|
+
|
157
|
+
it "works for tsv" do
|
158
|
+
expect(api_client.build_collection_param(param, :tsv)).to eq("aa\tbb\tcc")
|
159
|
+
end
|
160
|
+
|
161
|
+
it "works for pipes" do
|
162
|
+
expect(api_client.build_collection_param(param, :pipes)).to eq('aa|bb|cc')
|
163
|
+
end
|
164
|
+
|
165
|
+
it "works for multi" do
|
166
|
+
expect(api_client.build_collection_param(param, :multi)).to eq(['aa', 'bb', 'cc'])
|
167
|
+
end
|
168
|
+
|
169
|
+
it "fails for invalid collection format" do
|
170
|
+
expect(proc { api_client.build_collection_param(param, :INVALID) }).to raise_error(RuntimeError, 'unknown collection format: :INVALID')
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
describe "#json_mime?" do
|
175
|
+
let(:api_client) { Dkron::ApiClient.new }
|
176
|
+
|
177
|
+
it "works" do
|
178
|
+
expect(api_client.json_mime?(nil)).to eq false
|
179
|
+
expect(api_client.json_mime?('')).to eq false
|
180
|
+
|
181
|
+
expect(api_client.json_mime?('application/json')).to eq true
|
182
|
+
expect(api_client.json_mime?('application/json; charset=UTF8')).to eq true
|
183
|
+
expect(api_client.json_mime?('APPLICATION/JSON')).to eq true
|
184
|
+
|
185
|
+
expect(api_client.json_mime?('application/xml')).to eq false
|
186
|
+
expect(api_client.json_mime?('text/plain')).to eq false
|
187
|
+
expect(api_client.json_mime?('application/jsonp')).to eq false
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
describe "#select_header_accept" do
|
192
|
+
let(:api_client) { Dkron::ApiClient.new }
|
193
|
+
|
194
|
+
it "works" do
|
195
|
+
expect(api_client.select_header_accept(nil)).to be_nil
|
196
|
+
expect(api_client.select_header_accept([])).to be_nil
|
197
|
+
|
198
|
+
expect(api_client.select_header_accept(['application/json'])).to eq('application/json')
|
199
|
+
expect(api_client.select_header_accept(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8')
|
200
|
+
expect(api_client.select_header_accept(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON')
|
201
|
+
|
202
|
+
expect(api_client.select_header_accept(['application/xml'])).to eq('application/xml')
|
203
|
+
expect(api_client.select_header_accept(['text/html', 'application/xml'])).to eq('text/html,application/xml')
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
describe "#select_header_content_type" do
|
208
|
+
let(:api_client) { Dkron::ApiClient.new }
|
209
|
+
|
210
|
+
it "works" do
|
211
|
+
expect(api_client.select_header_content_type(nil)).to eq('application/json')
|
212
|
+
expect(api_client.select_header_content_type([])).to eq('application/json')
|
213
|
+
|
214
|
+
expect(api_client.select_header_content_type(['application/json'])).to eq('application/json')
|
215
|
+
expect(api_client.select_header_content_type(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8')
|
216
|
+
expect(api_client.select_header_content_type(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON')
|
217
|
+
expect(api_client.select_header_content_type(['application/xml'])).to eq('application/xml')
|
218
|
+
expect(api_client.select_header_content_type(['text/plain', 'application/xml'])).to eq('text/plain')
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
describe "#sanitize_filename" do
|
223
|
+
let(:api_client) { Dkron::ApiClient.new }
|
224
|
+
|
225
|
+
it "works" do
|
226
|
+
expect(api_client.sanitize_filename('sun')).to eq('sun')
|
227
|
+
expect(api_client.sanitize_filename('sun.gif')).to eq('sun.gif')
|
228
|
+
expect(api_client.sanitize_filename('../sun.gif')).to eq('sun.gif')
|
229
|
+
expect(api_client.sanitize_filename('/var/tmp/sun.gif')).to eq('sun.gif')
|
230
|
+
expect(api_client.sanitize_filename('./sun.gif')).to eq('sun.gif')
|
231
|
+
expect(api_client.sanitize_filename('..\sun.gif')).to eq('sun.gif')
|
232
|
+
expect(api_client.sanitize_filename('\var\tmp\sun.gif')).to eq('sun.gif')
|
233
|
+
expect(api_client.sanitize_filename('c:\var\tmp\sun.gif')).to eq('sun.gif')
|
234
|
+
expect(api_client.sanitize_filename('.\sun.gif')).to eq('sun.gif')
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|