mirror of
https://github.com/Infisical/infisical.git
synced 2026-01-09 15:38:03 -05:00
Fix: Refactor
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
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])
|
||||
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 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) {
|
||||
|
||||
for _, secret := range secrets {
|
||||
secretKeys = append(secretKeys, secret.Key)
|
||||
secretValues = append(secretValues, secret.Value)
|
||||
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
|
||||
}
|
||||
|
||||
if !alreadyBuilt {
|
||||
if err := exec.Command("go", "build", "../.").Run(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
return secretKeys, secretValues
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user