-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsessionmanager_hlp_test.go
85 lines (71 loc) · 2.28 KB
/
sessionmanager_hlp_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
package drmaa2os_test
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/dgruber/drmaa2os"
)
var _ = Describe("SessionmanagerHlp", func() {
Context("reflect on ContactString in job tracker implementation specific params", func() {
It("should set ContactString value", func() {
type X struct {
AnotherThing int
ContactString string
ContactString2 string
}
var test interface{} = X{
AnotherThing: 11,
ContactString: "",
ContactString2: "ö",
}
err := TryToSetContactString(&test, "ups")
Expect(err).To(BeNil())
Expect(test.(X).ContactString).To(Equal("ups"))
Expect(test.(X).AnotherThing).To(BeNumerically("==", 11))
Expect(test.(X).ContactString2).To(Equal("ö"))
err = TryToSetContactString(&test, "fedex")
Expect(err).To(BeNil())
Expect(test.(X).ContactString).To(Equal("fedex"))
Expect(test.(X).AnotherThing).To(BeNumerically("==", 11))
Expect(test.(X).ContactString2).To(Equal("ö"))
err = TryToSetContactString(&test, "cat")
Expect(err).To(BeNil())
Expect(test.(X).ContactString).To(Equal("cat"))
Expect(test.(X).AnotherThing).To(BeNumerically("==", 11))
Expect(test.(X).ContactString2).To(Equal("ö"))
})
It("should not crash if ContactString is not available", func() {
type X struct {
AnotherThing int
}
var test interface{} = X{
AnotherThing: 11,
}
err := TryToSetContactString(&test, "∂")
Expect(test.(X).AnotherThing).To(BeNumerically("==", 11))
Expect(err).NotTo(BeNil())
err = TryToSetContactString(nil, "k")
Expect(test.(X).AnotherThing).To(BeNumerically("==", 11))
Expect(err).NotTo(BeNil())
err = TryToSetContactString(test, "k")
Expect(err).NotTo(BeNil())
Expect(test.(X).AnotherThing).To(BeNumerically("==", 11))
})
It("should set ContactString when struct is referenced as interface", func() {
type X struct {
ContactString string
}
test := X{
ContactString: "",
}
err := TryToSetContactString(&test, "∂")
Expect(err).NotTo(BeNil())
Expect(test.ContactString).NotTo(Equal("∂"))
f := func(asInterface interface{}) {
err := TryToSetContactString(&asInterface, "†")
Expect(err).To(BeNil())
Expect(asInterface.(X).ContactString).To(Equal("†"))
}
f(test)
})
})
})