Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Fix: Refactor

Daniel Hougaard3bcf406688b3
diff --git a/cli/test/helper.go b/cli/test/helper.go
index 912a3a71db..995367c4b1 100644
--- a/cli/test/helper.go
+++ b/cli/test/helper.go
@@ -1,26 +1,64 @@
package tests
-type Secret struct {
- Key string
- Value string
+import (
+ "fmt"
+ "os"
+ "os/exec"
+ "strings"
+ "testing"
+)
+
+const (
+ CLI_NAME = "infisical-merge"
+)
+
+var (
+ FORMATTED_CLI_NAME = fmt.Sprintf("./%s", CLI_NAME)
+)
+
+type Credentials struct {
+ ClientID string
+ ClientSecret string
+ UAAccessToken string
+ ServiceToken string
+ ProjectID string
+ EnvSlug string
+}
+
+var creds = Credentials{
+ UAAccessToken: "",
+ ClientID: os.Getenv("CLI_TESTS_UA_CLIENT_ID"),
+ ClientSecret: os.Getenv("CLI_TESTS_UA_CLIENT_SECRET"),
+ ServiceToken: os.Getenv("CLI_TESTS_SERVICE_TOKEN"),
+ ProjectID: os.Getenv("CLI_TESTS_PROJECT_ID"),
+ EnvSlug: os.Getenv("CLI_TESTS_ENV_SLUG"),
}
-func Map[T, U any](ts []T, f func(T) U) []U {
- us := make([]U, len(ts))
- for i := range ts {
- us[i] = f(ts[i])
+func ExecuteCliCommand(command string, args ...string) (string, error) {
+ cmd := exec.Command(command, args...)
+ output, err := cmd.CombinedOutput()
+ if err != nil {
+ return strings.TrimSpace(string(output)), err
}
- return us
+ return strings.TrimSpace(string(output)), nil
}
-func getSecretKeysAndValues(secrets []Secret) (keys []string, values []string) {
- secretKeys := []string{}
- secretValues := []string{}
+func SetupCli(t *testing.T) {
+
+ if creds.ClientID == "" || creds.ClientSecret == "" || creds.ServiceToken == "" || creds.ProjectID == "" || creds.EnvSlug == "" {
+ panic("Missing required environment variables")
+ }
+
+ // check if the CLI is already built, if not build it
+ alreadyBuilt := false
+ if _, err := os.Stat(FORMATTED_CLI_NAME); err == nil {
+ alreadyBuilt = true
+ }
- for _, secret := range secrets {
- secretKeys = append(secretKeys, secret.Key)
- secretValues = append(secretValues, secret.Value)
+ if !alreadyBuilt {
+ if err := exec.Command("go", "build", "../.").Run(); err != nil {
+ t.Fatal(err)
+ }
}
- return secretKeys, secretValues
}