kube_cluster 0.3.6 → 0.3.8

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.
@@ -1,5 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ if __FILE__ == $0
4
+ require "bundler/setup"
5
+ require "kube/cluster"
6
+ end
7
+
3
8
  require_relative "endpoint"
4
9
  require_relative "chart"
5
10
 
@@ -119,3 +124,201 @@ module Kube
119
124
  end
120
125
  end
121
126
  end
127
+
128
+ if __FILE__ == $0
129
+ require "minitest/autorun"
130
+
131
+ class RepoTest < Minitest::Test
132
+ # ── initialization ────────────────────────────────────────────────────
133
+
134
+ def test_initializes_with_name_and_url
135
+ repo = Kube::Helm::Repo.new("bitnami", url: "https://charts.bitnami.com/bitnami")
136
+ assert_equal "bitnami", repo.name
137
+ assert_instance_of Kube::Helm::Endpoint, repo.endpoint
138
+ assert_equal "https://charts.bitnami.com/bitnami", repo.endpoint.url
139
+ end
140
+
141
+ def test_raises_on_empty_name
142
+ assert_raises(ArgumentError) do
143
+ Kube::Helm::Repo.new("", url: "https://charts.example.com")
144
+ end
145
+ end
146
+
147
+ def test_raises_on_nil_name
148
+ assert_raises(ArgumentError) do
149
+ Kube::Helm::Repo.new(nil, url: "https://charts.example.com")
150
+ end
151
+ end
152
+
153
+ # ── oci? delegation ──────────────────────────────────────────────────
154
+
155
+ def test_oci_returns_true_for_oci_url
156
+ repo = Kube::Helm::Repo.new("ghcr", url: "oci://ghcr.io/my-org/charts")
157
+ assert repo.oci?
158
+ end
159
+
160
+ def test_oci_returns_false_for_http_url
161
+ repo = Kube::Helm::Repo.new("bitnami", url: "https://charts.bitnami.com/bitnami")
162
+ refute repo.oci?
163
+ end
164
+
165
+ # ── add / update / remove ────────────────────────────────────────────
166
+
167
+ def test_add_returns_self_for_oci
168
+ repo = Kube::Helm::Repo.new("ghcr", url: "oci://ghcr.io/my-org/charts")
169
+ assert_equal repo, repo.add
170
+ end
171
+
172
+ def test_update_returns_self_for_oci
173
+ repo = Kube::Helm::Repo.new("ghcr", url: "oci://ghcr.io/my-org/charts")
174
+ assert_equal repo, repo.update
175
+ end
176
+
177
+ def test_remove_returns_self_for_oci
178
+ repo = Kube::Helm::Repo.new("ghcr", url: "oci://ghcr.io/my-org/charts")
179
+ assert_equal repo, repo.remove
180
+ end
181
+
182
+ def test_add_runs_helm_repo_add
183
+ repo = Kube::Helm::Repo.new("bitnami", url: "https://charts.bitnami.com/bitnami")
184
+
185
+ captured_cmd = nil
186
+ Kube::Helm.stub(:run, ->(cmd) { captured_cmd = cmd; "" }) do
187
+ result = repo.add
188
+ assert_equal repo, result
189
+ end
190
+
191
+ assert_includes captured_cmd, "repo"
192
+ assert_includes captured_cmd, "add"
193
+ assert_includes captured_cmd, "bitnami"
194
+ assert_includes captured_cmd, "https://charts.bitnami.com/bitnami"
195
+ end
196
+
197
+ def test_update_runs_helm_repo_update
198
+ repo = Kube::Helm::Repo.new("bitnami", url: "https://charts.bitnami.com/bitnami")
199
+
200
+ captured_cmd = nil
201
+ Kube::Helm.stub(:run, ->(cmd) { captured_cmd = cmd; "" }) do
202
+ repo.update
203
+ end
204
+
205
+ assert_includes captured_cmd, "repo"
206
+ assert_includes captured_cmd, "update"
207
+ assert_includes captured_cmd, "bitnami"
208
+ end
209
+
210
+ def test_remove_runs_helm_repo_remove
211
+ repo = Kube::Helm::Repo.new("bitnami", url: "https://charts.bitnami.com/bitnami")
212
+
213
+ captured_cmd = nil
214
+ Kube::Helm.stub(:run, ->(cmd) { captured_cmd = cmd; "" }) do
215
+ repo.remove
216
+ end
217
+
218
+ assert_includes captured_cmd, "repo"
219
+ assert_includes captured_cmd, "remove"
220
+ assert_includes captured_cmd, "bitnami"
221
+ end
222
+
223
+ # ── fetch ────────────────────────────────────────────────────────────
224
+
225
+ def test_fetch_returns_chart_with_metadata
226
+ repo = Kube::Helm::Repo.new("bitnami", url: "https://charts.bitnami.com/bitnami")
227
+
228
+ stub_chart_yaml = {
229
+ "name" => "nginx",
230
+ "version" => "18.1.0",
231
+ "appVersion" => "1.25.0",
232
+ }.to_yaml
233
+
234
+ captured_cmds = []
235
+ Kube::Helm.stub(:run, ->(cmd) {
236
+ captured_cmds << cmd
237
+ cmd.include?("show") ? stub_chart_yaml : ""
238
+ }) do
239
+ chart = repo.fetch("nginx", version: "18.1.0")
240
+
241
+ assert_instance_of Kube::Helm::Chart, chart
242
+ assert_equal "nginx", chart.name
243
+ assert_equal "18.1.0", chart.version
244
+ assert_equal "1.25.0", chart.app_version
245
+ assert_equal "bitnami/nginx", chart.ref
246
+ assert_nil chart.path
247
+ end
248
+
249
+ # Should have run: repo add, repo update, show chart
250
+ show_cmd = captured_cmds.find { |c| c.include?("show") && c.include?("chart") }
251
+ assert show_cmd, "Expected a show chart command"
252
+ assert_includes show_cmd, "bitnami/nginx"
253
+ assert_includes show_cmd, "--version=18.1.0"
254
+ end
255
+
256
+ def test_fetch_without_version
257
+ repo = Kube::Helm::Repo.new("bitnami", url: "https://charts.bitnami.com/bitnami")
258
+
259
+ stub_chart_yaml = { "name" => "nginx", "version" => "18.1.0" }.to_yaml
260
+
261
+ captured_cmds = []
262
+ Kube::Helm.stub(:run, ->(cmd) {
263
+ captured_cmds << cmd
264
+ cmd.include?("show") ? stub_chart_yaml : ""
265
+ }) do
266
+ chart = repo.fetch("nginx")
267
+ assert_instance_of Kube::Helm::Chart, chart
268
+ assert_nil chart.path
269
+ end
270
+
271
+ show_cmd = captured_cmds.find { |c| c.include?("show") && c.include?("chart") }
272
+ refute_includes show_cmd, "--version"
273
+ end
274
+
275
+ def test_fetch_propagates_cluster
276
+ cluster = Kube::Cluster.connect(kubeconfig: "/tmp/test-kubeconfig")
277
+ repo = Kube::Helm::Repo.new("bitnami", url: "https://charts.bitnami.com/bitnami", cluster: cluster)
278
+
279
+ stub_chart_yaml = { "name" => "nginx", "version" => "18.1.0" }.to_yaml
280
+
281
+ cluster.connection.helm.stub(:run, ->(cmd) {
282
+ cmd.include?("show") ? stub_chart_yaml : ""
283
+ }) do
284
+ chart = repo.fetch("nginx", version: "18.1.0")
285
+ assert_equal cluster, chart.cluster
286
+ assert_equal "bitnami/nginx", chart.ref
287
+ end
288
+ end
289
+
290
+ # ── cluster scoping ──────────────────────────────────────────────────
291
+
292
+ def test_initializes_without_cluster
293
+ repo = Kube::Helm::Repo.new("bitnami", url: "https://charts.bitnami.com/bitnami")
294
+ assert_nil repo.cluster
295
+ end
296
+
297
+ def test_initializes_with_cluster
298
+ cluster = Kube::Cluster.connect(kubeconfig: "/tmp/test-kubeconfig")
299
+ repo = Kube::Helm::Repo.new("bitnami", url: "https://charts.bitnami.com/bitnami", cluster: cluster)
300
+ assert_equal cluster, repo.cluster
301
+ end
302
+
303
+ def test_add_uses_cluster_helm_instance
304
+ cluster = Kube::Cluster.connect(kubeconfig: "/tmp/test-kubeconfig")
305
+ repo = Kube::Helm::Repo.new("bitnami", url: "https://charts.bitnami.com/bitnami", cluster: cluster)
306
+
307
+ captured_cmd = nil
308
+ cluster.connection.helm.stub(:run, ->(cmd) { captured_cmd = cmd; "" }) do
309
+ repo.add
310
+ end
311
+
312
+ assert_includes captured_cmd, "repo"
313
+ assert_includes captured_cmd, "add"
314
+ assert_includes captured_cmd, "bitnami"
315
+ end
316
+
317
+ # ── to_s ──────────────────────────────────────────────────────────────
318
+
319
+ def test_to_s
320
+ repo = Kube::Helm::Repo.new("bitnami", url: "https://charts.bitnami.com/bitnami")
321
+ assert_equal "bitnami (https://charts.bitnami.com/bitnami)", repo.to_s
322
+ end
323
+ end
324
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kube_cluster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan K
@@ -71,14 +71,14 @@ dependencies:
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: 2.0.0
74
+ version: 2.0.9
75
75
  type: :runtime
