@@ -17,6 +17,7 @@ limitations under the License.
17
17
package values_test
18
18
19
19
import (
20
+ "context"
20
21
. "github.com/onsi/ginkgo"
21
22
. "github.com/onsi/gomega"
22
23
"helm.sh/helm/v3/pkg/chartutil"
@@ -25,73 +26,50 @@ import (
25
26
. "github.com/operator-framework/helm-operator-plugins/pkg/reconciler/internal/values"
26
27
)
27
28
28
- var _ = Describe ("Values" , func () {
29
- var _ = Describe ("FromUnstructured" , func () {
30
- It ("should error with nil object" , func () {
31
- u := & unstructured.Unstructured {}
32
- v , err := FromUnstructured (u )
33
- Expect (v ).To (BeNil ())
34
- Expect (err ).NotTo (BeNil ())
35
- })
29
+ var _ = Describe ("ApplyOverrides" , func () {
30
+ var u * unstructured.Unstructured
36
31
37
- It ("should error with missing spec" , func () {
38
- u := & unstructured.Unstructured {Object : map [string ]interface {}{}}
39
- v , err := FromUnstructured (u )
40
- Expect (v ).To (BeNil ())
41
- Expect (err ).NotTo (BeNil ())
32
+ When ("Unstructured object is invalid" , func () {
33
+ It ("should error with nil unstructured" , func () {
34
+ u = nil
35
+ Expect (ApplyOverrides (nil , u )).NotTo (BeNil ())
42
36
})
43
37
44
- It ("should error with non-map spec" , func () {
45
- u := & unstructured.Unstructured {Object : map [string ]interface {}{"spec" : 0 }}
46
- v , err := FromUnstructured (u )
47
- Expect (v ).To (BeNil ())
48
- Expect (err ).NotTo (BeNil ())
38
+ It ("should error with nil object" , func () {
39
+ u = & unstructured.Unstructured {}
40
+ Expect (ApplyOverrides (nil , u )).NotTo (BeNil ())
49
41
})
50
42
51
- It ("should succeed with valid spec" , func () {
52
- values := New (map [string ]interface {}{"foo" : "bar" })
53
- u := & unstructured.Unstructured {Object : map [string ]interface {}{"spec" : values .Map ()}}
54
- Expect (FromUnstructured (u )).To (Equal (values ))
43
+ It ("should error with missing spec" , func () {
44
+ u = & unstructured.Unstructured {Object : map [string ]interface {}{}}
45
+ Expect (ApplyOverrides (nil , u )).NotTo (BeNil ())
55
46
})
56
- })
57
47
58
- var _ = Describe ("New" , func () {
59
- It ("should return new values" , func () {
60
- m := map [string ]interface {}{"foo" : "bar" }
61
- v := New (m )
62
- Expect (v .Map ()).To (Equal (m ))
48
+ It ("should error with non-map spec" , func () {
49
+ u = & unstructured.Unstructured {Object : map [string ]interface {}{"spec" : 0 }}
50
+ Expect (ApplyOverrides (nil , u )).NotTo (BeNil ())
63
51
})
64
52
})
65
53
66
- var _ = Describe ("Map" , func () {
67
- It ("should return nil with nil values" , func () {
68
- var v * Values
69
- Expect (v .Map ()).To (BeNil ())
70
- })
54
+ When ("Unstructured object is valid" , func () {
71
55
72
- It ("should return values as a map" , func () {
73
- m := map [string ]interface {}{"foo" : "bar" }
74
- v := New (m )
75
- Expect (v .Map ()).To (Equal (m ))
56
+ BeforeEach (func () {
57
+ u = & unstructured.Unstructured {Object : map [string ]interface {}{"spec" : map [string ]interface {}{}}}
76
58
})
77
- })
78
59
79
- var _ = Describe ("ApplyOverrides" , func () {
80
60
It ("should succeed with empty values" , func () {
81
- v := New (map [string ]interface {}{})
82
- Expect (v .ApplyOverrides (map [string ]string {"foo" : "bar" })).To (Succeed ())
83
- Expect (v .Map ()).To (Equal (map [string ]interface {}{"foo" : "bar" }))
61
+ Expect (ApplyOverrides (map [string ]string {"foo" : "bar" }, u )).To (Succeed ())
62
+ Expect (u .Object ).To (Equal (map [string ]interface {}{"spec" : map [string ]interface {}{"foo" : "bar" }}))
84
63
})
85
64
86
- It ("should succeed with empty values" , func () {
87
- v := New (map [string ]interface {}{ "foo" : "bar" })
88
- Expect (v . ApplyOverrides (map [string ]string {"foo" : "baz" })).To (Succeed ())
89
- Expect (v . Map ()) .To (Equal (map [string ]interface {}{"foo" : "baz" }))
65
+ It ("should succeed with non- empty values" , func () {
66
+ u . Object [ "spec" ]. (map [string ]interface {})[ "foo" ] = "bar"
67
+ Expect (ApplyOverrides (map [string ]string {"foo" : "baz" }, u )).To (Succeed ())
68
+ Expect (u . Object ) .To (Equal (map [string ]interface {}{"spec" : map [ string ] interface {}{ " foo" : "baz" } }))
90
69
})
91
70
92
71
It ("should fail with invalid overrides" , func () {
93
- v := New (map [string ]interface {}{"foo" : "bar" })
94
- Expect (v .ApplyOverrides (map [string ]string {"foo[" : "test" })).ToNot (BeNil ())
72
+ Expect (ApplyOverrides (map [string ]string {"foo[" : "test" }, u )).ToNot (BeNil ())
95
73
})
96
74
})
97
75
})
@@ -103,3 +81,20 @@ var _ = Describe("DefaultMapper", func() {
103
81
Expect (out ).To (Equal (in ))
104
82
})
105
83
})
84
+
85
+ var _ = Describe ("DefaultTranslator" , func () {
86
+ var m map [string ]interface {}
87
+
88
+ It ("returns empty spec untouched" , func () {
89
+ m = map [string ]interface {}{}
90
+ })
91
+
92
+ It ("returns filled spec untouched" , func () {
93
+ m = map [string ]interface {}{"something" : 0 }
94
+ })
95
+
96
+ AfterEach (func () {
97
+ u := & unstructured.Unstructured {Object : map [string ]interface {}{"spec" : m }}
98
+ Expect (DefaultTranslator .Translate (context .Background (), u )).To (Equal (chartutil .Values (m )))
99
+ })
100
+ })
0 commit comments