File tree 2 files changed +29
-6
lines changed
2 files changed +29
-6
lines changed Original file line number Diff line number Diff line change 8
8
"io"
9
9
"math"
10
10
"os"
11
+ "slices"
11
12
"sort"
12
13
"sync"
13
14
@@ -493,12 +494,7 @@ func (m *Manager) sortedExtensionNames() []string {
493
494
494
495
// IsFormatSupported returns if the snapshotter supports restoration from given format.
495
496
func IsFormatSupported (snapshotter types.ExtensionSnapshotter , format uint32 ) bool {
496
- for _ , i := range snapshotter .SupportedFormats () {
497
- if i == format {
498
- return true
499
- }
500
- }
501
- return false
497
+ return slices .Contains (snapshotter .SupportedFormats (), format )
502
498
}
503
499
504
500
// SnapshotIfApplicable takes a snapshot of the current state if we are on a snapshot height.
Original file line number Diff line number Diff line change @@ -256,3 +256,30 @@ func TestManager_TakeError(t *testing.T) {
256
256
_ , err = manager .Create (1 )
257
257
require .Error (t , err )
258
258
}
259
+
260
+ type mockExtensionSnapshotter struct {
261
+ types.ExtensionSnapshotter
262
+ formats []uint32
263
+ }
264
+
265
+ func (m * mockExtensionSnapshotter ) SnapshotName () string { return "mock" }
266
+ func (m * mockExtensionSnapshotter ) SupportedFormats () []uint32 { return m .formats }
267
+
268
+ func TestIsFormatSupported (t * testing.T ) {
269
+ mockExtension := & mockExtensionSnapshotter {
270
+ formats : []uint32 {1 , 2 },
271
+ }
272
+
273
+ t .Run ("supported format" , func (t * testing.T ) {
274
+ require .True (t , snapshots .IsFormatSupported (mockExtension , 1 ))
275
+ })
276
+
277
+ t .Run ("unsupported format" , func (t * testing.T ) {
278
+ require .False (t , snapshots .IsFormatSupported (mockExtension , 3 ))
279
+ })
280
+
281
+ t .Run ("empty supported formats" , func (t * testing.T ) {
282
+ emptyExtension := & mockExtensionSnapshotter {formats : []uint32 {}}
283
+ require .False (t , snapshots .IsFormatSupported (emptyExtension , 1 ))
284
+ })
285
+ }
You can’t perform that action at this time.
0 commit comments