mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 06:28:11 +00:00
Fix: Refactor
This commit is contained in:
+53
-15
@@ -1,26 +1,64 @@
|
|||||||
package tests
|
package tests
|
||||||
|
|
||||||
type Secret struct {
|
import (
|
||||||
Key string
|
"fmt"
|
||||||
Value string
|
"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
|
||||||
}
|
}
|
||||||
|
|
||||||
func Map[T, U any](ts []T, f func(T) U) []U {
|
var creds = Credentials{
|
||||||
us := make([]U, len(ts))
|
UAAccessToken: "",
|
||||||
for i := range ts {
|
ClientID: os.Getenv("CLI_TESTS_UA_CLIENT_ID"),
|
||||||
us[i] = f(ts[i])
|
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 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) {
|
func SetupCli(t *testing.T) {
|
||||||
secretKeys := []string{}
|
|
||||||
secretValues := []string{}
|
|
||||||
|
|
||||||
for _, secret := range secrets {
|
if creds.ClientID == "" || creds.ClientSecret == "" || creds.ServiceToken == "" || creds.ProjectID == "" || creds.EnvSlug == "" {
|
||||||
secretKeys = append(secretKeys, secret.Key)
|
panic("Missing required environment variables")
|
||||||
secretValues = append(secretValues, secret.Value)
|
}
|
||||||
|
|
||||||
|
// check if the CLI is already built, if not build it
|
||||||
|
alreadyBuilt := false
|
||||||
|
if _, err := os.Stat(FORMATTED_CLI_NAME); err == nil {
|
||||||
|
alreadyBuilt = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if !alreadyBuilt {
|
||||||
|
if err := exec.Command("go", "build", "../.").Run(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return secretKeys, secretValues
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user