storj/satellite/repair/queue/mock.go
Márton Elek 84ea80c1fd satellite/repair/checker: respect autoExcludeSubnet anntation in checker rangedloop
This patch is a oneliner: rangedloop checker should check the subnets only if it's not turned off with placement annotation.
(see in satellite/repair/checker/observer.go).

But I didn't find any unit test to cover that part, so I had to write one, and I prefered to write it as a unit test not an integration test, which requires a mock repair queue (observer_unit_test.go mock.go).

Because it's small change, I also included a small change: creating a elper method to check if AutoExcludeSubnet annotation is defined

Change-Id: I2666b937074ab57f603b356408ef108cd55bd6fd
2023-08-23 13:45:09 +00:00

75 lines
2.0 KiB
Go

// Copyright (C) 2023 Storj Labs, Inc.
// See LICENSE for copying information.
package queue
import (
"context"
"time"
"storj.io/common/uuid"
"storj.io/storj/satellite/metabase"
)
// MockRepairQueue helps testing RepairQueue.
type MockRepairQueue struct {
Segments []*InjuredSegment
}
// Insert implements RepairQueue.
func (m *MockRepairQueue) Insert(ctx context.Context, s *InjuredSegment) (alreadyInserted bool, err error) {
for _, alreadyAdded := range m.Segments {
if alreadyAdded.StreamID == s.StreamID {
return true, nil
}
}
m.Segments = append(m.Segments, s)
return false, nil
}
// InsertBatch implements RepairQueue.
func (m *MockRepairQueue) InsertBatch(ctx context.Context, segments []*InjuredSegment) (newlyInsertedSegments []*InjuredSegment, err error) {
for _, segment := range segments {
inserted, err := m.Insert(ctx, segment)
if err != nil {
return nil, err
}
if inserted {
newlyInsertedSegments = append(newlyInsertedSegments, segment)
}
}
return newlyInsertedSegments, nil
}
// Select implements RepairQueue.
func (m *MockRepairQueue) Select(ctx context.Context) (*InjuredSegment, error) {
panic("implement me")
}
// Delete implements RepairQueue.
func (m *MockRepairQueue) Delete(ctx context.Context, s *InjuredSegment) error {
panic("implement me")
}
// Clean implements RepairQueue.
func (m *MockRepairQueue) Clean(ctx context.Context, before time.Time) (deleted int64, err error) {
panic("implement me")
}
// SelectN implements RepairQueue.
func (m *MockRepairQueue) SelectN(ctx context.Context, limit int) ([]InjuredSegment, error) {
panic("implement me")
}
// Count implements RepairQueue.
func (m *MockRepairQueue) Count(ctx context.Context) (count int, err error) {
panic("implement me")
}
// TestingSetAttemptedTime implements RepairQueue.
func (m *MockRepairQueue) TestingSetAttemptedTime(ctx context.Context, streamID uuid.UUID, position metabase.SegmentPosition, t time.Time) (rowsAffected int64, err error) {
panic("implement me")
}
var _ RepairQueue = &MockRepairQueue{}