Class: HelmCommandTreeTest

Inherits:
Minitest::Test
  • Object
show all
Defined in:
lib/kube/helm/command_tree.rb

Instance Method Summary collapse

Instance Method Details

#assert_results(result, final = nil, commands:, positional:, flags: nil, errors: nil, valid: true) ⇒ Object



215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/kube/helm/command_tree.rb', line 215

def assert_results(result, final = nil, commands:, positional:, flags: nil, errors: nil, valid: true)
  assert_equal commands, result.commands, "commands mismatch"
  assert_equal positional, result.positional, "positional mismatch"
  if valid
    assert result.valid, "expected valid but got errors: #{result.errors}"
  else
    refute result.valid, "expected invalid"
  end

  assert_equal flags, result.flags, "flags mismatch" unless flags.nil?
  assert_equal errors, result.errors, "errors mismatch" unless errors.nil?
  assert_equal final, result.to_s, "to_s mismatch" unless final.nil?
end

#setupObject



210
211
212
213
# File 'lib/kube/helm/command_tree.rb', line 210

def setup
  data = YAML.load_file(File.expand_path("../../../data/helm.yaml", __dir__))
  @tree = Kube::Helm::CommandTree.new(data)
end

#test_create_chartObject



609
610
611
612
613
614
615
616
617
618
619
620
# File 'lib/kube/helm/command_tree.rb', line 609

def test_create_chart
  result = @tree.evaluate(Kube.helm { create.my-chart })

  assert_results(
    result,
    "create my-chart",
    commands: ["create"],
    positional: ["my-chart"],
    flags: [],
    valid: true
  )
end

#test_dependency_buildObject



460
461
462
463
464
465
466
467
468
469
470
471
# File 'lib/kube/helm/command_tree.rb', line 460

def test_dependency_build
  result = @tree.evaluate(Kube.helm { dependency.build.("./my-chart") })

  assert_results(
    result,
    "dependency build ./my-chart",
    commands: ["dependency", "build"],
    positional: ["./my-chart"],
    flags: [],
    valid: true
  )
end

#test_dependency_listObject



473
474
475
476
477
478
479
480
481
482
483
484
# File 'lib/kube/helm/command_tree.rb', line 473

def test_dependency_list
  result = @tree.evaluate(Kube.helm { dependency.list.("./my-chart") })

  assert_results(
    result,
    "dependency list ./my-chart",
    commands: ["dependency", "list"],
    positional: ["./my-chart"],
    flags: [],
    valid: true
  )
end

#test_dependency_updateObject

— Dependency subcommands —



447
448
449
450
451
452
453
454
455
456
457
458
# File 'lib/kube/helm/command_tree.rb', line 447

def test_dependency_update
  result = @tree.evaluate(Kube.helm { dependency.update.("./my-chart") })

  assert_results(
    result,
    "dependency update ./my-chart",
    commands: ["dependency", "update"],
    positional: ["./my-chart"],
    flags: [],
    valid: true
  )
end

#test_envObject



596
597
598
599
600
601
602
603
604
605
606
607
# File 'lib/kube/helm/command_tree.rb', line 596

def test_env
  result = @tree.evaluate(Kube.helm { env })

  assert_results(
    result,
    "env",
    commands: ["env"],
    positional: [],
    flags: [],
    valid: true
  )
end

#test_get_all_with_revisionObject



378
379
380
381
382
383
384
385
386
387
388
389
# File 'lib/kube/helm/command_tree.rb', line 378

def test_get_all_with_revision
  result = @tree.evaluate(Kube.helm { get.all.my_release.revision(3) })

  assert_results(
    result,
    "get all my_release --revision 3",
    commands: ["get", "all"],
    positional: ["my_release"],
    flags: ["--revision 3"],
    valid: true
  )
end

#test_get_hooksObject



391
392
393
394
395
396
397
398
399
400
401
402
# File 'lib/kube/helm/command_tree.rb', line 391

def test_get_hooks
  result = @tree.evaluate(Kube.helm { get.hooks.my_release })

  assert_results(
    result,
    "get hooks my_release",
    commands: ["get", "hooks"],
    positional: ["my_release"],
    flags: [],
    valid: true
  )
end

#test_get_manifestObject



365
366
367
368
369
370
371
372
373
374
375
376
# File 'lib/kube/helm/command_tree.rb', line 365

def test_get_manifest
  result = @tree.evaluate(Kube.helm { get.manifest.my_release })

  assert_results(
    result,
    "get manifest my_release",
    commands: ["get", "manifest"],
    positional: ["my_release"],
    flags: [],
    valid: true
  )
