bc8f8f62b5
We changed primary key for bucket_bandwidth_rollups table. Now we need to do some cleanup in places like structs, sorting methods or SQL queries. Change-Id: Ida4f874f161356df193379a53507602e04db1668
88 lines
1.7 KiB
Go
88 lines
1.7 KiB
Go
// Copyright (C) 2023 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package satellitedb
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"storj.io/common/pb"
|
|
"storj.io/common/uuid"
|
|
)
|
|
|
|
func TestSortRollupKeys(t *testing.T) {
|
|
rollups := []bandwidthRollupKey{
|
|
{
|
|
ProjectID: uuid.UUID{1},
|
|
BucketName: "a",
|
|
IntervalStart: 1,
|
|
Action: pb.PieceAction_GET, // GET is 2
|
|
|
|
},
|
|
{
|
|
ProjectID: uuid.UUID{2},
|
|
BucketName: "a",
|
|
IntervalStart: 2,
|
|
Action: pb.PieceAction_GET,
|
|
},
|
|
{
|
|
ProjectID: uuid.UUID{1},
|
|
BucketName: "b",
|
|
IntervalStart: 3,
|
|
Action: pb.PieceAction_GET,
|
|
},
|
|
{
|
|
ProjectID: uuid.UUID{1},
|
|
BucketName: "a",
|
|
IntervalStart: 4,
|
|
Action: pb.PieceAction_GET_AUDIT,
|
|
},
|
|
{
|
|
ProjectID: uuid.UUID{1},
|
|
BucketName: "a",
|
|
IntervalStart: 5,
|
|
Action: pb.PieceAction_GET,
|
|
},
|
|
}
|
|
|
|
expRollups := []bandwidthRollupKey{
|
|
{
|
|
ProjectID: uuid.UUID{1},
|
|
BucketName: "a",
|
|
IntervalStart: 1,
|
|
Action: pb.PieceAction_GET, // GET is 2
|
|
},
|
|
{
|
|
ProjectID: uuid.UUID{1},
|
|
BucketName: "a",
|
|
IntervalStart: 4,
|
|
Action: pb.PieceAction_GET_AUDIT,
|
|
},
|
|
{
|
|
ProjectID: uuid.UUID{1},
|
|
BucketName: "a",
|
|
IntervalStart: 5,
|
|
Action: pb.PieceAction_GET,
|
|
},
|
|
{
|
|
ProjectID: uuid.UUID{1},
|
|
BucketName: "b",
|
|
IntervalStart: 3,
|
|
Action: pb.PieceAction_GET,
|
|
},
|
|
{
|
|
ProjectID: uuid.UUID{2},
|
|
BucketName: "a",
|
|
IntervalStart: 2,
|
|
Action: pb.PieceAction_GET,
|
|
},
|
|
}
|
|
|
|
assert.NotEqual(t, expRollups, rollups)
|
|
sortBandwidthRollupKeys(rollups)
|
|
assert.Empty(t, cmp.Diff(expRollups, rollups))
|
|
}
|