76
76
  prerelease: false
77
77
  version_requirements: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: 2.0.0
81
+ version: 2.0.9
82
82
  description: 'OOP abstraction that allows you to deploy and manage kubernetes resources
83
83
  using Ruby.
84
84
 
@@ -98,6 +98,7 @@ files:
98
98
  - Gemfile.lock
99
99
  - LICENSE
100
100
  - README.md
101
+ - Rakefile
101
102
  - bin/console
102
103
  - bin/dev
103
104
  - bin/increment-version
@@ -145,11 +146,13 @@ files:
145
146
  - examples/04-pod-with-ingress/pod_with_ingress.rb
146
147
  - examples/04-pod-with-ingress/registries.yaml
147
148
  - examples/05-helm-chart-to-manifest/Gemfile
149
+ - examples/05-helm-chart-to-manifest/Gemfile.lock
148
150
  - examples/05-helm-chart-to-manifest/README.md
149
151
  - examples/05-helm-chart-to-manifest/bin/dev
150
152
  - examples/05-helm-chart-to-manifest/docker-compose.yml
151
153
  - examples/05-helm-chart-to-manifest/manifest.rb
152
154
  - examples/06-nginx-with-cert-manager/Gemfile
155
+ - examples/06-nginx-with-cert-manager/Gemfile.lock
153
156
  - examples/06-nginx-with-cert-manager/README.md
154
157
  - examples/06-nginx-with-cert-manager/bin/dev
155
158
  - examples/06-nginx-with-cert-manager/docker-compose.yml