forked from wagoodman/bashful
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_test.go
97 lines (79 loc) · 2.71 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"strings"
"testing"
"github.com/alecthomas/repr"
)
func TestTaskString(t *testing.T) {
var testOutput, expectedOutput string
taskConfig := TaskConfig{
Name: "some name!",
CmdString: "/bin/true",
}
task := NewTask(taskConfig, 1, "2")
task.Display.Values = LineInfo{Status: statusSuccess.Color(""), Title: task.Config.Name, Msg: "some message", Prefix: "$", Eta: "SOMEETAVALUE"}
testOutput = task.String(50)
expectedOutput = " \x1b[38;5;10m \x1b[0m • some name! som...SOMEETAVALUE"
if expectedOutput != testOutput {
t.Error("TestTaskString (default): Expected", repr.String(expectedOutput), "got", repr.String(testOutput))
}
config.Options.ShowTaskEta = false
task.Display.Values.Title = "123456789qwertyuiopasdfghjklzxcvbnm234567890qwertyuiopasdfghjklzxcvbnm123456789qwertyuiopasdfghjklzxcvbnm234567890qwertyuiopasdfghjklzxcvbnm"
testOutput = task.String(20)
expectedOutput = " \x1b[38;5;10m \x1b[0m • 123456789qwertyuiopasdfghjklzxcvbnm234567890qwertyuiopasdfghjklzxcvbnm123456789qwertyuiopasdfghjklzxcvbnm234567890qwertyuiopasdfghjklzxcvbnm s...SOMEETAVALUE"
if expectedOutput != testOutput {
t.Error("TestTaskString (eta, truncate): Expected", repr.String(expectedOutput), "got", repr.String(testOutput))
}
}
func TestSerialTaskEnvPersistence(t *testing.T) {
var expStr, actStr string
var failedTasks []*Task
simpleYamlStr := `
tasks:
- name: start
cmd: export SOMEVAR=this
- name: append 'is'
cmd: export SOMEVAR=$SOMEVAR:is
- name: append 'DONTDOIT'
parallel-tasks:
- cmd: export SOMEVAR=$SOMEVAR:DONTDOIT
- name: append '<replace>'
cmd: export SOMEVAR=$SOMEVAR:<replace>
for-each:
- working
- just
- name: append 'is'
cmd: eval 'export SOMEVAR=$SOMEVAR:fine'
`
environment := map[string]string{}
config.Options.StopOnFailure = false
failedTasks = run([]byte(simpleYamlStr), environment)
if len(failedTasks) > 0 {
t.Error("TestSerialTaskEnvPersistence: Expected no tasks to fail")
}
expStr, actStr = "this:is:working:just:fine", environment["SOMEVAR"]
if expStr != actStr {
t.Error("Expected", expStr, "got", actStr)
}
}
func TestCurrentWorkingDirectory(t *testing.T) {
var expStr, actStr string
var failedTasks []*Task
simpleYamlStr := `
tasks:
- name: start
cmd: export CWD=$(pwd)
cwd: ./example
`
environment := map[string]string{}
config.Options.StopOnFailure = false
failedTasks = run([]byte(simpleYamlStr), environment)
if len(failedTasks) > 0 {
t.Error("TestSerialTaskEnvPersistence: Expected no tasks to fail")
}
cwd := strings.Split(environment["CWD"], "/")
expStr, actStr = "example", cwd[len(cwd)-1]
if expStr != actStr {
t.Error("Expected", expStr, "got", actStr)
}
}