-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtemplate_test.go
124 lines (90 loc) · 3.26 KB
/
template_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package wfl_test
import (
"github.com/dgruber/wfl"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"strconv"
"github.com/dgruber/drmaa2interface"
)
var _ = Describe("Template", func() {
var jt drmaa2interface.JobTemplate
// itr increments the number in the first argument for the job by one
itr := func(t drmaa2interface.JobTemplate) drmaa2interface.JobTemplate {
if len(t.Args) == 0 {
t.Args = []string{"0"}
} else {
i, err := strconv.Atoi(t.Args[0])
if err != nil {
t.Args = []string{"0"}
} else {
i++
t.Args[0] = strconv.Itoa(i)
}
}
return t
}
rmt := func(t drmaa2interface.JobTemplate) drmaa2interface.JobTemplate {
t.RemoteCommand = "rmt"
return t
}
Context("happy path", func() {
BeforeEach(func() {
jt = drmaa2interface.JobTemplate{
RemoteCommand: "test",
Args: []string{"0"},
}
})
It("should create JobTemplates when no Iterator or Mapping function is registered", func() {
template := wfl.NewTemplate(jt)
Ω(template).ShouldNot(BeNil())
njt := template.Next()
Ω(njt.RemoteCommand).Should(Equal("test"))
Ω(template.Next().RemoteCommand).Should(Equal("test"))
Ω(template.Next().RemoteCommand).Should(Equal("test"))
})
It("should apply a registered Iterator when Next is called", func() {
template := wfl.NewTemplate(jt)
Ω(template).ShouldNot(BeNil())
Ω(template.Next().Args[0]).Should(Equal("0"))
template.AddIterator("test", itr)
Ω(template.Next().Args[0]).Should(Equal("1"))
Ω(template.Next().Args[0]).Should(Equal("2"))
Ω(template.Next().Args[0]).Should(Equal("3"))
template.AddIterator("test3", rmt)
Ω(template.Next().RemoteCommand).Should(Equal("rmt"))
})
It("should apply multiple Iterators when Next is called", func() {
template := wfl.NewTemplate(jt)
Ω(template).ShouldNot(BeNil())
Ω(template.Next().Args[0]).Should(Equal("0"))
template.AddIterator("test", itr)
template.AddIterator("test2", itr)
Ω(template.Next().Args[0]).Should(Equal("2"))
Ω(template.Next().Args[0]).Should(Equal("4"))
Ω(template.Next().Args[0]).Should(Equal("6"))
})
It("should temporarily convert a JobTemplate with MapTo a given output system", func() {
template := wfl.NewTemplate(jt)
Ω(template).ShouldNot(BeNil())
Ω(template.MapTo("nonExisting").Args[0]).Should(Equal("0"))
template.AddMap("existing", itr)
Ω(template.MapTo("nonExisting").Args[0]).Should(Equal("0"))
Ω(template.MapTo("existing").Args[0]).Should(Equal("1"))
// non-permanent changes
Ω(template.MapTo("existing").Args[0]).Should(Equal("1"))
Ω(template.MapTo("nonExisting").Args[0]).Should(Equal("0"))
Ω(template.MapTo("nonExisting").Args[0]).Should(Equal("0"))
})
It("should apply multiple Iterators and the mapping function when Next is called", func() {
template := wfl.NewTemplate(jt)
Ω(template).ShouldNot(BeNil())
Ω(template.Next().Args[0]).Should(Equal("0"))
template.AddIterator("test", itr)
template.AddIterator("test2", itr)
template.AddMap("existing", itr)
Ω(template.NextMap("existing").Args[0]).Should(Equal("3")) // 2 + 1
Ω(template.NextMap("non-existing").Args[0]).Should(Equal("4")) // 4 + 0
Ω(template.NextMap("existing").Args[0]).Should(Equal("7")) // 6 + 1
})
})
})