-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcontext_test.go
135 lines (119 loc) · 3.73 KB
/
context_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
125
126
127
128
129
130
131
132
133
134
135
package wfl_test
import (
"github.com/dgruber/wfl"
"github.com/dgruber/wfl/pkg/context/cloudfoundry"
"github.com/dgruber/wfl/pkg/context/docker"
"github.com/dgruber/wfl/pkg/context/kubernetes"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"os"
)
var _ = Describe("Context", func() {
Context("DRMAA2 Context", func() {
BeforeEach(func() {
os.Remove("tmp.db")
})
Context("Process Context", func() {
It("should be possible to create a process context", func() {
ctx := wfl.NewProcessContext()
err := ctx.Error()
Ω(err).Should(BeNil())
Ω(ctx).ShouldNot(BeNil())
Ω(ctx.HasError()).Should(BeFalse())
})
It("should be possible to create a process context with configuration", func() {
ctx := wfl.NewProcessContextByCfg(wfl.ProcessConfig{DBFile: "tmp.db"})
err := ctx.Error()
Ω(err).Should(BeNil())
Ω(ctx).ShouldNot(BeNil())
})
})
Context("Docker Context", func() {
It("should be possible to create a docker context", func() {
ctx := docker.NewDockerContext()
err := ctx.Error()
Ω(err).Should(BeNil())
Ω(ctx).ShouldNot(BeNil())
})
It("should be possible to create a docker context with configuration", func() {
ctx := docker.NewDockerContextByCfg(docker.Config{DBFile: "tmp.db", DefaultDockerImage: "golang:latest"})
err := ctx.Error()
Ω(err).Should(BeNil())
Ω(ctx).ShouldNot(BeNil())
})
})
Context("Cloud Foundry Context", func() {
It("should be possible to create a cloud foundry tasks context", func() {
ctx := cloudfoundry.NewCloudFoundryContext()
err := ctx.Error()
Ω(err).Should(BeNil())
Ω(ctx).ShouldNot(BeNil())
})
It("should be possible to create a cloud foundry tasks context with configuration", func() {
ctx := cloudfoundry.NewCloudFoundryContextByCfg(cloudfoundry.Config{DBFile: "tmp.db"})
err := ctx.Error()
Ω(err).Should(BeNil())
Ω(ctx).ShouldNot(BeNil())
})
})
Context("Kubernetes Context", func() {
It("should be possible to create a Kubernetes context", func() {
ctx := kubernetes.NewKubernetesContext()
Ω(ctx).ShouldNot(BeNil())
})
})
Context("Singularity Context", func() {
It("should be possible to create a Singularity context", func() {
ctx := wfl.NewSingularityContext()
Ω(ctx).ShouldNot(BeNil())
err := ctx.Error()
Ω(err).Should(BeNil())
})
It("should be possible to create a Singularity context by config", func() {
ctx := wfl.NewSingularityContextByCfg(wfl.SingularityConfig{
DefaultImage: "",
DBFile: "",
})
Ω(ctx).ShouldNot(BeNil())
err := ctx.Error()
Ω(err).Should(BeNil())
})
})
Context("Temporary DB file", func() {
It("should always be a different filename", func() {
files := make(map[string]interface{}, 100)
for i := 0; i < 100; i++ {
file := wfl.TmpFile()
Ω(files).ShouldNot(ContainElement(file))
Ω(file).ShouldNot(ContainSubstring("%d"))
files[file] = file
}
})
})
Context("Test Contexts", func() {
It("should be possible to create an empty test context", func() {
ctx := wfl.DRMAA2SessionManagerContext(nil)
err := ctx.Error()
Ω(err).Should(BeNil())
Ω(ctx).ShouldNot(BeNil())
})
It("should be possible to create an raw drmaa2 session manager context", func() {
ctx := wfl.DRMAA2SessionManagerContext(nil)
err := ctx.Error()
Ω(err).Should(BeNil())
Ω(ctx).ShouldNot(BeNil())
})
It("should execute a function when an error in context creation happened", func() {
ctx := wfl.ErrorTestContext()
var e error
ctx.OnError(func(err error) {
e = err
})
Ω(e).ShouldNot(BeNil())
err := ctx.Error()
Ω(err).ShouldNot(BeNil())
Ω(ctx).ShouldNot(BeNil())
})
})
})
})