@@ -7,112 +7,6 @@ import (
77 "github.com/stretchr/testify/assert"
88)
99
10- func TestFlat (t * testing.T ) {
11- input := map [string ]interface {}{
12- "foo" : "bar" ,
13- }
14- expected := map [string ]interface {}{
15- "foo" : "bar" ,
16- }
17- flattened := Flatten (input )
18- assert .Equal (t , expected , flattened )
19- unflattened := Unflatten (flattened )
20- assert .Equal (t , input , unflattened )
21- }
22-
23- func TestMap (t * testing.T ) {
24- input := map [string ]interface {}{
25- "foo" : map [string ]interface {}{
26- "bar" : 0 ,
27- "baz" : 0 ,
28- },
29- }
30- expected := map [string ]interface {}{
31- "foo" + mapSeparator + "bar" : 0 ,
32- "foo" + mapSeparator + "baz" : 0 ,
33- }
34- flattened := Flatten (input )
35- assert .Equal (t , expected , flattened )
36- unflattened := Unflatten (flattened )
37- assert .Equal (t , input , unflattened )
38- }
39-
40- func TestFlattenMapMoreNesting (t * testing.T ) {
41- input := map [string ]interface {}{
42- "foo" : map [string ]interface {}{
43- "bar" : map [string ]interface {}{
44- "baz" : 0 ,
45- },
46- },
47- }
48- expected := map [string ]interface {}{
49- "foo" + mapSeparator + "bar" + mapSeparator + "baz" : 0 ,
50- }
51- flattened := Flatten (input )
52- assert .Equal (t , expected , flattened )
53- unflattened := Unflatten (flattened )
54- assert .Equal (t , input , unflattened )
55- }
56-
57- func TestFlattenList (t * testing.T ) {
58- input := map [string ]interface {}{
59- "foo" : []interface {}{
60- 0 ,
61- },
62- }
63- expected := map [string ]interface {}{
64- "foo" + listSeparator + "0" : 0 ,
65- }
66- flattened := Flatten (input )
67- assert .Equal (t , expected , flattened )
68- unflattened := Unflatten (flattened )
69- assert .Equal (t , input , unflattened )
70- }
71-
72- func TestFlattenListWithMap (t * testing.T ) {
73- input := map [string ]interface {}{
74- "foo" : []interface {}{
75- map [string ]interface {}{
76- "bar" : 0 ,
77- },
78- },
79- }
80- expected := map [string ]interface {}{
81- "foo" + listSeparator + "0" + mapSeparator + "bar" : 0 ,
82- }
83- flattened := Flatten (input )
84- assert .Equal (t , expected , flattened )
85- unflattened := Unflatten (flattened )
86- assert .Equal (t , input , unflattened )
87- }
88-
89- func TestFlatten (t * testing.T ) {
90- input := map [string ]interface {}{
91- "foo" : "bar" ,
92- "baz" : map [string ]interface {}{
93- "foo" : 2 ,
94- "bar" : map [string ]interface {}{
95- "foo" : 2 ,
96- },
97- },
98- "qux" : []interface {}{
99- "hello" , 1 , 2 ,
100- },
101- }
102- expected := map [string ]interface {}{
103- "foo" : "bar" ,
104- "baz" + mapSeparator + "foo" : 2 ,
105- "baz" + mapSeparator + "bar" + mapSeparator + "foo" : 2 ,
106- "qux" + listSeparator + "0" : "hello" ,
107- "qux" + listSeparator + "1" : 1 ,
108- "qux" + listSeparator + "2" : 2 ,
109- }
110- flattened := Flatten (input )
111- assert .Equal (t , expected , flattened )
112- unflattened := Unflatten (flattened )
113- assert .Equal (t , input , unflattened )
114- }
115-
11610func TestTokenizeFlat (t * testing.T ) {
11711 input := "bar"
11812 expected := []token {mapToken {"bar" }}
@@ -141,46 +35,6 @@ func TestTokenizeNested(t *testing.T) {
14135 assert .Equal (t , expected , tokenized )
14236}
14337
144- func TestFlattenMetadata (t * testing.T ) {
145- tests := []struct {
146- input Metadata
147- want map [string ]interface {}
148- }{
149- {Metadata {MACOnlyEncrypted : false }, map [string ]interface {}{"mac_only_encrypted" : nil }},
150- {Metadata {MACOnlyEncrypted : true }, map [string ]interface {}{"mac_only_encrypted" : true }},
151- {Metadata {MessageAuthenticationCode : "line1\n line2" }, map [string ]interface {}{"mac" : "line1\n line2" }},
152- {Metadata {MessageAuthenticationCode : "line1\n \n \n line2\n \n line3" }, map [string ]interface {}{"mac" : "line1\n \n \n line2\n \n line3" }},
153- }
154-
155- for _ , tt := range tests {
156- got , err := FlattenMetadata (tt .input )
157- assert .NoError (t , err )
158- for k , v := range tt .want {
159- assert .Equal (t , v , got [k ])
160- }
161- }
162- }
163-
164- func TestFlattenMetadataToUnflattenMetadata (t * testing.T ) {
165- tests := []struct {
166- input Metadata
167- }{
168- {Metadata {MACOnlyEncrypted : true }},
169- {Metadata {MACOnlyEncrypted : false }},
170- {Metadata {ShamirThreshold : 3 }},
171- {Metadata {MessageAuthenticationCode : "line1\n line2" }},
172- {Metadata {MessageAuthenticationCode : "line1\n \n \n line2\n \n line3" }},
173- }
174-
175- for _ , tt := range tests {
176- flat , err := FlattenMetadata (tt .input )
177- assert .NoError (t , err )
178- md , err := UnflattenMetadata (flat )
179- assert .NoError (t , err )
180- assert .Equal (t , tt .input , md )
181- }
182- }
183-
18438func TestDecodeNewLines (t * testing.T ) {
18539 tests := []struct {
18640 input map [string ]interface {}
@@ -215,23 +69,6 @@ func TestEncodeNewLines(t *testing.T) {
21569 }
21670}
21771
218- func TestEncodeNonStrings (t * testing.T ) {
219- tests := []struct {
220- input map [string ]interface {}
221- want map [string ]interface {}
222- }{
223- {map [string ]interface {}{"mac_only_encrypted" : false }, map [string ]interface {}{"mac_only_encrypted" : "false" }},
224- {map [string ]interface {}{"mac_only_encrypted" : true }, map [string ]interface {}{"mac_only_encrypted" : "true" }},
225- {map [string ]interface {}{"shamir_threshold" : 2 }, map [string ]interface {}{"shamir_threshold" : "2" }},
226- {map [string ]interface {}{"shamir_threshold" : 123 }, map [string ]interface {}{"shamir_threshold" : "123" }},
227- }
228-
229- for _ , tt := range tests {
230- EncodeNonStrings (tt .input )
231- assert .Equal (t , tt .want , tt .input )
232- }
233- }
234-
23572func TestUnflattenTreeBranch (t * testing.T ) {
23673 var (
23774 input = sops.TreeBranch {
0 commit comments