filer_conf_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package filer
  2. import (
  3. "testing"
  4. "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestFilerConf(t *testing.T) {
  8. fc := NewFilerConf()
  9. conf := &filer_pb.FilerConf{Locations: []*filer_pb.FilerConf_PathConf{
  10. {
  11. LocationPrefix: "/buckets/abc",
  12. Collection: "abc",
  13. },
  14. {
  15. LocationPrefix: "/buckets/abcd",
  16. Collection: "abcd",
  17. },
  18. {
  19. LocationPrefix: "/buckets/",
  20. Replication: "001",
  21. },
  22. {
  23. LocationPrefix: "/buckets",
  24. ReadOnly: false,
  25. },
  26. {
  27. LocationPrefix: "/buckets/xxx",
  28. ReadOnly: true,
  29. },
  30. {
  31. LocationPrefix: "/buckets/xxx/yyy",
  32. ReadOnly: false,
  33. },
  34. }}
  35. fc.doLoadConf(conf)
  36. assert.Equal(t, "abc", fc.MatchStorageRule("/buckets/abc/jasdf").Collection)
  37. assert.Equal(t, "abcd", fc.MatchStorageRule("/buckets/abcd/jasdf").Collection)
  38. assert.Equal(t, "001", fc.MatchStorageRule("/buckets/abc/jasdf").Replication)
  39. assert.Equal(t, true, fc.MatchStorageRule("/buckets/xxx/yyy/zzz").ReadOnly)
  40. assert.Equal(t, false, fc.MatchStorageRule("/buckets/other").ReadOnly)
  41. }