Fix: Run cmd tests

This commit is contained in:
Daniel Hougaard
2024-04-22 15:27:42 +02:00
parent eb5f71cb05
commit 35071af478

View File

@@ -1,6 +1,7 @@
package tests
import (
"bytes"
"fmt"
"testing"
@@ -12,12 +13,13 @@ func TestServiceToken_RunCmdRecursiveAndImports(t *testing.T) {
output, err := ExecuteCliCommand(FORMATTED_CLI_NAME, "run", "--token", creds.ServiceToken, "--projectId", creds.ProjectID, "--env", creds.EnvSlug, "--recursive", "--silent", "--", "echo", "hello world")
fmt.Printf("output: %v\n", output)
if err != nil {
t.Fatalf("error running CLI command: %v", err)
}
output = string(bytes.Split([]byte(output), []byte("INF"))[1])
fmt.Printf("output: %v\n", output)
// Use cupaloy to snapshot test the output
err = cupaloy.Snapshot(output)
if err != nil {
@@ -29,12 +31,13 @@ func TestServiceToken_RunCmdWithImports(t *testing.T) {
output, err := ExecuteCliCommand(FORMATTED_CLI_NAME, "run", "--token", creds.ServiceToken, "--projectId", creds.ProjectID, "--env", creds.EnvSlug, "--silent", "--", "echo", "hello world")
fmt.Printf("output: %v\n", output)
if err != nil {
t.Fatalf("error running CLI command: %v", err)
}
output = string(bytes.Split([]byte(output), []byte("INF"))[1])
fmt.Printf("output: %v\n", output)
// Use cupaloy to snapshot test the output
err = cupaloy.Snapshot(output)
if err != nil {
@@ -48,12 +51,13 @@ func TestUniversalAuth_RunCmdRecursiveAndImports(t *testing.T) {
output, err := ExecuteCliCommand(FORMATTED_CLI_NAME, "run", "--token", creds.UAAccessToken, "--projectId", creds.ProjectID, "--env", creds.EnvSlug, "--recursive", "--silent", "--", "echo", "hello world")
fmt.Printf("output: %v\n", output)
if err != nil {
t.Fatalf("error running CLI command: %v", err)
}
output = string(bytes.Split([]byte(output), []byte("INF"))[1])
fmt.Printf("output: %v\n", output)
// Use cupaloy to snapshot test the output
err = cupaloy.Snapshot(output)
if err != nil {
@@ -67,12 +71,14 @@ func TestUniversalAuth_RunCmdWithImports(t *testing.T) {
output, err := ExecuteCliCommand(FORMATTED_CLI_NAME, "run", "--token", creds.UAAccessToken, "--projectId", creds.ProjectID, "--env", creds.EnvSlug, "--silent", "--", "echo", "hello world")
fmt.Printf("output: %v\n", output)
if err != nil {
t.Fatalf("error running CLI command: %v", err)
}
// remove the first few characters from the output because we don't care about the time, and it will change every time
output = string(bytes.Split([]byte(output), []byte("INF"))[1])
fmt.Printf("output: %v\n", output)
// Use cupaloy to snapshot test the output
err = cupaloy.Snapshot(output)
if err != nil {
@@ -86,12 +92,13 @@ func TestUniversalAuth_RunCmdWithoutImports(t *testing.T) {
output, err := ExecuteCliCommand(FORMATTED_CLI_NAME, "run", "--token", creds.UAAccessToken, "--projectId", creds.ProjectID, "--env", creds.EnvSlug, "--silent", "--include-imports=false", "--", "echo", "hello world")
fmt.Printf("output: %v\n", output)
if err != nil {
t.Fatalf("error running CLI command: %v", err)
}
output = string(bytes.Split([]byte(output), []byte("INF"))[1])
fmt.Printf("output: %v\n", output)
// Use cupaloy to snapshot test the output
err = cupaloy.Snapshot(output)
if err != nil {
@@ -104,12 +111,14 @@ func TestServiceToken_RunCmdWithoutImports(t *testing.T) {
output, err := ExecuteCliCommand(FORMATTED_CLI_NAME, "run", "--token", creds.ServiceToken, "--projectId", creds.ProjectID, "--env", creds.EnvSlug, "--silent", "--include-imports=false", "--", "echo", "hello world")
fmt.Printf("output: %v\n", output)
if err != nil {
t.Fatalf("error running CLI command: %v", err)
}
// Remove everything before "INF" because it's not relevant to the test
output = string(bytes.Split([]byte(output), []byte("INF"))[1])
fmt.Printf("output: %v\n", output)
// Use cupaloy to snapshot test the output
err = cupaloy.Snapshot(output)
if err != nil {