storj/satellite/satellitedb/orders_test.go
Michal Niewrzal bc8f8f62b5 satellite/orders: cleanup after altering primary key
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
2023-03-06 16:03:11 +00:00

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))
}