chart_test.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. Copyright © The ESO Authors
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. https://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package addon
  14. import "testing"
  15. func TestHelmDependencyUpdateEnabledByDefault(t *testing.T) {
  16. t.Setenv("E2E_SKIP_HELM_DEPENDENCY_UPDATE", "")
  17. if !helmDependencyUpdateEnabled() {
  18. t.Fatalf("expected helm dependency update to be enabled by default")
  19. }
  20. }
  21. func TestHelmDependencyUpdateCanBeSkipped(t *testing.T) {
  22. t.Setenv("E2E_SKIP_HELM_DEPENDENCY_UPDATE", "true")
  23. if helmDependencyUpdateEnabled() {
  24. t.Fatalf("expected helm dependency update to be disabled when E2E_SKIP_HELM_DEPENDENCY_UPDATE=true")
  25. }
  26. }
  27. func TestInstallArgsIncludeDependencyUpdateByDefault(t *testing.T) {
  28. t.Setenv("E2E_SKIP_HELM_DEPENDENCY_UPDATE", "")
  29. args := (&HelmChart{
  30. ReleaseName: "eso",
  31. Chart: "/tmp/chart",
  32. Namespace: "default",
  33. }).installArgs()
  34. if !contains(args, "--dependency-update") {
  35. t.Fatalf("expected install args to include --dependency-update, got %v", args)
  36. }
  37. }
  38. func TestInstallArgsOmitDependencyUpdateWhenSkipped(t *testing.T) {
  39. t.Setenv("E2E_SKIP_HELM_DEPENDENCY_UPDATE", "true")
  40. args := (&HelmChart{
  41. ReleaseName: "eso",
  42. Chart: "/tmp/chart",
  43. Namespace: "default",
  44. }).installArgs()
  45. if contains(args, "--dependency-update") {
  46. t.Fatalf("expected install args to omit --dependency-update when E2E_SKIP_HELM_DEPENDENCY_UPDATE=true, got %v", args)
  47. }
  48. }
  49. func TestUninstallArgsIncludeIgnoreNotFound(t *testing.T) {
  50. args := (&HelmChart{
  51. ReleaseName: "external-secrets",
  52. Namespace: "external-secrets-system",
  53. }).uninstallArgs()
  54. if !contains(args, "--ignore-not-found") {
  55. t.Fatalf("expected uninstall args to include --ignore-not-found, got %v", args)
  56. }
  57. }
  58. func TestCleanupUninstallArgsOmitWait(t *testing.T) {
  59. args := (&HelmChart{
  60. ReleaseName: "external-secrets",
  61. Namespace: "external-secrets-system",
  62. }).cleanupUninstallArgs()
  63. if contains(args, "--wait") {
  64. t.Fatalf("expected stale release cleanup uninstall args to omit --wait, got %v", args)
  65. }
  66. if !contains(args, "--ignore-not-found") {
  67. t.Fatalf("expected stale release cleanup uninstall args to include --ignore-not-found, got %v", args)
  68. }
  69. }
  70. func TestIsHelmReleaseNameInUseError(t *testing.T) {
  71. if !isHelmReleaseNameInUseError("Error: INSTALLATION FAILED: cannot re-use a name that is still in use") {
  72. t.Fatal("expected stale release message to be detected")
  73. }
  74. if isHelmReleaseNameInUseError("release: not found") {
  75. t.Fatal("did not expect unrelated helm output to be detected as stale release state")
  76. }
  77. }
  78. func TestIsHelmReleaseNotFoundError(t *testing.T) {
  79. if !isHelmReleaseNotFoundError("Error: release: not found") {
  80. t.Fatal("expected missing release message to be detected")
  81. }
  82. if isHelmReleaseNotFoundError("STATUS: deployed") {
  83. t.Fatal("did not expect deployed release output to be treated as missing")
  84. }
  85. }
  86. func TestCanIgnoreHelmCleanupErrorWhenReleaseMissingAfterUninstallFailure(t *testing.T) {
  87. if !canIgnoreHelmCleanupError("Error: release: not found") {
  88. t.Fatal("expected cleanup error to be ignored when release status reports not found")
  89. }
  90. }
  91. func TestCanIgnoreHelmCleanupErrorWhenReleaseStillExists(t *testing.T) {
  92. if canIgnoreHelmCleanupError("NAME: external-secrets\nSTATUS: uninstalling") {
  93. t.Fatal("did not expect cleanup error to be ignored when release still exists")
  94. }
  95. }
  96. func contains(values []string, want string) bool {
  97. for _, value := range values {
  98. if value == want {
  99. return true
  100. }
  101. }
  102. return false
  103. }