Skip to content

Commit 757e095

Browse files
committed
make dispatch run work without dispatch login
1 parent cf37e41 commit 757e095

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

cli/run_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestRunCommand(t *testing.T) {
4545

4646
result, found := findEnvVariableInLogs(&buff)
4747
if !found {
48-
t.Fatal("Expected printenv in the output")
48+
t.Fatalf("Expected printenv in the output: %s", buff.String())
4949
}
5050
assert.Equal(t, "rick_sanchez", result, fmt.Sprintf("Expected 'printenv | rick_sanchez' in the output, got 'printenv | %s'", result))
5151
})
@@ -63,7 +63,7 @@ func TestRunCommand(t *testing.T) {
6363

6464
result, found := findEnvVariableInLogs(&buff)
6565
if !found {
66-
t.Fatal("Expected printenv in the output")
66+
t.Fatalf("Expected printenv in the output: %s", buff.String())
6767
}
6868
assert.Equal(t, "morty_smith", result, fmt.Sprintf("Expected 'printenv | morty_smith' in the output, got 'printenv | %s'", result))
6969
})
@@ -86,7 +86,7 @@ func TestRunCommand(t *testing.T) {
8686

8787
result, found := findEnvVariableInLogs(&buff)
8888
if !found {
89-
t.Fatal("Expected printenv in the output")
89+
t.Fatalf("Expected printenv in the output: %s", buff.String())
9090
}
9191
assert.Equal(t, "morty_smith", result, fmt.Sprintf("Expected 'printenv | morty_smith' in the output, got 'printenv | %s'", result))
9292
})
@@ -111,7 +111,7 @@ func TestRunCommand(t *testing.T) {
111111

112112
result, found := findEnvVariableInLogs(&buff)
113113
if !found {
114-
t.Fatal("Expected printenv in the output")
114+
t.Fatalf("Expected printenv in the output: %s\n\n", buff.String())
115115
}
116116
assert.Equal(t, "morty_smith", result, fmt.Sprintf("Expected 'printenv | morty_smith' in the output, got 'printenv | %s'", result))
117117
})
@@ -122,6 +122,9 @@ func execRunCommand(envVars *[]string, arg ...string) (bytes.Buffer, string, err
122122
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
123123
defer cancel()
124124

125+
// add the api key to the arguments so the command can run without `dispatch login` being run first
126+
arg = append(arg[:1], append([]string{"--api-key", "00000000"}, arg[1:]...)...)
127+
125128
// Set up the command
126129
cmd := exec.CommandContext(ctx, dispatchBinary, arg...)
127130

@@ -137,7 +140,6 @@ func execRunCommand(envVars *[]string, arg ...string) (bytes.Buffer, string, err
137140
// Start the command
138141
if err := cmd.Start(); err != nil {
139142
return errBuf, "Failed to start command: &v", err
140-
// t.Fatalf("Failed to start command: %v", err)
141143
}
142144

143145
// Wait for the command to finish or for the context to timeout
@@ -157,12 +159,12 @@ func createEnvFile(path string, content []byte) (string, error) {
157159
return envFile, err
158160
}
159161

160-
func findEnvVariableInLogs(errBuf *bytes.Buffer) (string, bool) {
162+
func findEnvVariableInLogs(buf *bytes.Buffer) (string, bool) {
161163
var result string
162164
found := false
163165

164166
// Split the log into lines
165-
lines := strings.Split(errBuf.String(), "\n")
167+
lines := strings.Split(buf.String(), "\n")
166168

167169
// Iterate over each line and check for the condition
168170
for _, line := range lines {

0 commit comments

Comments
 (0)