@@ -40,9 +40,22 @@ func TestNextAligned(t *testing.T) {
40
40
41
41
func TestCreateContainer (t * testing.T ) {
42
42
tests := []struct {
43
- name string
44
- opts []CreateOpt
43
+ name string
44
+ opts []CreateOpt
45
+ wantErr error
45
46
}{
47
+ {
48
+ name : "ErrInsufficientCapacity" ,
49
+ opts : []CreateOpt {
50
+ OptCreateWithID (testID ),
51
+ OptCreateWithTime (testTime ),
52
+ OptCreateWithDescriptorCapacity (0 ),
53
+ OptCreateWithDescriptors (
54
+ getDescriptorInput (t , DataGeneric , []byte {0xfa , 0xce }),
55
+ ),
56
+ },
57
+ wantErr : errInsufficientCapacity ,
58
+ },
46
59
{
47
60
name : "Empty" ,
48
61
opts : []CreateOpt {
@@ -136,25 +149,41 @@ func TestCreateContainer(t *testing.T) {
136
149
var b Buffer
137
150
138
151
f , err := CreateContainer (& b , tt .opts ... )
139
- if err != nil {
140
- t .Fatal (err )
141
- }
142
152
143
- if err := f . UnloadContainer (); err != nil {
144
- t .Fatal ( err )
153
+ if got , want := err , tt . wantErr ; ! errors . Is ( got , want ) {
154
+ t .Fatalf ( "got error %v, want %v" , got , want )
145
155
}
146
156
147
- g := goldie .New (t , goldie .WithTestNameForDir (true ))
148
- g .Assert (t , tt .name , b .Bytes ())
157
+ if err == nil {
158
+ if err := f .UnloadContainer (); err != nil {
159
+ t .Error (err )
160
+ }
161
+
162
+ g := goldie .New (t , goldie .WithTestNameForDir (true ))
163
+ g .Assert (t , tt .name , b .Bytes ())
164
+ }
149
165
})
150
166
}
151
167
}
152
168
153
169
func TestCreateContainerAtPath (t * testing.T ) {
154
170
tests := []struct {
155
- name string
156
- opts []CreateOpt
171
+ name string
172
+ opts []CreateOpt
173
+ wantErr error
157
174
}{
175
+ {
176
+ name : "ErrInsufficientCapacity" ,
177
+ opts : []CreateOpt {
178
+ OptCreateWithID (testID ),
179
+ OptCreateWithTime (testTime ),
180
+ OptCreateWithDescriptorCapacity (0 ),
181
+ OptCreateWithDescriptors (
182
+ getDescriptorInput (t , DataGeneric , []byte {0xfa , 0xce }),
183
+ ),
184
+ },
185
+ wantErr : errInsufficientCapacity ,
186
+ },
158
187
{
159
188
name : "Empty" ,
160
189
opts : []CreateOpt {
@@ -237,21 +266,24 @@ func TestCreateContainerAtPath(t *testing.T) {
237
266
tf .Close ()
238
267
239
268
f , err := CreateContainerAtPath (tf .Name (), tt .opts ... )
240
- if err != nil {
241
- t .Fatal (err )
242
- }
243
269
244
- if err := f . UnloadContainer (); err != nil {
245
- t .Fatal ( err )
270
+ if got , want := err , tt . wantErr ; ! errors . Is ( got , want ) {
271
+ t .Fatalf ( "got error %v, want %v" , got , want )
246
272
}
247
273
248
- b , err := os . ReadFile ( tf . Name ())
249
- if err != nil {
250
- t . Fatal (err )
251
- }
274
+ if err == nil {
275
+ if err := f . UnloadContainer (); err != nil {
276
+ t . Error (err )
277
+ }
252
278
253
- g := goldie .New (t , goldie .WithTestNameForDir (true ))
254
- g .Assert (t , tt .name , b )
279
+ b , err := os .ReadFile (tf .Name ())
280
+ if err != nil {
281
+ t .Fatal (err )
282
+ }
283
+
284
+ g := goldie .New (t , goldie .WithTestNameForDir (true ))
285
+ g .Assert (t , tt .name , b )
286
+ }
255
287
})
256
288
}
257
289
}
0 commit comments