-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_test.go
70 lines (57 loc) · 1.29 KB
/
task_test.go
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package iapetus
import (
"errors"
"testing"
)
func TestIntegrationTest_Run(t *testing.T) {
test := &Task{
Command: "echo",
Args: []string{"Hello, World!"},
}
err := test.Run()
if err != nil {
t.Fatalf("expected no error, got %v", err)
}
if test.Actual.Output != "Hello, World!\n" {
t.Errorf("expected output 'Hello, World!', got %v", test.Actual.Output)
}
}
func TestIntegrationTest_AddAssertion(t *testing.T) {
test := &Task{}
assertion := func(i *Task) error {
return nil
}
test.AddAssertion(assertion)
if len(test.Asserts) != 1 {
t.Errorf("expected 1 assertion, got %d", len(test.Asserts))
}
}
func TestIntegrationTest_AddMultipleAssertions(t *testing.T) {
test := &Task{}
assertion1 := func(i *Task) error {
return nil
}
assertion2 := func(i *Task) error {
return errors.New("failed assertion")
}
test.AddAssertion(assertion1)
test.AddAssertion(assertion2)
if len(test.Asserts) != 2 {
t.Errorf("expected 2 assertions, got %d", len(test.Asserts))
}
}
func TestIntegrationTest_RunCommandError(t *testing.T) {
test := &Task{
Command: "invalid_command",
Expected: Output{
ExitCode: 1,
},
Asserts: []func(*Task) error{
AssertByExitCode,
},
}
err := test.Run()
if err == nil {
t.Fatalf("expected error for invalid command, got nil")
}
}