-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunpack_test.go
66 lines (56 loc) · 1.9 KB
/
unpack_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
package goutil_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/xchapter7x/goutil"
)
var _ = Describe("unpack package", func() {
controlANew := "hi"
controlAOld := "good"
controlBNew := "there"
controlBOld := "bye"
Describe("unpack args function", func() {
It("Should assign the value in the array to the associated pointer given", func() {
internalA := controlAOld
internalB := controlBOld
arr := []interface{}{controlANew, controlBNew}
err := Unpack(arr, &internalA, &internalB)
Ω(err).Should(BeNil())
Expect(internalA).NotTo(Equal(controlAOld))
Expect(internalA).To(Equal(controlANew))
Expect(internalB).NotTo(Equal(controlBOld))
Expect(internalB).To(Equal(controlBNew))
})
It("Should return error if there the argument lengths dont match", func() {
internalA := controlAOld
arr := []interface{}{controlANew, controlBNew}
err := Unpack(arr, &internalA)
Ω(err).ShouldNot(BeNil())
})
It("Should return error if there the arguments of non matching types", func() {
internalA := []string{"hi there"}
arr := []interface{}{controlANew}
err := Unpack(arr, &internalA)
Ω(err).ShouldNot(BeNil())
})
It("Should not panic if called with incorrect arg count", func() {
internalA := controlAOld
arr := []interface{}{controlANew, controlBNew}
Ω(func() { Unpack(arr, &internalA) }).ShouldNot(Panic())
})
It("Should not panic if called with invalid arg types", func() {
internalA := []string{"hi there"}
arr := []interface{}{controlANew}
Ω(func() { Unpack(arr, &internalA) }).ShouldNot(Panic())
})
It("Should not panic if called with empty", func() {
arr := []interface{}{controlANew}
Ω(func() { Unpack(arr, Empty()) }).ShouldNot(Panic())
})
It("Should not error if called with empty", func() {
arr := []interface{}{controlANew}
err := Unpack(arr, Empty())
Ω(err).Should(BeNil())
})
})
})