harbor2_client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +7 -0
  3. data/README.md +186 -0
  4. data/Rakefile +8 -0
  5. data/docs/AdditionLink.md +9 -0
  6. data/docs/AdditionLinks.md +7 -0
  7. data/docs/Annotations.md +7 -0
  8. data/docs/Artifact.md +25 -0
  9. data/docs/ArtifactApi.md +694 -0
  10. data/docs/AuditLog.md +13 -0
  11. data/docs/AuditlogApi.md +69 -0
  12. data/docs/CVEAllowlist.md +13 -0
  13. data/docs/CVEAllowlistItem.md +8 -0
  14. data/docs/Error.md +9 -0
  15. data/docs/Errors.md +8 -0
  16. data/docs/Execution.md +17 -0
  17. data/docs/ExtraAttrs.md +7 -0
  18. data/docs/Icon.md +9 -0
  19. data/docs/IconApi.md +66 -0
  20. data/docs/Instance.md +19 -0
  21. data/docs/Label.md +15 -0
  22. data/docs/Metadata.md +13 -0
  23. data/docs/Metrics.md +14 -0
  24. data/docs/NativeReportSummary.md +15 -0
  25. data/docs/Platform.md +12 -0
  26. data/docs/PreheatApi.md +1176 -0
  27. data/docs/PreheatPolicy.md +18 -0
  28. data/docs/Project.md +22 -0
  29. data/docs/ProjectApi.md +542 -0
  30. data/docs/ProjectDeletable.md +9 -0
  31. data/docs/ProjectMetadata.md +14 -0
  32. data/docs/ProjectReq.md +13 -0
  33. data/docs/ProjectSummary.md +16 -0
  34. data/docs/ProjectSummaryQuota.md +9 -0
  35. data/docs/ProviderUnderProject.md +11 -0
  36. data/docs/Reference.md +13 -0
  37. data/docs/Registry.md +17 -0
  38. data/docs/RegistryCredential.md +10 -0
  39. data/docs/Repository.md +15 -0
  40. data/docs/RepositoryApi.md +256 -0
  41. data/docs/ResourceList.md +7 -0
  42. data/docs/ScanApi.md +138 -0
  43. data/docs/ScanOverview.md +7 -0
  44. data/docs/Tag.md +15 -0
  45. data/docs/Task.md +17 -0
  46. data/docs/VulnerabilitySummary.md +10 -0
  47. data/git_push.sh +55 -0
  48. data/harbor2_client.gemspec +46 -0
  49. data/lib/harbor2_client.rb +81 -0
  50. data/lib/harbor2_client/api/artifact_api.rb +848 -0
  51. data/lib/harbor2_client/api/auditlog_api.rb +91 -0
  52. data/lib/harbor2_client/api/icon_api.rb +84 -0
  53. data/lib/harbor2_client/api/preheat_api.rb +1327 -0
  54. data/lib/harbor2_client/api/project_api.rb +601 -0
  55. data/lib/harbor2_client/api/repository_api.rb +302 -0
  56. data/lib/harbor2_client/api/scan_api.rb +174 -0
  57. data/lib/harbor2_client/api_client.rb +391 -0
  58. data/lib/harbor2_client/api_error.rb +38 -0
  59. data/lib/harbor2_client/configuration.rb +209 -0
  60. data/lib/harbor2_client/models/addition_link.rb +195 -0
  61. data/lib/harbor2_client/models/addition_links.rb +175 -0
  62. data/lib/harbor2_client/models/annotations.rb +175 -0
  63. data/lib/harbor2_client/models/artifact.rb +355 -0
  64. data/lib/harbor2_client/models/audit_log.rb +235 -0
  65. data/lib/harbor2_client/models/cve_allowlist.rb +237 -0
  66. data/lib/harbor2_client/models/cve_allowlist_item.rb +186 -0
  67. data/lib/harbor2_client/models/error.rb +196 -0
  68. data/lib/harbor2_client/models/errors.rb +187 -0
  69. data/lib/harbor2_client/models/execution.rb +273 -0
  70. data/lib/harbor2_client/models/extra_attrs.rb +175 -0
  71. data/lib/harbor2_client/models/icon.rb +195 -0
  72. data/lib/harbor2_client/models/instance.rb +297 -0
  73. data/lib/harbor2_client/models/label.rb +255 -0
  74. data/lib/harbor2_client/models/metadata.rb +237 -0
  75. data/lib/harbor2_client/models/metrics.rb +245 -0
  76. data/lib/harbor2_client/models/native_report_summary.rb +255 -0
  77. data/lib/harbor2_client/models/platform.rb +227 -0
  78. data/lib/harbor2_client/models/preheat_policy.rb +285 -0
  79. data/lib/harbor2_client/models/project.rb +327 -0
  80. data/lib/harbor2_client/models/project_deletable.rb +195 -0
  81. data/lib/harbor2_client/models/project_metadata.rb +245 -0
  82. data/lib/harbor2_client/models/project_req.rb +235 -0
  83. data/lib/harbor2_client/models/project_summary.rb +263 -0
  84. data/lib/harbor2_client/models/project_summary_quota.rb +195 -0
  85. data/lib/harbor2_client/models/provider_under_project.rb +211 -0
  86. data/lib/harbor2_client/models/reference.rb +235 -0
  87. data/lib/harbor2_client/models/registry.rb +274 -0
  88. data/lib/harbor2_client/models/registry_credential.rb +205 -0
  89. data/lib/harbor2_client/models/repository.rb +255 -0
  90. data/lib/harbor2_client/models/resource_list.rb +175 -0
  91. data/lib/harbor2_client/models/scan_overview.rb +176 -0
  92. data/lib/harbor2_client/models/tag.rb +255 -0
  93. data/lib/harbor2_client/models/task.rb +274 -0
  94. data/lib/harbor2_client/models/vulnerability_summary.rb +208 -0
  95. data/lib/harbor2_client/version.rb +15 -0
  96. data/spec/api/artifact_api_spec.rb +209 -0
  97. data/spec/api/auditlog_api_spec.rb +50 -0
  98. data/spec/api/icon_api_spec.rb +48 -0
  99. data/spec/api/preheat_api_spec.rb +311 -0
  100. data/spec/api/project_api_spec.rb +160 -0
  101. data/spec/api/repository_api_spec.rb +94 -0
  102. data/spec/api/scan_api_spec.rb +66 -0
  103. data/spec/api_client_spec.rb +243 -0
  104. data/spec/configuration_spec.rb +42 -0
  105. data/spec/models/addition_link_spec.rb +47 -0
  106. data/spec/models/addition_links_spec.rb +35 -0
  107. data/spec/models/annotations_spec.rb +35 -0
  108. data/spec/models/artifact_spec.rb +143 -0
  109. data/spec/models/audit_log_spec.rb +71 -0
  110. data/spec/models/cve_allowlist_item_spec.rb +41 -0
  111. data/spec/models/cve_allowlist_spec.rb +71 -0
  112. data/spec/models/error_spec.rb +47 -0
  113. data/spec/models/errors_spec.rb +41 -0
  114. data/spec/models/execution_spec.rb +95 -0
  115. data/spec/models/extra_attrs_spec.rb +35 -0
  116. data/spec/models/icon_spec.rb +47 -0
  117. data/spec/models/instance_spec.rb +107 -0
  118. data/spec/models/label_spec.rb +83 -0
  119. data/spec/models/metadata_spec.rb +71 -0
  120. data/spec/models/metrics_spec.rb +77 -0
  121. data/spec/models/native_report_summary_spec.rb +83 -0
  122. data/spec/models/platform_spec.rb +65 -0
  123. data/spec/models/preheat_policy_spec.rb +101 -0
  124. data/spec/models/project_deletable_spec.rb +47 -0
  125. data/spec/models/project_metadata_spec.rb +77 -0
  126. data/spec/models/project_req_spec.rb +71 -0
  127. data/spec/models/project_spec.rb +125 -0
  128. data/spec/models/project_summary_quota_spec.rb +47 -0
  129. data/spec/models/project_summary_spec.rb +89 -0
  130. data/spec/models/provider_under_project_spec.rb +59 -0
  131. data/spec/models/reference_spec.rb +71 -0
  132. data/spec/models/registry_credential_spec.rb +53 -0
  133. data/spec/models/registry_spec.rb +95 -0
  134. data/spec/models/repository_spec.rb +83 -0
  135. data/spec/models/resource_list_spec.rb +35 -0
  136. data/spec/models/scan_overview_spec.rb +35 -0
  137. data/spec/models/tag_spec.rb +83 -0
  138. data/spec/models/task_spec.rb +95 -0
  139. data/spec/models/vulnerability_summary_spec.rb +53 -0
  140. data/spec/spec_helper.rb +111 -0
  141. metadata +428 -0