end

#test_get_values_with_output_flagObject

— Deep subcommands —



352
353
354
355
356
357
358
359
360
361
362
363
# File 'lib/kube/helm/command_tree.rb', line 352

def test_get_values_with_output_flag
  result = @tree.evaluate(Kube.helm { get.values.my_release.output("json") })

  assert_results(
    result,
    "get values my_release --output json",
    commands: ["get", "values"],
    positional: ["my_release"],
    flags: ["--output json"],
    valid: true
  )
end

#test_historyObject



570
571
572
573
574
575
576
577
578
579
580
581
# File 'lib/kube/helm/command_tree.rb', line 570

def test_history
  result = @tree.evaluate(Kube.helm { history.my_release })

  assert_results(
    result,
    "history my_release",
    commands: ["history"],
    positional: ["my_release"],
    flags: [],
    valid: true
  )
end

#test_install_chart_with_namespace_flagObject



244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/kube/helm/command_tree.rb', line 244

def test_install_chart_with_namespace_flag
  result = @tree.evaluate(Kube.helm { install.my_release.("bitnami/nginx").namespace("default") })

  assert_results(
    result,
    "install my_release bitnami/nginx --namespace default",
    commands: ["install"],
    positional: ["my_release", "bitnami/nginx"],
    flags: ["--namespace default"],
    valid: true
  )
end

#test_install_chart_with_release_nameObject

— Basic commands —



231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/kube/helm/command_tree.rb', line 231

def test_install_chart_with_release_name
  result = @tree.evaluate(Kube.helm { install.my_release.("bitnami/nginx") })

  assert_results(
    result,
    "install my_release bitnami/nginx",
    commands: ["install"],
    positional: ["my_release", "bitnami/nginx"],
    flags: [],
    valid: true
  )
end

#test_install_with_multiple_flagsObject

— Complex flag combinations —



707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
# File 'lib/kube/helm/command_tree.rb', line 707

def test_install_with_multiple_flags
  result = @tree.evaluate(Kube.helm {
    install.my_release.("bitnami/nginx")
      .namespace("prod")
      .create_namespace(true)
      .wait(true)
      .timeout("5m0s")
  })

  assert_results(
    result,
    "install my_release bitnami/nginx --namespace prod --create-namespace --wait --timeout 5m0s",
    commands: ["install"],
    positional: ["my_release", "bitnami/nginx"],
    flags: ["--namespace prod", "--create-namespace", "--wait", "--timeout 5m0s"],
    valid: true
  )
end

#test_lint_chartObject



622
623
624
625
626
627
628
629
630
631
632
633
# File 'lib/kube/helm/command_tree.rb', line 622

def test_lint_chart
  result = @tree.evaluate(Kube.helm { lint.("./my-chart") })

  assert_results(
    result,
    "lint ./my-chart",
    commands: ["lint"],
    positional: ["./my-chart"],
    flags: [],
    valid: true
  )
end

#test_list_all_namespacesObject



283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/kube/helm/command_tree.rb', line 283

def test_list_all_namespaces
  result = @tree.evaluate(Kube.helm { list.all_namespaces(true) })

  assert_results(
    result,
    "list --all-namespaces",
    commands: ["list"],
    positional: [],
    flags: ["--all-namespaces"],
    valid: true
  )
end

#test_list_releasesObject



270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/kube/helm/command_tree.rb', line 270

def test_list_releases
  result = @tree.evaluate(Kube.helm { list })

  assert_results(
    result,
    "list",
    commands: ["list"],
    positional: [],
    flags: [],
    valid: true
  )
end

#test_package_chartObject



635
636
637
638
639
640
641
642
643
644
645
646
# File 'lib/kube/helm/command_tree.rb', line 635

def test_package_chart
  result = @tree.evaluate(Kube.helm { package.("./my-chart") })

  assert_results(
    result,
    "package ./my-chart",
    commands: ["package"],
    positional: ["./my-chart"],
    flags: [],
    valid: true
  )
end

#test_plugin_installObject



663
664
665
666
667
668
669
670
671
672
673
674
# File 'lib/kube/helm/command_tree.rb', line 663

def test_plugin_install
  result = @tree.evaluate(Kube.helm { plugin.install.("https://example.com/plugin.git") })

  assert_results(
    result,
    "plugin install https://example.com/plugin.git",
    commands: ["plugin", "install"],
    positional: ["https://example.com/plugin.git"],
    flags: [],
    valid: true
  )
end

#test_plugin_listObject

— Plugin subcommands —



650
651
652
653
654
655
656
657
658
659
660
661
# File 'lib/kube/helm/command_tree.rb', line 650

