本文整理汇总了Golang中github.com/jbenet/go-datastore/mount.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestQuerySimple
func TestQuerySimple(t *testing.T) {
mapds := datastore.NewMapDatastore()
m := mount.New([]mount.Mount{
{Prefix: datastore.NewKey("/quux"), Datastore: mapds},
})
const myKey = "/quux/thud"
if err := m.Put(datastore.NewKey(myKey), []byte("foobar")); err != nil {
t.Fatalf("Put error: %v", err)
}
res, err := m.Query(query.Query{Prefix: "/quux"})
if err != nil {
t.Fatalf("Query fail: %v\n", err)
}
entries, err := res.Rest()
if err != nil {
t.Fatalf("Query Results.Rest fail: %v\n", err)
}
seen := false
for _, e := range entries {
switch e.Key {
case datastore.NewKey(myKey).String():
seen = true
default:
t.Errorf("saw unexpected key: %q", e.Key)
}
}
if !seen {
t.Errorf("did not see wanted key %q in %+v", myKey, entries)
}
}
开发者ID:rht,项目名称:go-datastore,代码行数:32,代码来源:mount_test.go
示例2: TestGetBadNothing
func TestGetBadNothing(t *testing.T) {
m := mount.New([]mount.Mount{})
_, err := m.Get(datastore.NewKey("/quux/thud"))
if g, e := err, datastore.ErrNotFound; g != e {
t.Fatalf("expected ErrNotFound, got: %v\n", g)
}
}
开发者ID:rht,项目名称:go-datastore,代码行数:8,代码来源:mount_test.go
示例3: TestPutBadNothing
func TestPutBadNothing(t *testing.T) {
m := mount.New(nil)
err := m.Put(datastore.NewKey("quux"), []byte("foobar"))
if g, e := err, mount.ErrNoMount; g != e {
t.Fatalf("Put got wrong error: %v != %v", g, e)
}
}
开发者ID:rht,项目名称:go-datastore,代码行数:8,代码来源:mount_test.go
示例4: TestGetNotFound
func TestGetNotFound(t *testing.T) {
mapds := datastore.NewMapDatastore()
m := mount.New([]mount.Mount{
{Prefix: datastore.NewKey("/quux"), Datastore: mapds},
})
_, err := m.Get(datastore.NewKey("/quux/thud"))
if g, e := err, datastore.ErrNotFound; g != e {
t.Fatalf("expected ErrNotFound, got: %v\n", g)
}
}
开发者ID:rht,项目名称:go-datastore,代码行数:11,代码来源:mount_test.go
示例5: TestPutBadNoMount
func TestPutBadNoMount(t *testing.T) {
mapds := datastore.NewMapDatastore()
m := mount.New([]mount.Mount{
{Prefix: datastore.NewKey("/redherring"), Datastore: mapds},
})
err := m.Put(datastore.NewKey("/quux/thud"), []byte("foobar"))
if g, e := err, mount.ErrNoMount; g != e {
t.Fatalf("expected ErrNoMount, got: %v\n", g)
}
}
开发者ID:rht,项目名称:go-datastore,代码行数:11,代码来源:mount_test.go
示例6: TestHasBadNothing
func TestHasBadNothing(t *testing.T) {
m := mount.New([]mount.Mount{})
found, err := m.Has(datastore.NewKey("/quux/thud"))
if err != nil {
t.Fatalf("Has error: %v", err)
}
if g, e := found, false; g != e {
t.Fatalf("wrong value: %v != %v", g, e)
}
}
开发者ID:rht,项目名称:go-datastore,代码行数:11,代码来源:mount_test.go
示例7: TestHasNotFound
func TestHasNotFound(t *testing.T) {
mapds := datastore.NewMapDatastore()
m := mount.New([]mount.Mount{
{Prefix: datastore.NewKey("/quux"), Datastore: mapds},
})
found, err := m.Has(datastore.NewKey("/quux/thud"))
if err != nil {
t.Fatalf("Has error: %v", err)
}
if g, e := found, false; g != e {
t.Fatalf("wrong value: %v != %v", g, e)
}
}
开发者ID:rht,项目名称:go-datastore,代码行数:14,代码来源:mount_test.go
示例8: TestHas
func TestHas(t *testing.T) {
mapds := datastore.NewMapDatastore()
m := mount.New([]mount.Mount{
{Prefix: datastore.NewKey("/quux"), Datastore: mapds},
})
if err := mapds.Put(datastore.NewKey("/thud"), []byte("foobar")); err != nil {
t.Fatalf("Put error: %v", err)
}
found, err := m.Has(datastore.NewKey("/quux/thud"))
if err != nil {
t.Fatalf("Has error: %v", err)
}
if g, e := found, true; g != e {
t.Fatalf("wrong value: %v != %v", g, e)
}
}
开发者ID:rht,项目名称:go-datastore,代码行数:18,代码来源:mount_test.go
示例9: TestPut
func TestPut(t *testing.T) {
mapds := datastore.NewMapDatastore()
m := mount.New([]mount.Mount{
{Prefix: datastore.NewKey("/quux"), Datastore: mapds},
})
if err := m.Put(datastore.NewKey("/quux/thud"), []byte("foobar")); err != nil {
t.Fatalf("Put error: %v", err)
}
val, err := mapds.Get(datastore.NewKey("/thud"))
if err != nil {
t.Fatalf("Get error: %v", err)
}
buf, ok := val.([]byte)
if !ok {
t.Fatalf("Get value is not []byte: %T %v", val, val)
}
if g, e := string(buf), "foobar"; g != e {
t.Errorf("wrong value: %q != %q", g, e)
}
}
开发者ID:rht,项目名称:go-datastore,代码行数:22,代码来源:mount_test.go
示例10: TestDelete
func TestDelete(t *testing.T) {
mapds := datastore.NewMapDatastore()
m := mount.New([]mount.Mount{
{Prefix: datastore.NewKey("/quux"), Datastore: mapds},
})
if err := mapds.Put(datastore.NewKey("/thud"), []byte("foobar")); err != nil {
t.Fatalf("Put error: %v", err)
}
err := m.Delete(datastore.NewKey("/quux/thud"))
if err != nil {
t.Fatalf("Delete error: %v", err)
}
// make sure it disappeared
found, err := mapds.Has(datastore.NewKey("/thud"))
if err != nil {
t.Fatalf("Has error: %v", err)
}
if g, e := found, false; g != e {
t.Fatalf("wrong value: %v != %v", g, e)
}
}
开发者ID:rht,项目名称:go-datastore,代码行数:24,代码来源:mount_test.go
注:本文中的github.com/jbenet/go-datastore/mount.New函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论