2020-11-15 08:26:05 +00:00
|
|
|
package filer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-07-29 07:17:28 +00:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
2020-11-15 08:26:05 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFilerConf(t *testing.T) {
|
|
|
|
|
2020-11-15 22:06:03 +00:00
|
|
|
fc := NewFilerConf()
|
|
|
|
|
2020-11-15 08:26:05 +00:00
|
|
|
conf := &filer_pb.FilerConf{Locations: []*filer_pb.FilerConf_PathConf{
|
|
|
|
{
|
|
|
|
LocationPrefix: "/buckets/abc",
|
|
|
|
Collection: "abc",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
LocationPrefix: "/buckets/abcd",
|
|
|
|
Collection: "abcd",
|
|
|
|
},
|
2020-11-17 00:50:12 +00:00
|
|
|
{
|
|
|
|
LocationPrefix: "/buckets/",
|
2020-11-26 19:22:30 +00:00
|
|
|
Replication: "001",
|
2020-11-17 00:50:12 +00:00
|
|
|
},
|
2021-06-04 08:03:41 +00:00
|
|
|
{
|
|
|
|
LocationPrefix: "/buckets",
|
|
|
|
ReadOnly: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
LocationPrefix: "/buckets/xxx",
|
|
|
|
ReadOnly: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
LocationPrefix: "/buckets/xxx/yyy",
|
|
|
|
ReadOnly: false,
|
|
|
|
},
|
2020-11-15 08:26:05 +00:00
|
|
|
}}
|
|
|
|
fc.doLoadConf(conf)
|
|
|
|
|
|
|
|
assert.Equal(t, "abc", fc.MatchStorageRule("/buckets/abc/jasdf").Collection)
|
|
|
|
assert.Equal(t, "abcd", fc.MatchStorageRule("/buckets/abcd/jasdf").Collection)
|
2020-11-17 00:50:12 +00:00
|
|
|
assert.Equal(t, "001", fc.MatchStorageRule("/buckets/abc/jasdf").Replication)
|
2020-11-15 08:26:05 +00:00
|
|
|
|
2021-06-04 08:03:41 +00:00
|
|
|
assert.Equal(t, true, fc.MatchStorageRule("/buckets/xxx/yyy/zzz").ReadOnly)
|
|
|
|
assert.Equal(t, false, fc.MatchStorageRule("/buckets/other").ReadOnly)
|
|
|
|
|
2020-11-15 08:26:05 +00:00
|
|
|
}
|