-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathlocal_executor_test.go
More file actions
70 lines (59 loc) · 1.42 KB
/
local_executor_test.go
File metadata and controls
70 lines (59 loc) · 1.42 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package runtime
import (
"fmt"
"runtime"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRuntime_WithEnvVariables(t *testing.T) {
envVar := "$KEY"
if runtime.GOOS == "windows" {
envVar = "%KEY%"
}
s := TestCase{
Command: CommandUnderTest{
Cmd: fmt.Sprintf("echo %s", envVar),
Timeout: "2s",
Env: map[string]string{"KEY": "value"},
},
Expected: Expected{
Stdout: ExpectedOut{
Contains: []string{"value"},
},
ExitCode: 0,
},
Title: "Output env variable",
}
e := LocalExecutor{}
got, err := e.Execute(s)
assert.NoError(t, err)
assert.True(t, got.ValidationResult.Success)
}
func Test_runTestShouldReturnError(t *testing.T) {
test := TestCase{
Command: CommandUnderTest{
Cmd: "pwd",
Dir: "/home/invalid",
},
}
e := LocalExecutor{}
got, err := e.Execute(test)
assert.NoError(t, err)
if runtime.GOOS == "windows" {
assert.Contains(t, got.TestCase.Result.Error.Error(), "chdir /home/invalid")
} else {
assert.Equal(t, "chdir /home/invalid: no such file or directory", got.TestCase.Result.Error.Error())
}
}
func TestRuntime_WithInvalidDuration(t *testing.T) {
test := TestCase{
Command: CommandUnderTest{
Cmd: "echo test",
Timeout: "600lightyears",
},
}
e := LocalExecutor{}
got, err := e.Execute(test)
assert.NoError(t, err)
assert.Equal(t, `time: unknown unit "lightyears" in duration "600lightyears"`, got.TestCase.Result.Error.Error())
}