def test_plugin_list
  result = @tree.evaluate(Kube.helm { plugin.list })

  assert_results(
    result,
    "plugin list",
    commands: ["plugin", "list"],
    positional: [],
    flags: [],
    valid: true
  )
end

#test_registry_loginObject

— Registry subcommands —



678
679
680
681
682
683
684
685
686
687
688
689
# File 'lib/kube/helm/command_tree.rb', line 678

def 
  result = @tree.evaluate(Kube.helm { registry..("localhost:5000").username("admin").password("secret") })

  assert_results(
    result,
    "registry login localhost:5000 --username admin --password secret",
    commands: ["registry", "login"],
    positional: ["localhost:5000"],
    flags: ["--username admin", "--password secret"],
    valid: true
  )
end

#test_repo_addObject

— Subcommands —



298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/kube/helm/command_tree.rb', line 298

def test_repo_add
  result = @tree.evaluate(Kube.helm { repo.add.("bitnami").("https://charts.bitnami.com/bitnami") })

  assert_results(
    result,
    "repo add bitnami https://charts.bitnami.com/bitnami",
    commands: ["repo", "add"],
    positional: ["bitnami", "https://charts.bitnami.com/bitnami"],
    flags: [],
    valid: true
  )
end

#test_repo_listObject



311
312
313
314
315
316
317
318
319
320
321
322
# File 'lib/kube/helm/command_tree.rb', line 311

def test_repo_list
  result = @tree.evaluate(Kube.helm { repo.list })

  assert_results(
    result,
    "repo list",
    commands: ["repo", "list"],
    positional: [],
    flags: [],
    valid: true
  )
end

#test_repo_removeObject



337
338
339
340
341
342
343
344
345
346
347
348
# File 'lib/kube/helm/command_tree.rb', line 337

def test_repo_remove
  result = @tree.evaluate(Kube.helm { repo.remove.("bitnami") })

  assert_results(
    result,
    "repo remove bitnami",
    commands: ["repo", "remove"],
    positional: ["bitnami"],
    flags: [],
    valid: true
  )
end

#test_repo_updateObject



324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/kube/helm/command_tree.rb', line 324

def test_repo_update
  result = @tree.evaluate(Kube.helm { repo.update })

  assert_results(
    result,
    "repo update",
    commands: ["repo", "update"],
    positional: [],
    flags: [],
    valid: true
  )
end

#test_rollback_with_revisionObject

— Other commands —



557
558
559
560
561
562
563
564
565
566
567
568
# File 'lib/kube/helm/command_tree.rb', line 557

def test_rollback_with_revision
  result = @tree.evaluate(Kube.helm { rollback.my_release.("2") })

  assert_results(
    result,
    "rollback my_release 2",
    commands: ["rollback"],
    positional: ["my_release", "2"],
    flags: [],
    valid: true
  )
end

#test_search_hubObject



542
543
544
545
546
547
548
549
550
551
552
553
# File 'lib/kube/helm/command_tree.rb', line 542

def test_search_hub
  result = @tree.evaluate(Kube.helm { search.hub.("nginx") })

  assert_results(
    result,
    "search hub nginx",
    commands: ["search", "hub"],
    positional: ["nginx"],
    flags: [],
    valid: true
  )
end

#test_search_repoObject

— Search —



529
530
531
532
533
534
535
536
537
538
539
540
# File 'lib/kube/helm/command_tree.rb', line 529

def test_search_repo
  result = @tree.evaluate(Kube.helm { search.repo.("nginx") })

  assert_results(
    result,
    "search repo nginx",
    commands: ["search", "repo"],
    positional: ["nginx"],
    flags: [],
    valid: true
  )
end

#test_show_chartObject



514
515
516
517
518
519
520
521
522
523
524
525
# File 'lib/kube/helm/command_tree.rb', line 514

def test_show_chart
  result = @tree.evaluate(Kube.helm { show.chart.("bitnami/nginx") })

  assert_results(
    result,
    "show chart bitnami/nginx",
    commands: ["show", "chart"],
    positional: ["bitnami/nginx"],
    flags: [],
    valid: true
  )
end

#test_show_valuesObject



501
502
503
504
505
506
507
508
509
510
511
512
# File 'lib/kube/helm/command_tree.rb', line 501

def test_show_values
  result = @tree.evaluate(Kube.helm { show.values.("bitnami/nginx") })

  assert_results(
    result,
    "show values bitnami/nginx",
    commands: ["show", "values"],
    positional: ["bitnami/nginx"],
    flags: [],
    valid: true
  )
end

#test_status_with_outputObject



