|
| 1 | +package mount |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + datastore "github.com/ipfs/go-datastore" |
| 7 | +) |
| 8 | + |
| 9 | +func TestLookup(t *testing.T) { |
| 10 | + mapds0 := datastore.NewMapDatastore() |
| 11 | + mapds1 := datastore.NewMapDatastore() |
| 12 | + mapds2 := datastore.NewMapDatastore() |
| 13 | + mapds3 := datastore.NewMapDatastore() |
| 14 | + m := New([]Mount{ |
| 15 | + {Prefix: datastore.NewKey("/"), Datastore: mapds0}, |
| 16 | + {Prefix: datastore.NewKey("/foo"), Datastore: mapds1}, |
| 17 | + {Prefix: datastore.NewKey("/bar"), Datastore: mapds2}, |
| 18 | + {Prefix: datastore.NewKey("/baz"), Datastore: mapds3}, |
| 19 | + }) |
| 20 | + _, mnts, _ := m.lookupAll(datastore.NewKey("/bar")) |
| 21 | + if len(mnts) != 1 || mnts[0] != datastore.NewKey("/bar") { |
| 22 | + t.Errorf("expected to find the mountpoint /bar, got %v", mnts) |
| 23 | + } |
| 24 | + |
| 25 | + _, mnts, _ = m.lookupAll(datastore.NewKey("/fo")) |
| 26 | + if len(mnts) != 1 || mnts[0] != datastore.NewKey("/") { |
| 27 | + t.Errorf("expected to find the mountpoint /, got %v", mnts) |
| 28 | + } |
| 29 | + |
| 30 | + _, mnt, _ := m.lookup(datastore.NewKey("/fo")) |
| 31 | + if mnt != datastore.NewKey("/") { |
| 32 | + t.Errorf("expected to find the mountpoint /, got %v", mnt) |
| 33 | + } |
| 34 | + |
| 35 | + // /foo lives in /, /foo/bar lives in /foo. Most systems don't let us use the key "" or /. |
| 36 | + _, mnt, _ = m.lookup(datastore.NewKey("/foo")) |
| 37 | + if mnt != datastore.NewKey("/") { |
| 38 | + t.Errorf("expected to find the mountpoint /, got %v", mnt) |
| 39 | + } |
| 40 | + |
| 41 | + _, mnt, _ = m.lookup(datastore.NewKey("/foo/bar")) |
| 42 | + if mnt != datastore.NewKey("/foo") { |
| 43 | + t.Errorf("expected to find the mountpoint /foo, got %v", mnt) |
| 44 | + } |
| 45 | +} |
0 commit comments