diff --git a/cli/test/login.go b/cli/test/login.go deleted file mode 100644 index 0f4591413..000000000 --- a/cli/test/login.go +++ /dev/null @@ -1,29 +0,0 @@ -package tests - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func MachineIdentityLoginCmd(t *testing.T) { - SetupCli(t) - - if creds.UAAccessToken != "" { - return - } - - jwtPattern := `^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$` - - output, err := ExecuteCliCommand(FORMATTED_CLI_NAME, "login", "--method=universal-auth", "--client-id", creds.ClientID, "--client-secret", creds.ClientSecret, "--plain", "--silent") - - if err != nil { - t.Fatalf("error running CLI command: %v", err) - } - - assert.Regexp(t, jwtPattern, output) - - creds.UAAccessToken = output - - // We can't use snapshot testing here because the output will be different every time -} diff --git a/cli/test/login_test.go b/cli/test/login_test.go index 1d598153a..0f4591413 100644 --- a/cli/test/login_test.go +++ b/cli/test/login_test.go @@ -1,43 +1,29 @@ package tests import ( - "bytes" - "fmt" - "regexp" "testing" - "github.com/Infisical/infisical-merge/packages/cmd" "github.com/stretchr/testify/assert" ) -func UALoginCmd(t *testing.T) { - jwtPattern := `^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$` +func MachineIdentityLoginCmd(t *testing.T) { + SetupCli(t) - rootCommand := cmd.NewRootCmd() - - commandOutput := new(bytes.Buffer) - errorOutput := new(bytes.Buffer) - rootCommand.SetOut(commandOutput) - rootCommand.SetErr(errorOutput) - - args := []string{ - "login", + if creds.UAAccessToken != "" { + return } - args = append(args, fmt.Sprintf("--method=%s", "universal-auth")) - args = append(args, fmt.Sprintf("--client-id=%s", creds.ClientID)) - args = append(args, fmt.Sprintf("--client-secret=%s", creds.ClientSecret)) + jwtPattern := `^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$` - rootCommand.SetArgs(args) - rootCommand.Execute() + output, err := ExecuteCliCommand(FORMATTED_CLI_NAME, "login", "--method=universal-auth", "--client-id", creds.ClientID, "--client-secret", creds.ClientSecret, "--plain", "--silent") - token := commandOutput.String() + if err != nil { + t.Fatalf("error running CLI command: %v", err) + } - // We do a match and compare it against true, instead of using assert.Regexp. - // If the assertion fails, we would be able to see the potential token that was generated in the output console, which would be bad if running in a CI/CD pipeline. - match, err := regexp.MatchString(jwtPattern, token) - assert.Nil(t, err) - assert.True(t, match, "The token does not match the pattern") + assert.Regexp(t, jwtPattern, output) - creds.UAAccessToken = token + creds.UAAccessToken = output + + // We can't use snapshot testing here because the output will be different every time }