@@ -49,6 +49,13 @@ func TestWithIndex(t *testing.T) {
49
49
50
50
g .Expect (d .digests ).To (BeEmpty ())
51
51
})
52
+
53
+ t .Run ("handles nil index" , func (t * testing.T ) {
54
+ g := NewWithT (t )
55
+ d := & Digester {}
56
+ WithIndex (nil )(d )
57
+ g .Expect (d .index ).To (BeNil ())
58
+ })
52
59
}
53
60
54
61
func TestNewDigester (t * testing.T ) {
@@ -72,6 +79,14 @@ func TestNewDigester(t *testing.T) {
72
79
g .Expect (d .index ).To (Equal (i ))
73
80
g .Expect (d .digests ).ToNot (BeNil ())
74
81
})
82
+
83
+ t .Run ("handles multiple WithIndex options, applying last one" , func (t * testing.T ) {
84
+ g := NewWithT (t )
85
+ firstIndex := map [string ]string {"a" : "b" }
86
+ secondIndex := map [string ]string {"c" : "d" }
87
+ d := NewDigester (WithIndex (firstIndex ), WithIndex (secondIndex ))
88
+ g .Expect (d .index ).To (Equal (secondIndex ))
89
+ })
75
90
}
76
91
77
92
func TestDigester_Add (t * testing.T ) {
@@ -107,6 +122,13 @@ func TestDigester_Add(t *testing.T) {
107
122
108
123
g .Expect (d .digests ).To (BeEmpty ())
109
124
})
125
+
126
+ t .Run ("adds empty key and value" , func (t * testing.T ) {
127
+ g := NewWithT (t )
128
+ d := NewDigester ()
129
+ d .Add ("" , "" )
130
+ g .Expect (d .index ).To (HaveKeyWithValue ("" , "" ))
131
+ })
110
132
}
111
133
112
134
func TestDigester_Delete (t * testing.T ) {
@@ -138,6 +160,14 @@ func TestDigester_Delete(t *testing.T) {
138
160
d .Delete ("foo" )
139
161
g .Expect (d .digests ).To (BeEmpty ())
140
162
})
163
+
164
+ t .Run ("deletes non-existent key without error" , func (t * testing.T ) {
165
+ g := NewWithT (t )
166
+ d := NewDigester ()
167
+ d .Delete ("non-existent" )
168
+ g .Expect (d .index ).To (BeEmpty ()) // Index should remain empty
169
+ g .Expect (d .digests ).To (BeEmpty ()) // Digests should remain empty as no change
170
+ })
141
171
}
142
172
143
173
func TestDigester_Get (t * testing.T ) {
@@ -161,17 +191,26 @@ func TestDigester_Has(t *testing.T) {
161
191
}
162
192
163
193
func TestDigester_Index (t * testing.T ) {
164
- g := NewWithT (t )
194
+ t .Run ("returns a copy of the index" , func (t * testing.T ) {
195
+ g := NewWithT (t )
165
196
166
- i := map [string ]string {
167
- "foo" : "bar" ,
168
- "bar" : "baz" ,
169
- }
170
- d := NewDigester (WithIndex (i ))
197
+ i := map [string ]string {
198
+ "foo" : "bar" ,
199
+ "bar" : "baz" ,
200
+ }
201
+ d := NewDigester (WithIndex (i ))
171
202
172
- iCopy := d .Index ()
173
- g .Expect (iCopy ).To (Equal (i ))
174
- g .Expect (iCopy ).ToNot (BeIdenticalTo (i ))
203
+ iCopy := d .Index ()
204
+ g .Expect (iCopy ).To (Equal (i ))
205
+ g .Expect (iCopy ).ToNot (BeIdenticalTo (i ))
206
+ })
207
+
208
+ t .Run ("returns an empty copy for an empty index" , func (t * testing.T ) {
209
+ g := NewWithT (t )
210
+ d := NewDigester ()
211
+ emptyIndex := d .Index ()
212
+ g .Expect (emptyIndex ).To (BeEmpty ())
213
+ })
175
214
}
176
215
177
216
func TestDigester_Len (t * testing.T ) {
@@ -183,6 +222,8 @@ func TestDigester_Len(t *testing.T) {
183
222
}))
184
223
185
224
g .Expect (d .Len ()).To (Equal (2 ))
225
+
226
+ g .Expect (NewDigester ().Len ()).To (Equal (0 ))
186
227
}
187
228
188
229
func TestDigester_String (t * testing.T ) {
@@ -196,6 +237,8 @@ func TestDigester_String(t *testing.T) {
196
237
g .Expect (d .String ()).To (Equal (`bar baz
197
238
foo bar
198
239
` ))
240
+
241
+ g .Expect (NewDigester ().String ()).To (Equal ("" ))
199
242
}
200
243
201
244
func TestDigester_WriteTo (t * testing.T ) {
0 commit comments