-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_helpers_test.go
More file actions
53 lines (43 loc) · 1.35 KB
/
test_helpers_test.go
File metadata and controls
53 lines (43 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import "errors"
// stubRunnerWithOutput is a test stub that implements CommandRunner for testing executor actions.
type stubRunnerWithOutput struct {
stdout string
stderr string
exitCode int
err error
}
func (s *stubRunnerWithOutput) RunCommand(cmd string, useStdin bool, data any) error {
return s.err
}
func (s *stubRunnerWithOutput) RunCommandWithOutput(cmd string, useStdin bool, data any) (stdout, stderr string, exitCode int, err error) {
return s.stdout, s.stderr, s.exitCode, s.err
}
// stubRunnerWithMultipleOutputs は複数のコマンド実行に対して順番に異なる出力を返すstub
type stubRunnerWithMultipleOutputs struct {
outputs []string
index int
}
func (s *stubRunnerWithMultipleOutputs) RunCommand(cmd string, useStdin bool, data any) error {
return nil
}
func (s *stubRunnerWithMultipleOutputs) RunCommandWithOutput(cmd string, useStdin bool, data any) (stdout, stderr string, exitCode int, err error) {
if s.index >= len(s.outputs) {
return "", "", 1, errors.New("no more outputs configured")
}
output := s.outputs[s.index]
s.index++
return output, "", 0, nil
}
// Helper function to create *bool
func boolPtr(b bool) *bool {
return &b
}
// Helper function to create *string
func stringPtr(s string) *string {
return &s
}
// Helper function to create *int
func intPtr(i int) *int {
return &i
}