Class: RepoTest
- Inherits:
-
Minitest::Test
- Object
- Minitest::Test
- RepoTest
- Defined in:
- lib/kube/helm/repo.rb
Instance Method Summary collapse
-
#test_add_returns_self_for_oci ⇒ Object
── add / update / remove ────────────────────────────────────────────.
- #test_add_runs_helm_repo_add ⇒ Object
- #test_add_uses_cluster_helm_instance ⇒ Object
- #test_fetch_propagates_cluster ⇒ Object
-
#test_fetch_returns_chart_with_metadata ⇒ Object
── fetch ────────────────────────────────────────────────────────────.
- #test_fetch_without_version ⇒ Object
- #test_initializes_with_cluster ⇒ Object
-
#test_initializes_with_name_and_url ⇒ Object
── initialization ────────────────────────────────────────────────────.
-
#test_initializes_without_cluster ⇒ Object
── cluster scoping ──────────────────────────────────────────────────.
- #test_oci_returns_false_for_http_url ⇒ Object
-
#test_oci_returns_true_for_oci_url ⇒ Object
── oci? delegation ──────────────────────────────────────────────────.
- #test_raises_on_empty_name ⇒ Object
- #test_raises_on_nil_name ⇒ Object
- #test_remove_returns_self_for_oci ⇒ Object
- #test_remove_runs_helm_repo_remove ⇒ Object
-
#test_to_s ⇒ Object
── to_s ──────────────────────────────────────────────────────────────.
- #test_update_returns_self_for_oci ⇒ Object
- #test_update_runs_helm_repo_update ⇒ Object
Instance Method Details
#test_add_returns_self_for_oci ⇒ Object
── add / update / remove ────────────────────────────────────────────
167 168 169 170 |
# File 'lib/kube/helm/repo.rb', line 167 def test_add_returns_self_for_oci repo = Kube::Helm::Repo.new("ghcr", url: "oci://ghcr.io/my-org/charts") assert_equal repo, repo.add end |
#test_add_runs_helm_repo_add ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/kube/helm/repo.rb', line 182 def test_add_runs_helm_repo_add repo = Kube::Helm::Repo.new("bitnami", url: "https://charts.bitnami.com/bitnami") captured_cmd = nil Kube::Helm.stub(:run, ->(cmd) { captured_cmd = cmd; "" }) do result = repo.add assert_equal repo, result end assert_includes captured_cmd, "repo" assert_includes captured_cmd, "add" assert_includes captured_cmd, "bitnami" assert_includes captured_cmd, "https://charts.bitnami.com/bitnami" end |
#test_add_uses_cluster_helm_instance ⇒ Object
303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/kube/helm/repo.rb', line 303 def test_add_uses_cluster_helm_instance cluster = Kube::Cluster.connect(kubeconfig: "/tmp/test-kubeconfig") repo = Kube::Helm::Repo.new("bitnami", url: "https://charts.bitnami.com/bitnami", cluster: cluster) captured_cmd = nil cluster.connection.helm.stub(:run, ->(cmd) { captured_cmd = cmd; "" }) do repo.add end assert_includes captured_cmd, "repo" assert_includes captured_cmd, "add" assert_includes captured_cmd, "bitnami" end |
#test_fetch_propagates_cluster ⇒ Object
275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/kube/helm/repo.rb', line 275 def test_fetch_propagates_cluster cluster = Kube::Cluster.connect(kubeconfig: "/tmp/test-kubeconfig") repo = Kube::Helm::Repo.new("bitnami", url: "https://charts.bitnami.com/bitnami", cluster: cluster) stub_chart_yaml = { "name" => "nginx", "version" => "18.1.0" }.to_yaml cluster.connection.helm.stub(:run, ->(cmd) { cmd.include?("show") ? stub_chart_yaml : "" }) do chart = repo.fetch("nginx", version: "18.1.0") assert_equal cluster, chart.cluster assert_equal "bitnami/nginx", chart.ref end end |
#test_fetch_returns_chart_with_metadata ⇒ Object
── fetch ────────────────────────────────────────────────────────────
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/kube/helm/repo.rb', line 225 def repo = Kube::Helm::Repo.new("bitnami", url: "https://charts.bitnami.com/bitnami") stub_chart_yaml = { "name" => "nginx", "version" => "18.1.0", "appVersion" => "1.25.0", }.to_yaml captured_cmds = [] Kube::Helm.stub(:run, ->(cmd) { captured_cmds << cmd cmd.include?("show") ? stub_chart_yaml : "" }) do chart = repo.fetch("nginx", version: "18.1.0") assert_instance_of Kube::Helm::Chart, chart assert_equal "nginx", chart.name assert_equal "18.1.0", chart.version assert_equal "1.25.0", chart.app_version assert_equal "bitnami/nginx", chart.ref assert_nil chart.path end # Should have run: repo add, repo update, show chart show_cmd = captured_cmds.find { |c| c.include?("show") && c.include?("chart") } assert show_cmd, "Expected a show chart command" assert_includes show_cmd, "bitnami/nginx" assert_includes show_cmd, "--version=18.1.0" end |
#test_fetch_without_version ⇒ Object
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/kube/helm/repo.rb', line 256 def test_fetch_without_version repo = Kube::Helm::Repo.new("bitnami", url: "https://charts.bitnami.com/bitnami") stub_chart_yaml = { "name" => "nginx", "version" => "18.1.0" }.to_yaml captured_cmds = [] Kube::Helm.stub(:run, ->(cmd) { captured_cmds << cmd cmd.include?("show") ? stub_chart_yaml : "" }) do chart = repo.fetch("nginx") assert_instance_of Kube::Helm::Chart, chart assert_nil chart.path end show_cmd = captured_cmds.find { |c| c.include?("show") && c.include?("chart") } refute_includes show_cmd, "--version" end |
#test_initializes_with_cluster ⇒ Object
297 298 299 300 301 |
# File 'lib/kube/helm/repo.rb', line 297 def test_initializes_with_cluster cluster = Kube::Cluster.connect(kubeconfig: "/tmp/test-kubeconfig") repo = Kube::Helm::Repo.new("bitnami", url: "https://charts.bitnami.com/bitnami", cluster: cluster) assert_equal cluster, repo.cluster end |
#test_initializes_with_name_and_url ⇒ Object
── initialization ────────────────────────────────────────────────────
134 135 136 137 138 139 |
# File 'lib/kube/helm/repo.rb', line 134 def test_initializes_with_name_and_url repo = Kube::Helm::Repo.new("bitnami", url: "https://charts.bitnami.com/bitnami") assert_equal "bitnami", repo.name assert_instance_of Kube::Helm::Endpoint, repo.endpoint assert_equal "https://charts.bitnami.com/bitnami", repo.endpoint.url end |
#test_initializes_without_cluster ⇒ Object
── cluster scoping ──────────────────────────────────────────────────
292 293 294 295 |
# File 'lib/kube/helm/repo.rb', line 292 def test_initializes_without_cluster repo = Kube::Helm::Repo.new("bitnami", url: "https://charts.bitnami.com/bitnami") assert_nil repo.cluster end |
#test_oci_returns_false_for_http_url ⇒ Object
160 161 162 163 |
# File 'lib/kube/helm/repo.rb', line 160 def test_oci_returns_false_for_http_url repo = Kube::Helm::Repo.new("bitnami", url: "https://charts.bitnami.com/bitnami") refute repo.oci? end |
#test_oci_returns_true_for_oci_url ⇒ Object
── oci? delegation ──────────────────────────────────────────────────
155 156 157 158 |
# File 'lib/kube/helm/repo.rb', line 155 def test_oci_returns_true_for_oci_url repo = Kube::Helm::Repo.new("ghcr", url: "oci://ghcr.io/my-org/charts") assert repo.oci? end |
#test_raises_on_empty_name ⇒ Object
141 142 143 144 145 |
# File 'lib/kube/helm/repo.rb', line 141 def test_raises_on_empty_name assert_raises(ArgumentError) do Kube::Helm::Repo.new("", url: "https://charts.example.com") end end |
#test_raises_on_nil_name ⇒ Object
147 148 149 150 151 |
# File 'lib/kube/helm/repo.rb', line 147 def test_raises_on_nil_name assert_raises(ArgumentError) do Kube::Helm::Repo.new(nil, url: "https://charts.example.com") end end |
#test_remove_returns_self_for_oci ⇒ Object
177 178 179 180 |
# File 'lib/kube/helm/repo.rb', line 177 def test_remove_returns_self_for_oci repo = Kube::Helm::Repo.new("ghcr", url: "oci://ghcr.io/my-org/charts") assert_equal repo, repo.remove end |
#test_remove_runs_helm_repo_remove ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/kube/helm/repo.rb', line 210 def test_remove_runs_helm_repo_remove repo = Kube::Helm::Repo.new("bitnami", url: "https://charts.bitnami.com/bitnami") captured_cmd = nil Kube::Helm.stub(:run, ->(cmd) { captured_cmd = cmd; "" }) do repo.remove end assert_includes captured_cmd, "repo" assert_includes captured_cmd, "remove" assert_includes captured_cmd, "bitnami" end |
#test_to_s ⇒ Object
── to_s ──────────────────────────────────────────────────────────────
319 320 321 322 |
# File 'lib/kube/helm/repo.rb', line 319 def test_to_s repo = Kube::Helm::Repo.new("bitnami", url: "https://charts.bitnami.com/bitnami") assert_equal "bitnami (https://charts.bitnami.com/bitnami)", repo.to_s end |
#test_update_returns_self_for_oci ⇒ Object
172 173 174 175 |
# File 'lib/kube/helm/repo.rb', line 172 def test_update_returns_self_for_oci repo = Kube::Helm::Repo.new("ghcr", url: "oci://ghcr.io/my-org/charts") assert_equal repo, repo.update end |
#test_update_runs_helm_repo_update ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/kube/helm/repo.rb', line 197 def test_update_runs_helm_repo_update repo = Kube::Helm::Repo.new("bitnami", url: "https://charts.bitnami.com/bitnami") captured_cmd = nil Kube::Helm.stub(:run, ->(cmd) { captured_cmd = cmd; "" }) do repo.update end assert_includes captured_cmd, "repo" assert_includes captured_cmd, "update" assert_includes captured_cmd, "bitnami" end |