From cf9169ad6feace705296f6f635209d25cde00b61 Mon Sep 17 00:00:00 2001 From: Sheen Capadngan Date: Tue, 11 Jun 2024 03:37:51 +0800 Subject: [PATCH] test: resolved test issues --- cli/scripts/export_test_env.sh | 9 +++++---- cli/test/login_test.go | 21 ++++++++------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/cli/scripts/export_test_env.sh b/cli/scripts/export_test_env.sh index 08b5ad41b1..0b242281d9 100644 --- a/cli/scripts/export_test_env.sh +++ b/cli/scripts/export_test_env.sh @@ -9,14 +9,15 @@ if [ ! -f "$TEST_ENV_FILE" ]; then fi # Export the variables -while IFS='=' read -r key value +while IFS= read -r line do # Skip empty lines and lines starting with # - if [[ -z "$key" || "$key" =~ ^\# ]]; then + if [[ -z "$line" || "$line" =~ ^\# ]]; then continue fi - # Use eval to correctly handle values with spaces - eval export $key='$value' + # Read the key-value pair + IFS='=' read -r key value <<< "$line" + eval export $key=\$value done < "$TEST_ENV_FILE" echo "Test environment variables set." diff --git a/cli/test/login_test.go b/cli/test/login_test.go index 1ee9d50a4f..71273a3ec7 100644 --- a/cli/test/login_test.go +++ b/cli/test/login_test.go @@ -77,22 +77,19 @@ func UserLoginCmd() { n, err := ptmx.Read(buf) if n > 0 { terminalOut := string(buf) - if strings.Contains(terminalOut, "Add a new account") && step < 0 { - step += 1 - stepChan <- step - } else if strings.Contains(terminalOut, "Infisical Cloud") && step < 1 { + if strings.Contains(terminalOut, "Infisical Cloud") && step < 0 { step += 1; stepChan <- step - } else if strings.Contains(terminalOut, "Email") && step < 2 { + } else if strings.Contains(terminalOut, "Email") && step < 1 { step += 1; stepChan <- step - } else if strings.Contains(terminalOut, "Password") && step < 3 { + } else if strings.Contains(terminalOut, "Password") && step < 2 { step += 1; stepChan <- step - } else if strings.Contains(terminalOut, "Infisical organization") && step < 4 { + } else if strings.Contains(terminalOut, "Infisical organization") && step < 3 { step += 1; stepChan <- step - } else if strings.Contains(terminalOut, "Enter passphrase") && step < 5 { + } else if strings.Contains(terminalOut, "Enter passphrase") && step < 4 { step += 1; stepChan <- step } @@ -106,17 +103,15 @@ func UserLoginCmd() { for i := range stepChan { switch i { - case 0: + case 0: ptmx.Write([]byte("\n")) case 1: - ptmx.Write([]byte("\n")) - case 2: ptmx.Write([]byte(creds.UserEmail)) ptmx.Write([]byte("\n")) - case 3: + case 2: ptmx.Write([]byte(creds.UserPassword)) ptmx.Write([]byte("\n")) - case 4: + case 3: ptmx.Write([]byte("\n")) } }