-
Notifications
You must be signed in to change notification settings - Fork 8
/
template_iterators_test.go
73 lines (51 loc) · 1.82 KB
/
template_iterators_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
package wfl_test
import (
"github.com/dgruber/wfl"
"github.com/dgruber/drmaa2interface"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"time"
)
var _ = Describe("TemplateIterators", func() {
Context("NewEnvSequenceIterator", func() {
jt := drmaa2interface.JobTemplate{}
It("should set the environment variable if not set", func() {
iter := wfl.NewEnvSequenceIterator("test", 100, 2)
newJt := iter(jt)
Ω(jt.JobEnvironment).Should(BeNil())
Ω(newJt.JobEnvironment).ShouldNot(BeNil())
Ω(newJt.JobEnvironment["test"]).Should(Equal("100"))
tmpl := wfl.NewTemplate(jt).AddIterator("test", iter)
newJt = tmpl.Next()
Ω(newJt.JobEnvironment).ShouldNot(BeNil())
Ω(newJt.JobEnvironment["test"]).Should(Equal("102"))
Ω(jt.JobEnvironment).Should(BeNil())
})
It("should override the environment variable if set", func() {
iter := wfl.NewEnvSequenceIterator("test", 100, 2)
jt.JobEnvironment = make(map[string]string, 1)
jt.JobEnvironment["test"] = "1"
newJt := iter(jt)
Ω(jt.JobEnvironment).ShouldNot(BeNil())
Ω(newJt.JobEnvironment).ShouldNot(BeNil())
Ω(newJt.JobEnvironment["test"]).Should(Equal("100"))
tmpl := wfl.NewTemplate(jt).AddIterator("test", iter)
newJt = tmpl.Next()
Ω(newJt.JobEnvironment).ShouldNot(BeNil())
Ω(newJt.JobEnvironment["test"]).Should(Equal("102"))
Ω(jt.JobEnvironment).ShouldNot(BeNil())
})
})
Context("NewTimeIterator", func() {
jt := drmaa2interface.JobTemplate{}
It("should return a new job template after the given duration", func() {
iter := wfl.NewTimeIterator(time.Millisecond * 30)
Ω(iter).ShouldNot(BeNil())
tmpl := wfl.NewTemplate(jt).AddIterator("timer", iter)
now := time.Now()
tmpl.Next()
tmpl.Next()
Ω(time.Now()).Should(BeTemporally(">=", now.Add(time.Millisecond*50)))
})
})
})