Skip to content

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

Feat: CLI Integration Tests

Daniel Hougaard1dd0167ac8ea
diff --git a/cli/test/secrets_by_name_test.go b/cli/test/secrets_by_name_test.go
new file mode 100644
index 0000000000..bd86749b65
--- /dev/null
+++ b/cli/test/secrets_by_name_test.go
@@ -0,0 +1,119 @@
+package tests
+
+import (
+ "fmt"
+ "testing"
+
+ "github.com/bradleyjkemp/cupaloy/v2"
+)
+
+func TestServiceToken_GetSecretsByNameRecursive(t *testing.T) {
+ SetupCli(t)
+
+ output, err := ExecuteCliCommand(FORMATTED_CLI_NAME, "secrets", "get", "TEST-SECRET-1", "TEST-SECRET-2", "FOLDER-SECRET-1", "--token", creds.ServiceToken, "--projectId", creds.ProjectID, "--env", creds.EnvSlug, "--recursive", "--silent")
+
+ fmt.Printf("output: %v\n", output)
+
+ if err != nil {
+ t.Fatalf("error running CLI command: %v", err)
+ }
+
+ // Use cupaloy to snapshot test the output
+ err = cupaloy.Snapshot(output)
+ if err != nil {
+ t.Fatalf("snapshot failed: %v", err)
+ }
+}
+
+func TestServiceToken_GetSecretsByNameWithNotFoundSecret(t *testing.T) {
+ SetupCli(t)
+
+ output, err := ExecuteCliCommand(FORMATTED_CLI_NAME, "secrets", "get", "TEST-SECRET-1", "TEST-SECRET-2", "FOLDER-SECRET-1", "DOES-NOT-EXIST", "--token", creds.ServiceToken, "--projectId", creds.ProjectID, "--env", creds.EnvSlug, "--recursive", "--silent")
+
+ fmt.Printf("output: %v\n", output)
+
+ if err != nil {
+ t.Fatalf("error running CLI command: %v", err)
+ }
+
+ // Use cupaloy to snapshot test the output
+ err = cupaloy.Snapshot(output)
+ if err != nil {
+ t.Fatalf("snapshot failed: %v", err)
+ }
+}
+
+func TestServiceToken_GetSecretsByNameWithImports(t *testing.T) {
+ SetupCli(t)
+
+ output, err := ExecuteCliCommand(FORMATTED_CLI_NAME, "secrets", "get", "TEST-SECRET-1", "STAGING-SECRET-2", "FOLDER-SECRET-1", "--token", creds.ServiceToken, "--projectId", creds.ProjectID, "--env", creds.EnvSlug, "--recursive", "--silent")
+
+ fmt.Printf("output: %v\n", output)
+
+ if err != nil {
+ t.Fatalf("error running CLI command: %v", err)
+ }
+
+ // Use cupaloy to snapshot test the output
+ err = cupaloy.Snapshot(output)
+ if err != nil {
+ t.Fatalf("snapshot failed: %v", err)
+ }
+}
+
+func TestUniversalAuth_GetSecretsByNameRecursive(t *testing.T) {
+ MachineIdentityLoginCmd(t)
+ SetupCli(t)
+
+ output, err := ExecuteCliCommand(FORMATTED_CLI_NAME, "secrets", "get", "TEST-SECRET-1", "TEST-SECRET-2", "FOLDER-SECRET-1", "--token", creds.UAAccessToken, "--projectId", creds.ProjectID, "--env", creds.EnvSlug, "--recursive", "--silent")
+
+ fmt.Printf("output: %v\n", output)
+
+ if err != nil {
+ t.Fatalf("error running CLI command: %v", err)
+ }
+
+ // Use cupaloy to snapshot test the output
+ err = cupaloy.Snapshot(output)
+ if err != nil {
+ t.Fatalf("snapshot failed: %v", err)
+ }
+}
+
+func TestUniversalAuth_GetSecretsByNameWithNotFoundSecret(t *testing.T) {
+ MachineIdentityLoginCmd(t)
+ SetupCli(t)
+
+ output, err := ExecuteCliCommand(FORMATTED_CLI_NAME, "secrets", "get", "TEST-SECRET-1", "TEST-SECRET-2", "FOLDER-SECRET-1", "DOES-NOT-EXIST", "--token", creds.UAAccessToken, "--projectId", creds.ProjectID, "--env", creds.EnvSlug, "--recursive", "--silent")
+
+ fmt.Printf("output: %v\n", output)
+
+ if err != nil {
+ t.Fatalf("error running CLI command: %v", err)
+ }
+
+ // Use cupaloy to snapshot test the output
+ err = cupaloy.Snapshot(output)
+ if err != nil {
+ t.Fatalf("snapshot failed: %v", err)
+ }
+}
+
+func TestUniversalAuth_GetSecretsByNameWithImports(t *testing.T) {
+ MachineIdentityLoginCmd(t)
+ SetupCli(t)
+
+ output, err := ExecuteCliCommand(FORMATTED_CLI_NAME, "secrets", "get", "TEST-SECRET-1", "STAGING-SECRET-2", "FOLDER-SECRET-1", "--token", creds.UAAccessToken, "--projectId", creds.ProjectID, "--env", creds.EnvSlug, "--recursive", "--silent")
+
+ fmt.Printf("output: %v\n", output)
+
+ if err != nil {
+ t.Fatalf("error running CLI command: %v", err)
+ }
+
+ // Use cupaloy to snapshot test the output
+ err = cupaloy.Snapshot(output)
+ if err != nil {
+ t.Fatalf("snapshot failed: %v", err)
+ }
+}