本文整理汇总了Golang中github.com/coreos/etcd/Godeps/_workspace/src/github.com/stretchr/testify/assert.Nil函数的典型用法代码示例。如果您正苦于以下问题:Golang Nil函数的具体用法?Golang Nil怎么用?Golang Nil使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Nil函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestStoreDeleteDiretory
// Ensure that the store can delete a directory if recursive is specified.
func TestStoreDeleteDiretory(t *testing.T) {
s := newStore()
// create directory /foo
var eidx uint64 = 2
s.Create("/foo", true, "", false, Permanent)
// delete /foo with dir = true and recursive = false
// this should succeed, since the directory is empty
e, err := s.Delete("/foo", true, false)
assert.Nil(t, err, "")
assert.Equal(t, e.EtcdIndex, eidx, "")
assert.Equal(t, e.Action, "delete", "")
// check prevNode
assert.NotNil(t, e.PrevNode, "")
assert.Equal(t, e.PrevNode.Key, "/foo", "")
assert.Equal(t, e.PrevNode.Dir, true, "")
// create directory /foo and directory /foo/bar
s.Create("/foo/bar", true, "", false, Permanent)
// delete /foo with dir = true and recursive = false
// this should fail, since the directory is not empty
_, err = s.Delete("/foo", true, false)
assert.NotNil(t, err, "")
// delete /foo with dir=false and recursive = true
// this should succeed, since recursive implies dir=true
// and recursively delete should be able to delete all
// items under the given directory
e, err = s.Delete("/foo", false, true)
assert.Nil(t, err, "")
assert.Equal(t, e.Action, "delete", "")
}
开发者ID:mayank-chutani,项目名称:etcd,代码行数:33,代码来源:store_test.go
示例2: TestStoreRecoverWithExpiration
// Ensure that the store can recover from a previously saved state that includes an expiring key.
func TestStoreRecoverWithExpiration(t *testing.T) {
s := newStore()
s.clock = newFakeClock()
fc := newFakeClock()
var eidx uint64 = 4
s.Create("/foo", true, "", false, Permanent)
s.Create("/foo/x", false, "bar", false, Permanent)
s.Create("/foo/y", false, "baz", false, fc.Now().Add(5*time.Millisecond))
b, err := s.Save()
time.Sleep(10 * time.Millisecond)
s2 := newStore()
s2.clock = fc
s2.Recovery(b)
fc.Advance(600 * time.Millisecond)
s.DeleteExpiredKeys(fc.Now())
e, err := s.Get("/foo/x", false, false)
assert.Nil(t, err, "")
assert.Equal(t, e.EtcdIndex, eidx, "")
assert.Equal(t, *e.Node.Value, "bar", "")
e, err = s.Get("/foo/y", false, false)
assert.NotNil(t, err, "")
assert.Nil(t, e, "")
}
开发者ID:mayank-chutani,项目名称:etcd,代码行数:32,代码来源:store_test.go
示例3: TestNewStoreWithNamespaces
func TestNewStoreWithNamespaces(t *testing.T) {
s := newStore("/0", "/1")
_, err := s.Get("/0", false, false)
assert.Nil(t, err, "")
_, err = s.Get("/1", false, false)
assert.Nil(t, err, "")
}
开发者ID:mayank-chutani,项目名称:etcd,代码行数:8,代码来源:store_test.go
示例4: TestStoreWatchRecursiveCreateWithHiddenKey
// Ensure that the store doesn't see hidden key creates without an exact path match in recursive mode.
func TestStoreWatchRecursiveCreateWithHiddenKey(t *testing.T) {
s := newStore()
w, _ := s.Watch("/foo", true, false, 0)
s.Create("/foo/_bar", false, "baz", false, Permanent)
e := nbselect(w.EventChan())
assert.Nil(t, e, "")
w, _ = s.Watch("/foo", true, false, 0)
s.Create("/foo/_baz", true, "", false, Permanent)
e = nbselect(w.EventChan())
assert.Nil(t, e, "")
s.Create("/foo/_baz/quux", false, "quux", false, Permanent)
e = nbselect(w.EventChan())
assert.Nil(t, e, "")
}
开发者ID:mayank-chutani,项目名称:etcd,代码行数:15,代码来源:store_test.go
示例5: TestStoreWatchExpire
// Ensure that the store can watch for key expiration.
func TestStoreWatchExpire(t *testing.T) {
s := newStore()
fc := newFakeClock()
s.clock = fc
var eidx uint64 = 2
s.Create("/foo", false, "bar", false, fc.Now().Add(500*time.Millisecond))
s.Create("/foofoo", false, "barbarbar", false, fc.Now().Add(500*time.Millisecond))
w, _ := s.Watch("/", true, false, 0)
assert.Equal(t, w.StartIndex(), eidx, "")
c := w.EventChan()
e := nbselect(c)
assert.Nil(t, e, "")
fc.Advance(600 * time.Millisecond)
s.DeleteExpiredKeys(fc.Now())
eidx = 3
e = nbselect(c)
assert.Equal(t, e.EtcdIndex, eidx, "")
assert.Equal(t, e.Action, "expire", "")
assert.Equal(t, e.Node.Key, "/foo", "")
w, _ = s.Watch("/", true, false, 4)
eidx = 4
assert.Equal(t, w.StartIndex(), eidx, "")
e = nbselect(w.EventChan())
assert.Equal(t, e.EtcdIndex, eidx, "")
assert.Equal(t, e.Action, "expire", "")
assert.Equal(t, e.Node.Key, "/foofoo", "")
}
开发者ID:mayank-chutani,项目名称:etcd,代码行数:30,代码来源:store_test.go
示例6: TestStoreGetSorted
// Ensure that the store can retrieve a directory in sorted order.
func TestStoreGetSorted(t *testing.T) {
s := newStore()
s.Create("/foo", true, "", false, Permanent)
s.Create("/foo/x", false, "0", false, Permanent)
s.Create("/foo/z", false, "0", false, Permanent)
s.Create("/foo/y", true, "", false, Permanent)
s.Create("/foo/y/a", false, "0", false, Permanent)
s.Create("/foo/y/b", false, "0", false, Permanent)
var eidx uint64 = 6
e, err := s.Get("/foo", true, true)
assert.Nil(t, err, "")
assert.Equal(t, e.EtcdIndex, eidx, "")
var yNodes NodeExterns
for _, node := range e.Node.Nodes {
switch node.Key {
case "/foo/x":
case "/foo/y":
yNodes = node.Nodes
case "/foo/z":
default:
t.Errorf("key = %s, not matched", node.Key)
}
}
for _, node := range yNodes {
switch node.Key {
case "/foo/y/a":
case "/foo/y/b":
default:
t.Errorf("key = %s, not matched", node.Key)
}
}
}
开发者ID:mayank-chutani,项目名称:etcd,代码行数:33,代码来源:store_test.go
示例7: TestStoreWatchExpireRefresh
// Ensure that the store can watch for key expiration when refreshing.
func TestStoreWatchExpireRefresh(t *testing.T) {
s := newStore()
fc := newFakeClock()
s.clock = fc
var eidx uint64 = 2
s.Create("/foo", false, "bar", false, TTLOptionSet{ExpireTime: fc.Now().Add(500 * time.Millisecond), Refresh: true})
s.Create("/foofoo", false, "barbarbar", false, TTLOptionSet{ExpireTime: fc.Now().Add(1200 * time.Millisecond), Refresh: true})
// Make sure we set watch updates when Refresh is true for newly created keys
w, _ := s.Watch("/", true, false, 0)
assert.Equal(t, w.StartIndex(), eidx, "")
c := w.EventChan()
e := nbselect(c)
assert.Nil(t, e, "")
fc.Advance(600 * time.Millisecond)
s.DeleteExpiredKeys(fc.Now())
eidx = 3
e = nbselect(c)
assert.Equal(t, e.EtcdIndex, eidx, "")
assert.Equal(t, e.Action, "expire", "")
assert.Equal(t, e.Node.Key, "/foo", "")
s.Update("/foofoo", "", TTLOptionSet{ExpireTime: fc.Now().Add(500 * time.Millisecond), Refresh: true})
w, _ = s.Watch("/", true, false, 4)
fc.Advance(700 * time.Millisecond)
s.DeleteExpiredKeys(fc.Now())
eidx = 5 // We should skip 4 because a TTL update should occur with no watch notification
assert.Equal(t, w.StartIndex(), eidx-1, "")
e = nbselect(w.EventChan())
assert.Equal(t, e.EtcdIndex, eidx, "")
assert.Equal(t, e.Action, "expire", "")
assert.Equal(t, e.Node.Key, "/foofoo", "")
}
开发者ID:lrita,项目名称:etcd,代码行数:35,代码来源:store_test.go
示例8: TestStoreUpdateValue
// Ensure that the store can update a key if it already exists.
func TestStoreUpdateValue(t *testing.T) {
s := newStore()
// create /foo=bar
s.Create("/foo", false, "bar", false, Permanent)
// update /foo="bzr"
var eidx uint64 = 2
e, err := s.Update("/foo", "baz", Permanent)
assert.Nil(t, err, "")
assert.Equal(t, e.EtcdIndex, eidx, "")
assert.Equal(t, e.Action, "update", "")
assert.Equal(t, e.Node.Key, "/foo", "")
assert.False(t, e.Node.Dir, "")
assert.Equal(t, *e.Node.Value, "baz", "")
assert.Equal(t, e.Node.TTL, 0, "")
assert.Equal(t, e.Node.ModifiedIndex, uint64(2), "")
// check prevNode
assert.Equal(t, e.PrevNode.Key, "/foo", "")
assert.Equal(t, *e.PrevNode.Value, "bar", "")
assert.Equal(t, e.PrevNode.TTL, 0, "")
assert.Equal(t, e.PrevNode.ModifiedIndex, uint64(1), "")
e, _ = s.Get("/foo", false, false)
assert.Equal(t, *e.Node.Value, "baz", "")
assert.Equal(t, e.EtcdIndex, eidx, "")
// update /foo=""
eidx = 3
e, err = s.Update("/foo", "", Permanent)
assert.Nil(t, err, "")
assert.Equal(t, e.EtcdIndex, eidx, "")
assert.Equal(t, e.Action, "update", "")
assert.Equal(t, e.Node.Key, "/foo", "")
assert.False(t, e.Node.Dir, "")
assert.Equal(t, *e.Node.Value, "", "")
assert.Equal(t, e.Node.TTL, 0, "")
assert.Equal(t, e.Node.ModifiedIndex, uint64(3), "")
// check prevNode
assert.Equal(t, e.PrevNode.Key, "/foo", "")
assert.Equal(t, *e.PrevNode.Value, "baz", "")
assert.Equal(t, e.PrevNode.TTL, 0, "")
assert.Equal(t, e.PrevNode.ModifiedIndex, uint64(2), "")
e, _ = s.Get("/foo", false, false)
assert.Equal(t, e.EtcdIndex, eidx, "")
assert.Equal(t, *e.Node.Value, "", "")
}
开发者ID:mayank-chutani,项目名称:etcd,代码行数:47,代码来源:store_test.go
示例9: TestStoreWatchRecursiveDeleteWithHiddenKey
// Ensure that the store doesn't see hidden key deletes without an exact path match in recursive mode.
func TestStoreWatchRecursiveDeleteWithHiddenKey(t *testing.T) {
s := newStore()
s.Create("/foo/_bar", false, "baz", false, TTLOptionSet{ExpireTime: Permanent})
w, _ := s.Watch("/foo", true, false, 0)
s.Delete("/foo/_bar", false, false)
e := nbselect(w.EventChan())
assert.Nil(t, e, "")
}
开发者ID:lrita,项目名称:etcd,代码行数:9,代码来源:store_test.go
示例10: TestStoreDeleteDiretoryFailsIfNonRecursiveAndDir
// Ensure that the store cannot delete a directory if both of recursive
// and dir are not specified.
func TestStoreDeleteDiretoryFailsIfNonRecursiveAndDir(t *testing.T) {
s := newStore()
s.Create("/foo", true, "", false, Permanent)
e, _err := s.Delete("/foo", false, false)
err := _err.(*etcdErr.Error)
assert.Equal(t, err.ErrorCode, etcdErr.EcodeNotFile, "")
assert.Equal(t, err.Message, "Not a file", "")
assert.Nil(t, e, "")
}
开发者ID:mayank-chutani,项目名称:etcd,代码行数:11,代码来源:store_test.go
示例11: TestStoreUpdateFailsIfDirectory
// Ensure that the store cannot update a directory.
func TestStoreUpdateFailsIfDirectory(t *testing.T) {
s := newStore()
s.Create("/foo", true, "", false, Permanent)
e, _err := s.Update("/foo", "baz", Permanent)
err := _err.(*etcdErr.Error)
assert.Equal(t, err.ErrorCode, etcdErr.EcodeNotFile, "")
assert.Equal(t, err.Message, "Not a file", "")
assert.Equal(t, err.Cause, "/foo", "")
assert.Nil(t, e, "")
}
开发者ID:mayank-chutani,项目名称:etcd,代码行数:11,代码来源:store_test.go
示例12: TestStoreCreateDirectory
// Ensure that the store can create a new directory if it doesn't already exist.
func TestStoreCreateDirectory(t *testing.T) {
s := newStore()
var eidx uint64 = 1
e, err := s.Create("/foo", true, "", false, Permanent)
assert.Nil(t, err, "")
assert.Equal(t, e.EtcdIndex, eidx, "")
assert.Equal(t, e.Action, "create", "")
assert.Equal(t, e.Node.Key, "/foo", "")
assert.True(t, e.Node.Dir, "")
}
开发者ID:mayank-chutani,项目名称:etcd,代码行数:11,代码来源:store_test.go
示例13: TestStoreRefresh
// Ensure that the store can update the TTL on a value with refresh.
func TestStoreRefresh(t *testing.T) {
s := newStore()
fc := newFakeClock()
s.clock = fc
s.Create("/foo", false, "bar", false, TTLOptionSet{ExpireTime: fc.Now().Add(500 * time.Millisecond)})
s.Create("/bar", true, "bar", false, TTLOptionSet{ExpireTime: fc.Now().Add(500 * time.Millisecond)})
_, err := s.Update("/foo", "", TTLOptionSet{ExpireTime: fc.Now().Add(500 * time.Millisecond), Refresh: true})
assert.Nil(t, err, "")
_, err = s.Set("/foo", false, "", TTLOptionSet{ExpireTime: fc.Now().Add(500 * time.Millisecond), Refresh: true})
assert.Nil(t, err, "")
_, err = s.Update("/bar", "", TTLOptionSet{ExpireTime: fc.Now().Add(500 * time.Millisecond), Refresh: true})
assert.Nil(t, err, "")
_, err = s.CompareAndSwap("/foo", "bar", 0, "", TTLOptionSet{ExpireTime: fc.Now().Add(500 * time.Millisecond), Refresh: true})
assert.Nil(t, err, "")
}
开发者ID:lrita,项目名称:etcd,代码行数:20,代码来源:store_test.go
示例14: TestStoreWatchUpdateWithHiddenKey
// Ensure that the store doesn't see hidden key updates.
func TestStoreWatchUpdateWithHiddenKey(t *testing.T) {
s := newStore()
s.Create("/_foo", false, "bar", false, Permanent)
w, _ := s.Watch("/_foo", false, false, 0)
s.Update("/_foo", "baz", Permanent)
e := nbselect(w.EventChan())
assert.Equal(t, e.Action, "update", "")
assert.Equal(t, e.Node.Key, "/_foo", "")
e = nbselect(w.EventChan())
assert.Nil(t, e, "")
}
开发者ID:mayank-chutani,项目名称:etcd,代码行数:12,代码来源:store_test.go
示例15: TestStoreGetValue
// Ensure that the store can retrieve an existing value.
func TestStoreGetValue(t *testing.T) {
s := newStore()
s.Create("/foo", false, "bar", false, Permanent)
var eidx uint64 = 1
e, err := s.Get("/foo", false, false)
assert.Nil(t, err, "")
assert.Equal(t, e.EtcdIndex, eidx, "")
assert.Equal(t, e.Action, "get", "")
assert.Equal(t, e.Node.Key, "/foo", "")
assert.Equal(t, *e.Node.Value, "bar", "")
}
开发者ID:mayank-chutani,项目名称:etcd,代码行数:12,代码来源:store_test.go
示例16: TestStoreRecover
// Ensure that the store can recover from a previously saved state.
func TestStoreRecover(t *testing.T) {
s := newStore()
var eidx uint64 = 3
s.Create("/foo", true, "", false, Permanent)
s.Create("/foo/x", false, "bar", false, Permanent)
s.Create("/foo/y", false, "baz", false, Permanent)
b, err := s.Save()
s2 := newStore()
s2.Recovery(b)
e, err := s.Get("/foo/x", false, false)
assert.Equal(t, e.EtcdIndex, eidx, "")
assert.Nil(t, err, "")
assert.Equal(t, *e.Node.Value, "bar", "")
e, err = s.Get("/foo/y", false, false)
assert.Equal(t, e.EtcdIndex, eidx, "")
assert.Nil(t, err, "")
assert.Equal(t, *e.Node.Value, "baz", "")
}
开发者ID:ericcapricorn,项目名称:etcd,代码行数:22,代码来源:store_test.go
示例17: TestStoreWatchCreateWithHiddenKey
// Ensure that the store can watch for hidden keys as long as it's an exact path match.
func TestStoreWatchCreateWithHiddenKey(t *testing.T) {
s := newStore()
var eidx uint64 = 1
w, _ := s.Watch("/_foo", false, false, 0)
s.Create("/_foo", false, "bar", false, Permanent)
e := nbselect(w.EventChan())
assert.Equal(t, e.EtcdIndex, eidx, "")
assert.Equal(t, e.Action, "create", "")
assert.Equal(t, e.Node.Key, "/_foo", "")
e = nbselect(w.EventChan())
assert.Nil(t, e, "")
}
开发者ID:mayank-chutani,项目名称:etcd,代码行数:13,代码来源:store_test.go
示例18: TestStoreCreateValue
// Ensure that the store can create a new key if it doesn't already exist.
func TestStoreCreateValue(t *testing.T) {
s := newStore()
// Create /foo=bar
var eidx uint64 = 1
e, err := s.Create("/foo", false, "bar", false, Permanent)
assert.Nil(t, err, "")
assert.Equal(t, e.EtcdIndex, eidx, "")
assert.Equal(t, e.Action, "create", "")
assert.Equal(t, e.Node.Key, "/foo", "")
assert.False(t, e.Node.Dir, "")
assert.Equal(t, *e.Node.Value, "bar", "")
assert.Nil(t, e.Node.Nodes, "")
assert.Nil(t, e.Node.Expiration, "")
assert.Equal(t, e.Node.TTL, 0, "")
assert.Equal(t, e.Node.ModifiedIndex, uint64(1), "")
// Create /empty=""
eidx = 2
e, err = s.Create("/empty", false, "", false, Permanent)
assert.Nil(t, err, "")
assert.Equal(t, e.EtcdIndex, eidx, "")
assert.Equal(t, e.Action, "create", "")
assert.Equal(t, e.Node.Key, "/empty", "")
assert.False(t, e.Node.Dir, "")
assert.Equal(t, *e.Node.Value, "", "")
assert.Nil(t, e.Node.Nodes, "")
assert.Nil(t, e.Node.Expiration, "")
assert.Equal(t, e.Node.TTL, 0, "")
assert.Equal(t, e.Node.ModifiedIndex, uint64(2), "")
}
开发者ID:mayank-chutani,项目名称:etcd,代码行数:32,代码来源:store_test.go
示例19: TestStoreWatchExpireWithHiddenKey
// Ensure that the store doesn't see expirations of hidden keys.
func TestStoreWatchExpireWithHiddenKey(t *testing.T) {
s := newStore()
fc := newFakeClock()
s.clock = fc
s.Create("/_foo", false, "bar", false, fc.Now().Add(500*time.Millisecond))
s.Create("/foofoo", false, "barbarbar", false, fc.Now().Add(1000*time.Millisecond))
w, _ := s.Watch("/", true, false, 0)
c := w.EventChan()
e := nbselect(c)
assert.Nil(t, e, "")
fc.Advance(600 * time.Millisecond)
s.DeleteExpiredKeys(fc.Now())
e = nbselect(c)
assert.Nil(t, e, "")
fc.Advance(600 * time.Millisecond)
s.DeleteExpiredKeys(fc.Now())
e = nbselect(c)
assert.Equal(t, e.Action, "expire", "")
assert.Equal(t, e.Node.Key, "/foofoo", "")
}
开发者ID:mayank-chutani,项目名称:etcd,代码行数:23,代码来源:store_test.go
示例20: TestStoreWatchDeleteWithHiddenKey
// Ensure that the store can watch for key deletions.
func TestStoreWatchDeleteWithHiddenKey(t *testing.T) {
s := newStore()
var eidx uint64 = 2
s.Create("/_foo", false, "bar", false, TTLOptionSet{ExpireTime: Permanent})
w, _ := s.Watch("/_foo", false, false, 0)
s.Delete("/_foo", false, false)
e := nbselect(w.EventChan())
assert.Equal(t, e.EtcdIndex, eidx, "")
assert.Equal(t, e.Action, "delete", "")
assert.Equal(t, e.Node.Key, "/_foo", "")
e = nbselect(w.EventChan())
assert.Nil(t, e, "")
}
开发者ID:lrita,项目名称:etcd,代码行数:14,代码来源:store_test.go
注:本文中的github.com/coreos/etcd/Godeps/_workspace/src/github.com/stretchr/testify/assert.Nil函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论