chart_test.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 TestIsHelmReleaseNameInUseError(t *testing.T) {
  59. if !isHelmReleaseNameInUseError("Error: INSTALLATION FAILED: cannot re-use a name that is still in use") {
  60. t.Fatal("expected stale release message to be detected")
  61. }
  62. if isHelmReleaseNameInUseError("release: not found") {
  63. t.Fatal("did not expect unrelated helm output to be detected as stale release state")
  64. }
  65. }
  66. func contains(values []string, want string) bool {
  67. for _, value := range values {
  68. if value == want {
  69. return true
  70. }
  71. }
  72. return false
  73. }