2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-07-03 09:35:01 +01:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package ecclient
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2018-11-29 18:39:27 +00:00
|
|
|
"storj.io/storj/internal/teststorj"
|
2018-09-18 05:39:06 +01:00
|
|
|
"storj.io/storj/pkg/pb"
|
2018-07-03 09:35:01 +01:00
|
|
|
)
|
|
|
|
|
2019-03-18 10:55:06 +00:00
|
|
|
func TestUnique(t *testing.T) {
|
|
|
|
limits := make([]*pb.AddressedOrderLimit, 4)
|
|
|
|
for i := 0; i < len(limits); i++ {
|
|
|
|
limits[i] = &pb.AddressedOrderLimit{
|
|
|
|
Limit: &pb.OrderLimit2{
|
|
|
|
StorageNodeId: teststorj.NodeIDFromString(fmt.Sprintf("node-%d", i)),
|
|
|
|
},
|
2018-07-03 09:35:01 +01:00
|
|
|
}
|
|
|
|
}
|
2018-08-02 16:12:19 +01:00
|
|
|
|
|
|
|
for i, tt := range []struct {
|
2019-03-18 10:55:06 +00:00
|
|
|
limits []*pb.AddressedOrderLimit
|
2018-08-02 16:12:19 +01:00
|
|
|
unique bool
|
|
|
|
}{
|
|
|
|
{nil, true},
|
2019-03-18 10:55:06 +00:00
|
|
|
{[]*pb.AddressedOrderLimit{}, true},
|
|
|
|
{[]*pb.AddressedOrderLimit{limits[0]}, true},
|
|
|
|
{[]*pb.AddressedOrderLimit{limits[0], limits[1]}, true},
|
|
|
|
{[]*pb.AddressedOrderLimit{limits[0], limits[0]}, false},
|
|
|
|
{[]*pb.AddressedOrderLimit{limits[0], limits[1], limits[0]}, false},
|
|
|
|
{[]*pb.AddressedOrderLimit{limits[1], limits[0], limits[0]}, false},
|
|
|
|
{[]*pb.AddressedOrderLimit{limits[0], limits[0], limits[1]}, false},
|
|
|
|
{[]*pb.AddressedOrderLimit{limits[2], limits[0], limits[1]}, true},
|
|
|
|
{[]*pb.AddressedOrderLimit{limits[2], limits[0], limits[3], limits[1]}, true},
|
|
|
|
{[]*pb.AddressedOrderLimit{limits[2], limits[0], limits[2], limits[1]}, false},
|
|
|
|
{[]*pb.AddressedOrderLimit{limits[1], limits[0], limits[3], limits[1]}, false},
|
2018-08-02 16:12:19 +01:00
|
|
|
} {
|
|
|
|
errTag := fmt.Sprintf("Test case #%d", i)
|
2019-03-18 10:55:06 +00:00
|
|
|
assert.Equal(t, tt.unique, unique(tt.limits), errTag)
|
2018-08-02 16:12:19 +01:00
|
|
|
}
|
|
|
|
}
|