This repository has been archived by the owner on Jul 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtask_test.go
67 lines (56 loc) · 1.8 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
package urknall
import (
"testing"
)
type vers struct {
Version string
}
func (v *vers) Render(Package) {
}
func TestTaskImpl(t *testing.T) {
reference := &vers{"1.2"}
i := &task{taskBuilder: reference, name: "base"}
i.Add("echo 1", "echo {{ .Version }}")
if cmds, err := i.Commands(); err != nil {
t.Errorf("didn't expect an error, got %q", err)
} else if len(cmds) != 2 {
t.Errorf("expected %d commands, got %q", 2, len(cmds))
}
if err := i.Compile(); err != nil {
t.Errorf("didn't expect an error, got %q", err)
}
if cmds, err := i.Commands(); err != nil {
t.Errorf("didn't expect an error, got %q", err)
} else if len(cmds) != 2 {
t.Errorf("expected %d commands, got %q", 2, len(cmds))
} else if cmds[0].Shell() != "echo 1" {
t.Errorf("expected command %d to be %q, got %q", 0, "echo 1", cmds[0])
} else if cmds[1].Shell() != "echo 1.2" {
t.Errorf("expected command %d to be %q, got %q", 1, "echo 1.2", cmds[1])
}
}
func TestInvalidTaskImpl(t *testing.T) {
reference := &struct {
genericPkg
Version string `urknall:"default=1.3"`
}{}
i := &task{taskBuilder: reference}
i.Add("echo 1", "echo {{ .Version }}")
if cmds, err := i.Commands(); err != nil {
t.Errorf("didn't expect an error, got %q", err)
} else if len(cmds) != 2 {
t.Errorf("expected %d commands, got %q", 2, len(cmds))
}
if err := i.Compile(); err != nil {
t.Errorf("didn't expect an error, got %q", err)
}
if cmds, err := i.Commands(); err != nil {
t.Errorf("didn't expect an error, got %q", err)
} else if len(cmds) != 2 {
t.Errorf("expected %d commands, got %q", 2, len(cmds))
} else if cmds[0].Shell() != "echo 1" {
t.Errorf("expected command %d to be %q, got %q", 0, "echo 1", cmds[0])
} else if cmds[1].Shell() != "echo 1.3" {
t.Errorf("expected command %d to be %q, got %q", 1, "echo 1.3", cmds[1])
}
}