From 1e5b1e3c269d4a38c986bdfec8dbd69456de79c2 Mon Sep 17 00:00:00 2001
From: Timo Furrer <tfurrer@gitlab.com>
Date: Wed, 15 May 2024 07:03:16 +0200
Subject: [PATCH] Mock CI_SERVER_HOST predefined env variable for unit test

This change set mocks the CI_SERVER_HOST predefined environment variable
with a deterministic value in the unit tests.
This is necessary so that the unit tests run on self-managed.

Changelog: fixed
---
 tests/unit.gitlab-ci.yml | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/tests/unit.gitlab-ci.yml b/tests/unit.gitlab-ci.yml
index e307e3d..7490a01 100644
--- a/tests/unit.gitlab-ci.yml
+++ b/tests/unit.gitlab-ci.yml
@@ -160,10 +160,13 @@ gitlab-tofu-init-with-prepared-registry-token:
     - |
       cat <<'EOF' > test.sh
       set -x
-      export TF_TOKEN_gitlab_com=mysecrettoken
+      # NOTE: as part of the tst fixture, we need to overwrite the CI_SERVER_HOST,
+      # so that this test also properly works on GitLab self-managed.
+      export CI_SERVER_HOST=gitlab.example.com
+      export TF_TOKEN_gitlab_example_com=mysecrettoken
       . $(which gitlab-tofu)
       terraform_authenticate_private_registry
-      test "$TF_TOKEN_gitlab_com" = "mysecrettoken"
+      test "$TF_TOKEN_gitlab_example_com" = "mysecrettoken"
       EOF
     - $SHELL test.sh
   parallel:
@@ -186,9 +189,12 @@ gitlab-tofu-init-without-prepared-registry-token:
     - |
       cat <<'EOF' > test.sh
       set -x
+      # NOTE: as part of the tst fixture, we need to overwrite the CI_SERVER_HOST,
+      # so that this test also properly works on GitLab self-managed.
+      export CI_SERVER_HOST=gitlab.example.com
       . $(which gitlab-tofu)
       terraform_authenticate_private_registry
-      test -n "$TF_TOKEN_gitlab_com"
+      test -n "$TF_TOKEN_gitlab_example_com"
       EOF
     - $SHELL test.sh
   parallel:
-- 
GitLab