583
584
585
586
587
588
589
590
591
592
593
594
# File 'lib/kube/helm/command_tree.rb', line 583

def test_status_with_output
  result = @tree.evaluate(Kube.helm { status.my_release.o(:json) })

  assert_results(
    result,
    "status my_release -o json",
    commands: ["status"],
    positional: ["my_release"],
    flags: ["-o json"],
    valid: true
  )
end

#test_template_with_namespaceObject

— Template & Show —



488
489
490
491
492
493
494
495
496
497
498
499
# File 'lib/kube/helm/command_tree.rb', line 488

def test_template_with_namespace
  result = @tree.evaluate(Kube.helm { template.my_release.("bitnami/nginx").namespace("prod") })

  assert_results(
    result,
    "template my_release bitnami/nginx --namespace prod",
    commands: ["template"],
    positional: ["my_release", "bitnami/nginx"],
    flags: ["--namespace prod"],
    valid: true
  )
end

#test_to_s_produces_valid_command_stringObject

— to_s output —



746
747
748
749
# File 'lib/kube/helm/command_tree.rb', line 746

def test_to_s_produces_valid_command_string
  result = @tree.evaluate(Kube.helm { install.my_release.("bitnami/nginx").namespace("default").wait(true) })
  assert_equal "install my_release bitnami/nginx --namespace default --wait", result.to_s
end

#test_uninstall_releaseObject



257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/kube/helm/command_tree.rb', line 257

def test_uninstall_release
  result = @tree.evaluate(Kube.helm { uninstall.my_release })

  assert_results(
    result,
    "uninstall my_release",
    commands: ["uninstall"],
    positional: ["my_release"],
    flags: [],
    valid: true
  )
end

#test_unknown_command_returns_errorObject

— Error cases —



693
694
695
696
697
698
699
700
701
702
703
# File 'lib/kube/helm/command_tree.rb', line 693

def test_unknown_command_returns_error
  result = @tree.evaluate(Kube.helm { definitely_missing })

  assert_results(
    result,
    commands: [],
    positional: ["definitely_missing"],
    errors: ["invalid command start: `definitely_missing`"],
    valid: false
  )
end

#test_upgrade_install_with_values_and_setObject



726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
# File 'lib/kube/helm/command_tree.rb', line 726

def test_upgrade_install_with_values_and_set
  result = @tree.evaluate(Kube.helm {
    upgrade.install(true).my_release.("bitnami/nginx")
      .f("values.yaml")
      .set("replicaCount=3")
      .namespace("prod")
  })

  assert_results(
    result,
    "upgrade my_release bitnami/nginx --install -f values.yaml --set replicaCount=3 --namespace prod",
    commands: ["upgrade"],
    positional: ["my_release", "bitnami/nginx"],
    flags: ["--install", "-f values.yaml", "--set replicaCount=3", "--namespace prod"],
    valid: true
  )
end

#test_upgrade_with_install_flagObject

— Upgrade —



406
407
408
409
410
411
412
413
414
415
416
417
# File 'lib/kube/helm/command_tree.rb', line 406

def test_upgrade_with_install_flag
  result = @tree.evaluate(Kube.helm { upgrade.install(true).my_release.("bitnami/nginx") })

  assert_results(
    result,
    "upgrade my_release bitnami/nginx --install",
    commands: ["upgrade"],
    positional: ["my_release", "bitnami/nginx"],
    flags: ["--install"],
    valid: true
  )
end

#test_upgrade_with_set_flagObject



419
420
421
422
423
424
425
426
427
428
429
430
# File 'lib/kube/helm/command_tree.rb', line 419

def test_upgrade_with_set_flag
  result = @tree.evaluate(Kube.helm { upgrade.my_release.("bitnami/nginx").set("image.tag=latest") })

  assert_results(
    result,
    "upgrade my_release bitnami/nginx --set image.tag=latest",
    commands: ["upgrade"],
    positional: ["my_release", "bitnami/nginx"],
    flags: ["--set image.tag=latest"],
    valid: true
  )
end

#test_upgrade_with_values_fileObject



432
433
434
435
436
437
438
439
440
441
442
443
# File 'lib/kube/helm/command_tree.rb', line 432

def test_upgrade_with_values_file
  result = @tree.evaluate(Kube.helm { upgrade.my_release.("bitnami/nginx").f("values.yaml") })

  assert_results(
    result,
    "upgrade my_release bitnami/nginx -f values.yaml",
    commands: ["upgrade"],
    positional: ["my_release", "bitnami/nginx"],
    flags: ["-f values.yaml"],
    valid: true
  )
end