20d03bebdb
This commit doesn't change any behavior, just organize the code in different way to make it easier to implement different Criterias to include nodes. Today we use NodeID and Subnet based selection but later Criteria can be extended with different kind of placement rules (like geofencing). The change nodeselection is used by segment allocaton (upload) and repair and excludes nodes from an in-memory selection. Resolves https://github.com/storj/storj/issues/4240 Change-Id: I0c1955fe16a045e3b76d7e50b2e1f4575a7ff095
84 lines
1.6 KiB
Go
84 lines
1.6 KiB
Go
// Copyright (C) 2021 Storj Labs, Inc.
|
|
// See LICENSE for copying information
|
|
|
|
package uploadselection
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"storj.io/common/storj"
|
|
"storj.io/common/testrand"
|
|
)
|
|
|
|
func TestCriteria_AutoExcludeSubnet(t *testing.T) {
|
|
|
|
criteria := Criteria{
|
|
AutoExcludeSubnets: map[string]struct{}{},
|
|
}
|
|
|
|
assert.True(t, criteria.MatchInclude(&Node{
|
|
LastNet: "192.168.0.1",
|
|
}))
|
|
|
|
assert.False(t, criteria.MatchInclude(&Node{
|
|
LastNet: "192.168.0.1",
|
|
}))
|
|
|
|
assert.True(t, criteria.MatchInclude(&Node{
|
|
LastNet: "192.168.1.1",
|
|
}))
|
|
}
|
|
|
|
func TestCriteria_ExcludeNodeID(t *testing.T) {
|
|
included := testrand.NodeID()
|
|
excluded := testrand.NodeID()
|
|
|
|
criteria := Criteria{
|
|
ExcludeNodeIDs: []storj.NodeID{excluded},
|
|
}
|
|
|
|
assert.False(t, criteria.MatchInclude(&Node{
|
|
NodeURL: storj.NodeURL{
|
|
ID: excluded,
|
|
Address: "localhost",
|
|
},
|
|
}))
|
|
|
|
assert.True(t, criteria.MatchInclude(&Node{
|
|
NodeURL: storj.NodeURL{
|
|
ID: included,
|
|
Address: "localhost",
|
|
},
|
|
}))
|
|
|
|
}
|
|
|
|
func TestCriteria_NodeIDAndSubnet(t *testing.T) {
|
|
excluded := testrand.NodeID()
|
|
|
|
criteria := Criteria{
|
|
ExcludeNodeIDs: []storj.NodeID{excluded},
|
|
AutoExcludeSubnets: map[string]struct{}{},
|
|
}
|
|
|
|
// due to node id criteria
|
|
assert.False(t, criteria.MatchInclude(&Node{
|
|
NodeURL: storj.NodeURL{
|
|
ID: excluded,
|
|
Address: "192.168.0.1",
|
|
},
|
|
}))
|
|
|
|
// should be included as previous one excluded and
|
|
// not stored for subnet exclusion
|
|
assert.True(t, criteria.MatchInclude(&Node{
|
|
NodeURL: storj.NodeURL{
|
|
ID: testrand.NodeID(),
|
|
Address: "192.168.0.2",
|
|
},
|
|
}))
|
|
|
|
}
|