mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-07-19 14:32:41 +00:00
378f9a64ff
* fix(shell): correct volume.list -writable filter unit and comparison * fix(shell): correct volume.list -writable filter unit and comparison * chore(shell): fix typo in EC shard helper param names * fix(shell): use exact match for volume.balance -racks/-nodes filter The old strings.Contains-based filter quietly included any id that was a substring of the user-supplied flag value (e.g. -racks=rack10 also matched rack1). Replace it with an exact-match set parsed from the comma-separated flag value, and add regression tests for both -racks and -nodes paths. Also fix a small typo in the "remote storage" error returned by maybeMoveOneVolume. * fix(shell): use exact match for volume.balance -racks/-nodes filter The old strings.Contains-based filter quietly included any id that was a substring of the user-supplied flag value (e.g. -racks=rack10 also matched rack1). Replace it with an exact-match set parsed from the comma-separated flag value, and add regression tests for both -racks and -nodes paths. Also fix a small typo in the "remote storage" error returned by maybeMoveOneVolume. * refactor(shell): drop nil sentinel in splitCSVSet, use len() in callers * fix: apply collectionPattern during detection in volume.fix.replication * use existing wildcard.MatchesWildcard for collection matching It returns a plain bool, so drop the up-front filepath.Match validation and the path/filepath import that only existed to handle its error. * trim verbose comments to terse one-liners * drop redundant per-path collection guards Detection already filters by replicas[0].info.Collection. The repair guard re-checked pickOneReplicaToCopyFrom's collection (a different replica), so a mixed-collection volume could pass detection yet be skipped in repair without decrementing the counter, spinning the -apply loop. deleteOneVolume keeps its collectionIsMismatch safety. --------- Co-authored-by: Chris Lu <chris.lu@gmail.com>
35 lines
1.6 KiB
Go
35 lines
1.6 KiB
Go
package shell
|
|
|
|
import "testing"
|
|
|
|
func TestMatchCollectionPattern(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
pattern string
|
|
collection string
|
|
expected bool
|
|
}{
|
|
{name: "empty pattern matches any collection", pattern: "", collection: "jfs-hdfs-test", expected: true},
|
|
{name: "empty pattern matches empty collection", pattern: "", collection: "", expected: true},
|
|
{name: "default pattern matches empty collection", pattern: CollectionDefault, collection: "", expected: true},
|
|
{name: "default pattern rejects named collection", pattern: CollectionDefault, collection: "jfs-hdfs-test", expected: false},
|
|
{name: "exact match", pattern: "smart-highlevel-test", collection: "smart-highlevel-test", expected: true},
|
|
{name: "exact mismatch", pattern: "smart-highlevel-test", collection: "jfs-hdfs-test", expected: false},
|
|
{name: "prefix wildcard match", pattern: "smart*", collection: "smart-highlevel-test", expected: true},
|
|
{name: "prefix wildcard mismatch", pattern: "smart*", collection: "jfs-hdfs-test", expected: false},
|
|
{name: "single char wildcard match", pattern: "vol?", collection: "vol1", expected: true},
|
|
{name: "single char wildcard mismatch", pattern: "vol?", collection: "vol42", expected: false},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
pattern := tt.pattern
|
|
c := &commandVolumeFixReplication{collectionPattern: &pattern}
|
|
if got := c.matchCollectionPattern(tt.collection); got != tt.expected {
|
|
t.Errorf("matchCollectionPattern(pattern=%q, collection=%q) = %v, want %v",
|
|
tt.pattern, tt.collection, got, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|