Просмотр исходного кода

test: fix helm dependency ensure linting

Signed-off-by: Moritz Johner <beller.moritz@googlemail.com>
Moritz Johner 2 месяцев назад
Родитель
Сommit
fa7805997a
1 измененных файлов с 42 добавлено и 3 удалено
  1. 42 3
      hack/helm_dependency_ensure_test.go

+ 42 - 3
hack/helm_dependency_ensure_test.go

@@ -1,6 +1,23 @@
+/*
+Copyright © The ESO Authors
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    https://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
 package hack
 
 import (
+	"fmt"
 	"os"
 	"os/exec"
 	"path/filepath"
@@ -12,7 +29,7 @@ func TestHelmDependencyEnsureSkipsBuildWhenDependenciesAreReady(t *testing.T) {
 
 	workdir := t.TempDir()
 	marker := filepath.Join(workdir, "build-called")
-	fakeHelm := writeFakeHelm(t, workdir, "#!/usr/bin/env bash\nset -euo pipefail\n\nif [[ \"$1\" == \"dependency\" && \"$2\" == \"list\" ]]; then\n  cat <<'EOF'\nNAME                \tVERSION\tREPOSITORY                           \tSTATUS\nbitwarden-sdk-server\tv0.5.2 \toci://ghcr.io/external-secrets/charts\tok\nEOF\n  exit 0\nfi\n\nif [[ \"$1\" == \"dependency\" && \"$2\" == \"build\" ]]; then\n  touch \""+marker+"\"\n  exit 0\nfi\n\necho \"unexpected helm invocation: $*\" >&2\nexit 1\n")
+	fakeHelm := writeFakeHelm(t, workdir, fakeHelmScript("v0.5.2", "ok", marker))
 
 	cmd := exec.Command("bash", "helm.dependency.ensure.sh", "deploy/charts/external-secrets")
 	cmd.Dir = "."
@@ -32,7 +49,7 @@ func TestHelmDependencyEnsureSkipsBuildWhenDependenciesAreUnpacked(t *testing.T)
 
 	workdir := t.TempDir()
 	marker := filepath.Join(workdir, "build-called")
-	fakeHelm := writeFakeHelm(t, workdir, "#!/usr/bin/env bash\nset -euo pipefail\n\nif [[ \"$1\" == \"dependency\" && \"$2\" == \"list\" ]]; then\n  cat <<'EOF'\nNAME                \tVERSION\tREPOSITORY                           \tSTATUS\nbitwarden-sdk-server\tv0.6.0 \toci://ghcr.io/external-secrets/charts\tunpacked\nEOF\n  exit 0\nfi\n\nif [[ \"$1\" == \"dependency\" && \"$2\" == \"build\" ]]; then\n  touch \""+marker+"\"\n  exit 0\nfi\n\necho \"unexpected helm invocation: $*\" >&2\nexit 1\n")
+	fakeHelm := writeFakeHelm(t, workdir, fakeHelmScript("v0.6.0", "unpacked", marker))
 
 	cmd := exec.Command("bash", "helm.dependency.ensure.sh", "deploy/charts/external-secrets")
 	cmd.Dir = "."
@@ -52,7 +69,7 @@ func TestHelmDependencyEnsureBuildsWhenDependenciesAreMissing(t *testing.T) {
 
 	workdir := t.TempDir()
 	marker := filepath.Join(workdir, "build-called")
-	fakeHelm := writeFakeHelm(t, workdir, "#!/usr/bin/env bash\nset -euo pipefail\n\nif [[ \"$1\" == \"dependency\" && \"$2\" == \"list\" ]]; then\n  cat <<'EOF'\nNAME                \tVERSION\tREPOSITORY                           \tSTATUS\nbitwarden-sdk-server\tv0.5.2 \toci://ghcr.io/external-secrets/charts\tmissing\nEOF\n  exit 0\nfi\n\nif [[ \"$1\" == \"dependency\" && \"$2\" == \"build\" ]]; then\n  touch \""+marker+"\"\n  exit 0\nfi\n\necho \"unexpected helm invocation: $*\" >&2\nexit 1\n")
+	fakeHelm := writeFakeHelm(t, workdir, fakeHelmScript("v0.5.2", "missing", marker))
 
 	cmd := exec.Command("bash", "helm.dependency.ensure.sh", "deploy/charts/external-secrets")
 	cmd.Dir = "."
@@ -77,3 +94,25 @@ func writeFakeHelm(t *testing.T, dir, content string) string {
 
 	return path
 }
+
+func fakeHelmScript(version, status, marker string) string {
+	return fmt.Sprintf(`#!/usr/bin/env bash
+set -euo pipefail
+
+if [[ "$1" == "dependency" && "$2" == "list" ]]; then
+  cat <<'EOF'
+NAME                	VERSION	REPOSITORY                           	STATUS
+bitwarden-sdk-server	%s	oci://ghcr.io/external-secrets/charts	%s
+EOF
+  exit 0
+fi
+
+if [[ "$1" == "dependency" && "$2" == "build" ]]; then
+  touch %q
+  exit 0
+fi
+
+echo "unexpected helm invocation: $*" >&2
+exit 1
+`, version, status, marker)
+}