@@ -0,0 +1,160 @@
1
+ =begin
2
+ #Harbor API
3
+
4
+ #These APIs provide services for manipulating Harbor project.
5
+
6
+ OpenAPI spec version: 2.0
7
+
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 2.4.17
10
+
11
+ =end
12
+
13
+ require 'spec_helper'
14
+ require 'json'
15
+
16
+ # Unit tests for Harbor2Client::ProjectApi
17
+ # Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
18
+ # Please update as you see appropriate
19
+ describe 'ProjectApi' do
20
+ before do
21
+ # run before each test
22
+ @instance = Harbor2Client::ProjectApi.new
23
+ end
24
+
25
+ after do
26
+ # run after each test
27
+ end
28
+
29
+ describe 'test an instance of ProjectApi' do
30
+ it 'should create an instance of ProjectApi' do
31
+ expect(@instance).to be_instance_of(Harbor2Client::ProjectApi)
32
+ end
33
+ end
34
+
35
+ # unit tests for create_project
36
+ # Create a new project.
37
+ # This endpoint is for user to create a new project.
38
+ # @param project New created project.
39
+ # @param [Hash] opts the optional parameters
40
+ # @option opts [String] :x_request_id An unique ID for the request
41
+ # @return [nil]
42
+ describe 'create_project test' do
43
+ it 'should work' do
44
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
45
+ end
46
+ end
47
+
48
+ # unit tests for delete_project
49
+ # Delete project by projectID
50
+ # This endpoint is aimed to delete project by project ID.
51
+ # @param project_id The ID of the project
52
+ # @param [Hash] opts the optional parameters
53
+ # @option opts [String] :x_request_id An unique ID for the request
54
+ # @return [nil]
55
+ describe 'delete_project test' do
56
+ it 'should work' do
57
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
58
+ end
59
+ end
60
+
61
+ # unit tests for get_logs
62
+ # Get recent logs of the projects
63
+ # Get recent logs of the projects
64
+ # @param project_name The name of the project
65
+ # @param [Hash] opts the optional parameters
66
+ # @option opts [String] :x_request_id An unique ID for the request
67
+ # @option opts [String] :q Query string to query resources. Supported query patterns are \"exact match(k=v)\", \"fuzzy match(k=~v)\", \"range(k=[min~max])\", \"list with union releationship(k={v1 v2 v3})\" and \"list with intersetion relationship(k=(v1 v2 v3))\". The value of range and list can be string(enclosed by \" or '), integer or time(in format \"2020-04-09 02:36:00\"). All of these query patterns should be put in the query string \"q=xxx\" and splitted by \",\". e.g. q=k1=v1,k2=~v2,k3=[min~max]
68
+ # @option opts [Integer] :page The page number
69
+ # @option opts [Integer] :page_size The size of per page
70
+ # @return [Array<AuditLog>]
71
+ describe 'get_logs test' do
72
+ it 'should work' do
73
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
74
+ end
75
+ end
76
+
77
+ # unit tests for get_project
78
+ # Return specific project detail information
79
+ # This endpoint returns specific project information by project ID.
80
+ # @param project_id The ID of the project
81
+ # @param [Hash] opts the optional parameters
82
+ # @option opts [String] :x_request_id An unique ID for the request
83
+ # @return [Project]
84
+ describe 'get_project test' do
85
+ it 'should work' do
86
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
87
+ end
88
+ end
89
+
90
+ # unit tests for get_project_deletable
91
+ # Get the deletable status of the project
92
+ # Get the deletable status of the project
93
+ # @param project_id The ID of the project
94
+ # @param [Hash] opts the optional parameters
95
+ # @option opts [String] :x_request_id An unique ID for the request
96
+ # @return [ProjectDeletable]
97
+ describe 'get_project_deletable test' do
98
+ it 'should work' do
99
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
100
+ end
101
+ end
102
+
103
+ # unit tests for get_project_summary
104
+ # Get summary of the project.
105
+ # Get summary of the project.
106
+ # @param project_id The ID of the project
107
+ # @param [Hash] opts the optional parameters
108
+ # @option opts [String] :x_request_id An unique ID for the request
109
+ # @return [ProjectSummary]
110
+ describe 'get_project_summary test' do
111
+ it 'should work' do
112
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
113
+ end
114
+ end
115
+
116
+ # unit tests for head_project
117
+ # Check if the project name user provided already exists.
118
+ # This endpoint is used to check if the project name provided already exist.
119
+ # @param project_name Project name for checking exists.
120
+ # @param [Hash] opts the optional parameters
121
+ # @option opts [String] :x_request_id An unique ID for the request
122
+ # @return [nil]
123
+ describe 'head_project test' do
124
+ it 'should work' do
125
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
126
+ end
127
+ end
128
+
129
+ # unit tests for list_projects
130
+ # List projects
131
+ # This endpoint returns projects created by Harbor.
132
+ # @param [Hash] opts the optional parameters
133
+ # @option opts [String] :x_request_id An unique ID for the request
134
+ # @option opts [Integer] :page The page number
135
+ # @option opts [Integer] :page_size The size of per page
136
+ # @option opts [String] :name The name of project.
137
+ # @option opts [BOOLEAN] :public The project is public or private.
138
+ # @option opts [String] :owner The name of project owner.
139
+ # @return [Array<Project>]
140
+ describe 'list_projects test' do
141
+ it 'should work' do
142
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
143
+ end
144
+ end
145
+
146
+ # unit tests for update_project
147
+ # Update properties for a selected project.
148
+ # This endpoint is aimed to update the properties of a project.
149
+ # @param project_id The ID of the project
150
+ # @param project Updates of project.
151
+ # @param [Hash] opts the optional parameters
152
+ # @option opts [String] :x_request_id An unique ID for the request
153
+ # @return [nil]
154
+ describe 'update_project test' do
155
+ it 'should work' do
156
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
157
+ end
158
+ end
159
+
160
+ end
@@ -0,0 +1,94 @@
1
+ =begin
2
+ #Harbor API
3
+
4
+ #These APIs provide services for manipulating Harbor project.
5
+
6
+ OpenAPI spec version: 2.0
7
+
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 2.4.17
10
+
11
+ =end
12
+
13
+ require 'spec_helper'
14
+ require 'json'
15
+
16
+ # Unit tests for Harbor2Client::RepositoryApi
17
+ # Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
18
+ # Please update as you see appropriate
19
+ describe 'RepositoryApi' do
20
+ before do
21
+ # run before each test
22
+ @instance = Harbor2Client::RepositoryApi.new
23
+ end
24
+
25
+ after do
26
+ # run after each test
27
+ end
28
+
29
+ describe 'test an instance of RepositoryApi' do
30
+ it 'should create an instance of RepositoryApi' do
31
+ expect(@instance).to be_instance_of(Harbor2Client::RepositoryApi)
32
+ end
33
+ end
34
+
35
+ # unit tests for delete_repository
36
+ # Delete repository
37
+ # Delete the repository specified by name
38
+ # @param project_name The name of the project
39
+ # @param repository_name The name of the repository. If it contains slash, encode it with URL encoding. e.g. a/b -&gt; a%252Fb
40
+ # @param [Hash] opts the optional parameters
41
+ # @option opts [String] :x_request_id An unique ID for the request
42
+ # @return [nil]
43
+ describe 'delete_repository test' do
44
+ it 'should work' do
45
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
46
+ end
47
+ end
48
+
49
+ # unit tests for get_repository
50
+ # Get repository
51
+ # Get the repository specified by name
52
+ # @param project_name The name of the project
53
+ # @param repository_name The name of the repository. If it contains slash, encode it with URL encoding. e.g. a/b -&gt; a%252Fb
54
+ # @param [Hash] opts the optional parameters
55
+ # @option opts [String] :x_request_id An unique ID for the request
56
+ # @return [Repository]
57
+ describe 'get_repository test' do
58
+ it 'should work' do
59
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
60
+ end
61
+ end
62
+
63
+ # unit tests for list_repositories
64
+ # List repositories
65
+ # List repositories of the specified project
66
+ # @param project_name The name of the project
67
+ # @param [Hash] opts the optional parameters
68
+ # @option opts [String] :x_request_id An unique ID for the request
69
+ # @option opts [String] :q Query string to query resources. Supported query patterns are \&quot;exact match(k&#x3D;v)\&quot;, \&quot;fuzzy match(k&#x3D;~v)\&quot;, \&quot;range(k&#x3D;[min~max])\&quot;, \&quot;list with union releationship(k&#x3D;{v1 v2 v3})\&quot; and \&quot;list with intersetion relationship(k&#x3D;(v1 v2 v3))\&quot;. The value of range and list can be string(enclosed by \&quot; or &#39;), integer or time(in format \&quot;2020-04-09 02:36:00\&quot;). All of these query patterns should be put in the query string \&quot;q&#x3D;xxx\&quot; and splitted by \&quot;,\&quot;. e.g. q&#x3D;k1&#x3D;v1,k2&#x3D;~v2,k3&#x3D;[min~max]
70
+ # @option opts [Integer] :page The page number
71
+ # @option opts [Integer] :page_size The size of per page
72
+ # @return [Array<Repository>]
73
+ describe 'list_repositories test' do
74
+ it 'should work' do
75
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
76
+ end
77
+ end
78
+
79
+ # unit tests for update_repository
80
+ # Update repository
81
+ # Update the repository specified by name
82
+ # @param project_name The name of the project
83
+ # @param repository_name The name of the repository. If it contains slash, encode it with URL encoding. e.g. a/b -&gt; a%252Fb
84
+ # @param repository The JSON object of repository.
85
+ # @param [Hash] opts the optional parameters
86
+ # @option opts [String] :x_request_id An unique ID for the request
87
+ # @return [nil]
88
+ describe 'update_repository test' do
89
+ it 'should work' do
90
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
91
+ end
92
+ end
93
+
94
+ end
@@ -0,0 +1,66 @@
1
+ =begin
2
+ #Harbor API
3
+
4
+ #These APIs provide services for manipulating Harbor project.
5
+
6
+ OpenAPI spec version: 2.0
7
+
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 2.4.17
10
+
11
+ =end
12
+
13
+ require 'spec_helper'
14
+ require 'json'
15
+
16
+ # Unit tests for Harbor2Client::ScanApi
17
+ # Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
18
+ # Please update as you see appropriate
19
+ describe 'ScanApi' do
20
+ before do
21
+ # run before each test
22
+ @instance = Harbor2Client::ScanApi.new
23
+ end
24
+
25
+ after do
26
+ # run after each test
27
+ end
28
+
29
+ describe 'test an instance of ScanApi' do
30
+ it 'should create an instance of ScanApi' do
31
+ expect(@instance).to be_instance_of(Harbor2Client::ScanApi)
32
+ end
33
+ end
34
+
35
+ # unit tests for get_report_log
36
+ # Get the log of the scan report
37
+ # Get the log of the scan report
38
+ # @param project_name The name of the project
39
+ # @param repository_name The name of the repository. If it contains slash, encode it with URL encoding. e.g. a/b -&gt; a%252Fb
40
+ # @param reference The reference of the artifact, can be digest or tag
41
+ # @param report_id The report id to get the log
42
+ # @param [Hash] opts the optional parameters
43
+ # @option opts [String] :x_request_id An unique ID for the request
44
+ # @return [String]
45
+ describe 'get_report_log test' do
46
+ it 'should work' do
47
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
48
+ end
49
+ end
50
+
51
+ # unit tests for scan_artifact
52
+ # Scan the artifact
53
+ # Scan the specified artifact
54
+ # @param project_name The name of the project
55
+ # @param repository_name The name of the repository. If it contains slash, encode it with URL encoding. e.g. a/b -&gt; a%252Fb
56
+ # @param reference The reference of the artifact, can be digest or tag
57
+ # @param [Hash] opts the optional parameters
58
+ # @option opts [String] :x_request_id An unique ID for the request
59
+ # @return [nil]
60
+ describe 'scan_artifact test' do
61
+ it 'should work' do
62
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
63
+ end
64
+ end
65
+
66
+ end
@@ -0,0 +1,243 @@
1
+ =begin
2
+ #Harbor API
3
+
4
+ #These APIs provide services for manipulating Harbor project.
5
+
6
+ OpenAPI spec version: 2.0
7
+
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 2.4.17
10
+
11
+ =end
12
+
13
+ require 'spec_helper'
14
+
15
+ describe Harbor2Client::ApiClient do
16
+ context 'initialization' do
17
+ context 'URL stuff' do
18
+ context 'host' do
19
+ it 'removes http from host' do
20
+ Harbor2Client.configure { |c| c.host = 'http://example.com' }
21
+ expect(Harbor2Client::Configuration.default.host).to eq('example.com')
22
+ end
23
+
24
+ it 'removes https from host' do
25
+ Harbor2Client.configure { |c| c.host = 'https://wookiee.com' }
26
+ expect(Harbor2Client::ApiClient.default.config.host).to eq('wookiee.com')
27
+ end
28
+
29
+ it 'removes trailing path from host' do
30
+ Harbor2Client.configure { |c| c.host = 'hobo.com/v4' }
31
+ expect(Harbor2Client::Configuration.default.host).to eq('hobo.com')
32
+ end
33
+ end
34
+
35
+ context 'base_path' do
36
+ it "prepends a slash to base_path" do
37
+ Harbor2Client.configure { |c| c.base_path = 'v4/dog' }
38
+ expect(Harbor2Client::Configuration.default.base_path).to eq('/v4/dog')
39
+ end
40
+
41
+ it "doesn't prepend a slash if one is already there" do
42
+ Harbor2Client.configure { |c| c.base_path = '/v4/dog' }
43
+ expect(Harbor2Client::Configuration.default.base_path).to eq('/v4/dog')
44
+ end
45
+
46
+ it "ends up as a blank string if nil" do
47
+ Harbor2Client.configure { |c| c.base_path = nil }
48
+ expect(Harbor2Client::Configuration.default.base_path).to eq('')
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ describe 'params_encoding in #build_request' do
55
+ let(:config) { Harbor2Client::Configuration.new }
56
+ let(:api_client) { Harbor2Client::ApiClient.new(config) }
57
+
58
+ it 'defaults to nil' do
59
+ expect(Harbor2Client::Configuration.default.params_encoding).to eq(nil)
60
+ expect(config.params_encoding).to eq(nil)
61
+
62
+ request = api_client.build_request(:get, '/test')
63
+ expect(request.options[:params_encoding]).to eq(nil)
64
+ end
65
+
66
+ it 'can be customized' do
67
+ config.params_encoding = :multi
68
+ request = api_client.build_request(:get, '/test')
69
+ expect(request.options[:params_encoding]).to eq(:multi)
70
+ end
71
+ end
72
+
73
+ describe 'timeout in #build_request' do
74
+ let(:config) { Harbor2Client::Configuration.new }
75
+ let(:api_client) { Harbor2Client::ApiClient.new(config) }
76
+
77
+ it 'defaults to 0' do
78
+ expect(Harbor2Client::Configuration.default.timeout).to eq(0)
79
+ expect(config.timeout).to eq(0)
80
+
81
+ request = api_client.build_request(:get, '/test')
82
+ expect(request.options[:timeout]).to eq(0)
83
+ end
84
+
85
+ it 'can be customized' do
86
+ config.timeout = 100
87
+ request = api_client.build_request(:get, '/test')
88
+ expect(request.options[:timeout]).to eq(100)
89
+ end
90
+ end
91
+
92
+ describe '#build_request' do
93
+ let(:config) { Harbor2Client::Configuration.new }
94
+ let(:api_client) { Harbor2Client::ApiClient.new(config) }
95
+
96
+ it 'does not send multipart to request' do
97
+ expect(Typhoeus::Request).to receive(:new).with(anything, hash_not_including(:multipart))
98
+ api_client.build_request(:get, '/test')
99
+ end
100
+
101
+ context 'when the content type is multipart' do
102
+ it 'sends multipart to request' do
103
+ expect(Typhoeus::Request).to receive(:new).with(anything, hash_including(multipart: true))
104
+ api_client.build_request(:get, '/test', {header_params: { 'Content-Type' => 'multipart/form-data'}})
105
+ end
106
+ end
107
+ end
108
+
109
+ describe '#deserialize' do
110
+ it "handles Array<Integer>" do
111
+ api_client = Harbor2Client::ApiClient.new
112
+ headers = { 'Content-Type' => 'application/json' }
113
+ response = double('response', headers: headers, body: '[12, 34]')
114
+ data = api_client.deserialize(response, 'Array<Integer>')
115
+ expect(data).to be_instance_of(Array)
116
+ expect(data).to eq([12, 34])
117
+ end
118
+
119
+ it 'handles Array<Array<Integer>>' do
120
+ api_client = Harbor2Client::ApiClient.new
121
+ headers = { 'Content-Type' => 'application/json' }
122
+ response = double('response', headers: headers, body: '[[12, 34], [56]]')
123
+ data = api_client.deserialize(response, 'Array<Array<Integer>>')
124
+ expect(data).to be_instance_of(Array)
125
+ expect(data).to eq([[12, 34], [56]])
126
+ end
127
+
128
+ it 'handles Hash<String, String>' do
129
+ api_client = Harbor2Client::ApiClient.new
130
+ headers = { 'Content-Type' => 'application/json' }
131
+ response = double('response', headers: headers, body: '{"message": "Hello"}')
132
+ data = api_client.deserialize(response, 'Hash<String, String>')
133
+ expect(data).to be_instance_of(Hash)
134
+ expect(data).to eq(:message => 'Hello')
135
+ end
136
+ end
137
+
138
+ describe "#object_to_hash" do
139
+ it 'ignores nils and includes empty arrays' do
140
+ # uncomment below to test object_to_hash for model
141
+ # api_client = Harbor2Client::ApiClient.new
142
+ # _model = Harbor2Client::ModelName.new
143
+ # update the model attribute below
144
+ # _model.id = 1
145
+ # update the expected value (hash) below
146
+ # expected = {id: 1, name: '', tags: []}
147
+ # expect(api_client.object_to_hash(_model)).to eq(expected)
148
+ end
149
+ end
150
+
151
+ describe '#build_collection_param' do
152
+ let(:param) { ['aa', 'bb', 'cc'] }
153
+ let(:api_client) { Harbor2Client::ApiClient.new }
154
+
155
+ it 'works for csv' do
156
+ expect(api_client.build_collection_param(param, :csv)).to eq('aa,bb,cc')
157
+ end
158
+
159
+ it 'works for ssv' do
160
+ expect(api_client.build_collection_param(param, :ssv)).to eq('aa bb cc')
161
+ end
162
+
163
+ it 'works for tsv' do
164
+ expect(api_client.build_collection_param(param, :tsv)).to eq("aa\tbb\tcc")
165
+ end
166
+
167
+ it 'works for pipes' do
168
+ expect(api_client.build_collection_param(param, :pipes)).to eq('aa|bb|cc')
169
+ end
170
+
171
+ it 'works for multi' do
172
+ expect(api_client.build_collection_param(param, :multi)).to eq(['aa', 'bb', 'cc'])
173
+ end
174
+
175
+ it 'fails for invalid collection format' do
176
+ expect(proc { api_client.build_collection_param(param, :INVALID) }).to raise_error(RuntimeError, 'unknown collection format: :INVALID')
177
+ end
178
+ end
179
+
180
+ describe '#json_mime?' do
181
+ let(:api_client) { Harbor2Client::ApiClient.new }
182
+
183
+ it 'works' do
184
+ expect(api_client.json_mime?(nil)).to eq false
185
+ expect(api_client.json_mime?('')).to eq false
186
+
187
+ expect(api_client.json_mime?('application/json')).to eq true
188
+ expect(api_client.json_mime?('application/json; charset=UTF8')).to eq true
189
+ expect(api_client.json_mime?('APPLICATION/JSON')).to eq true
190
+
191
+ expect(api_client.json_mime?('application/xml')).to eq false
192
+ expect(api_client.json_mime?('text/plain')).to eq false
193
+ expect(api_client.json_mime?('application/jsonp')).to eq false
194
+ end
195
+ end
196
+
197
+ describe '#select_header_accept' do
198
+ let(:api_client) { Harbor2Client::ApiClient.new }
199
+
200
+ it 'works' do
201
+ expect(api_client.select_header_accept(nil)).to be_nil
202
+ expect(api_client.select_header_accept([])).to be_nil
203
+
204
+ expect(api_client.select_header_accept(['application/json'])).to eq('application/json')
205
+ expect(api_client.select_header_accept(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8')
206
+ expect(api_client.select_header_accept(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON')
207
+
208
+ expect(api_client.select_header_accept(['application/xml'])).to eq('application/xml')
209
+ expect(api_client.select_header_accept(['text/html', 'application/xml'])).to eq('text/html,application/xml')
210
+ end
211
+ end
212
+
213
+ describe '#select_header_content_type' do
214
+ let(:api_client) { Harbor2Client::ApiClient.new }
215
+
216
+ it 'works' do
217
+ expect(api_client.select_header_content_type(nil)).to eq('application/json')
218
+ expect(api_client.select_header_content_type([])).to eq('application/json')
219
+
220
+ expect(api_client.select_header_content_type(['application/json'])).to eq('application/json')
221
+ expect(api_client.select_header_content_type(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8')
222
+ expect(api_client.select_header_content_type(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON')
223
+ expect(api_client.select_header_content_type(['application/xml'])).to eq('application/xml')
224
+ expect(api_client.select_header_content_type(['text/plain', 'application/xml'])).to eq('text/plain')
225
+ end
226
+ end
227
+
228
+ describe '#sanitize_filename' do
229
+ let(:api_client) { Harbor2Client::ApiClient.new }
230
+
231
+ it 'works' do
232
+ expect(api_client.sanitize_filename('sun')).to eq('sun')
233
+ expect(api_client.sanitize_filename('sun.gif')).to eq('sun.gif')
234
+ expect(api_client.sanitize_filename('../sun.gif')).to eq('sun.gif')
235
+ expect(api_client.sanitize_filename('/var/tmp/sun.gif')).to eq('sun.gif')
236
+ expect(api_client.sanitize_filename('./sun.gif')).to eq('sun.gif')
237
+ expect(api_client.sanitize_filename('..\sun.gif')).to eq('sun.gif')
238
+ expect(api_client.sanitize_filename('\var\tmp\sun.gif')).to eq('sun.gif')
239
+ expect(api_client.sanitize_filename('c:\var\tmp\sun.gif')).to eq('sun.gif')
240
+ expect(api_client.sanitize_filename('.\sun.gif')).to eq('sun.gif')
241
+ end
242
+ end
243
+ end