@@ -9,28 +9,79 @@ import (
99 "gopkg.in/yaml.v3"
1010)
1111
12- // UnmarshalExpect defines the expected Unmarshal result. Types are very
13- // important here, only nil, float64, bool, string, map[string]interface{} and
14- // []interface{} may exist.
15- var UnmarshalExpect = Manifest {
16- "apiVersion" : string ("apps/v1" ),
17- "kind" : string ("Deployment" ),
18- "metadata" : map [string ]interface {}{
19- "name" : string ("MyDeployment" ),
20- },
21- "spec" : map [string ]interface {}{
22- "replicas" : float64 (3 ),
23- "template" : map [string ]interface {}{
24- "spec" : map [string ]interface {}{
25- "containers" : []interface {}{
26- map [string ]interface {}{
27- "name" : string ("nginx" ),
28- "image" : string ("nginx:1.14.2" ),
12+ var (
13+ // UnmarshalExpect defines the expected Unmarshal result. Types are very
14+ // important here, only nil, float64, bool, string, map[string]interface{} and
15+ // []interface{} may exist.
16+ UnmarshalExpect = Manifest {
17+ "apiVersion" : string ("apps/v1" ),
18+ "kind" : string ("Deployment" ),
19+ "metadata" : map [string ]interface {}{
20+ "name" : string ("MyDeployment" ),
21+ },
22+ "spec" : map [string ]interface {}{
23+ "replicas" : float64 (3 ),
24+ "template" : map [string ]interface {}{
25+ "spec" : map [string ]interface {}{
26+ "containers" : []interface {}{
27+ map [string ]interface {}{
28+ "name" : string ("nginx" ),
29+ "image" : string ("nginx:1.14.2" ),
30+ },
2931 },
3032 },
3133 },
3234 },
33- },
35+ }
36+
37+ // Manifest defines the manifest we're comparing the marshal results below to.
38+ SubstituteManifest = Manifest {
39+ "apiVersion" : string ("test/v1" ),
40+ "kind" : string ("Test" ),
41+ "metadata" : map [string ]interface {}{
42+ "name" : string ("test" ),
43+ },
44+ "spec" : map [string ]interface {}{
45+ "integer" : float64 (3 ),
46+ "string" : string ("${TEST_ENV}" ),
47+ },
48+ }
49+
50+ // SubstituteManifestString defines the expected Marshal result when using String(forceQuotedStrings=true).
51+ SubstituteManifestString = `apiVersion: test/v1
52+ kind: Test
53+ metadata:
54+ name: test
55+ spec:
56+ integer: 3
57+ string: ${TEST_ENV}
58+ `
59+
60+ // SubstituteManifestQuotedString defines the expected Marshal result when using String(forceQuotedStrings=falsetrue).
61+ SubstituteManifestQuotedString = `"apiVersion": "test/v1"
62+ "kind": "Test"
63+ "metadata":
64+ "name": "test"
65+ "spec":
66+ "integer": 3
67+ "string": "${TEST_ENV}"
68+ `
69+ )
70+
71+ func TestMarshalString (t * testing.T ) {
72+ m := SubstituteManifest .String (false )
73+
74+ if s := cmp .Diff (SubstituteManifestString , m ); s != "" {
75+ t .Error (s )
76+ }
77+ }
78+
79+ func TestMarshalQuotedString (t * testing.T ) {
80+ m := SubstituteManifest .String (true )
81+
82+ if s := cmp .Diff (SubstituteManifestQuotedString , m ); s != "" {
83+ t .Error (s )
84+ }
3485}
3586
3687func TestUnmarshalJSON (t * testing.T ) {
0 commit comments