本文整理汇总了Golang中github.com/coreos/etcd/third_party/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
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.Action, "delete", "")
// check pervNode
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:rwindelz,项目名称:etcd,代码行数:31,代码来源:store_test.go
示例2: TestConfigDataDirGuess
// Ensures that a DataDir gets guessed if not specified
func TestConfigDataDirGuess(t *testing.T) {
c := New()
assert.Nil(t, c.LoadFlags([]string{}), "")
assert.Nil(t, c.Sanitize())
name, _ := os.Hostname()
assert.Equal(t, c.DataDir, name+".etcd", "")
}
开发者ID:RubanDeventhiran,项目名称:etcd,代码行数:8,代码来源:config_test.go
示例3: TestConfigClusterSyncIntervalFlag
func TestConfigClusterSyncIntervalFlag(t *testing.T) {
c := New()
assert.Nil(t, c.LoadFlags([]string{"-http-read-timeout", "2.34"}), "")
assert.Equal(t, c.HTTPReadTimeout, 2.34, "")
assert.Nil(t, c.LoadFlags([]string{"-http-write-timeout", "1.23"}), "")
assert.Equal(t, c.HTTPWriteTimeout, 1.23, "")
}
开发者ID:RubanDeventhiran,项目名称:etcd,代码行数:7,代码来源:config_test.go
示例4: TestConfigNameGuess
// Ensures that a Name gets guessed if not specified
func TestConfigNameGuess(t *testing.T) {
c := New()
assert.Nil(t, c.LoadFlags([]string{}), "")
assert.Nil(t, c.Sanitize())
name, _ := os.Hostname()
assert.Equal(t, c.Name, name, "")
}
开发者ID:RubanDeventhiran,项目名称:etcd,代码行数:8,代码来源:config_test.go
示例5: TestV1ClusterMigration
// Ensure that we can start a v2 cluster from the logs of a v1 cluster.
func TestV1ClusterMigration(t *testing.T) {
path, _ := ioutil.TempDir("", "etcd-")
os.RemoveAll(path)
defer os.RemoveAll(path)
nodes := []string{"node0", "node2"}
for i, node := range nodes {
nodepath := filepath.Join(path, node)
fixturepath, _ := filepath.Abs(filepath.Join("../fixtures/v1.cluster/", node))
fmt.Println("FIXPATH =", fixturepath)
fmt.Println("NODEPATH =", nodepath)
os.MkdirAll(filepath.Dir(nodepath), 0777)
// Copy over fixture files.
c := exec.Command("cp", "-rf", fixturepath, nodepath)
if out, err := c.CombinedOutput(); err != nil {
fmt.Println(">>>>>>\n", string(out), "<<<<<<")
panic("Fixture initialization error:" + err.Error())
}
procAttr := new(os.ProcAttr)
procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
args := []string{"etcd", fmt.Sprintf("-data-dir=%s", nodepath)}
args = append(args, "-addr", fmt.Sprintf("127.0.0.1:%d", 4001+i))
args = append(args, "-peer-addr", fmt.Sprintf("127.0.0.1:%d", 7001+i))
args = append(args, "-name", node)
process, err := os.StartProcess(EtcdBinPath, args, procAttr)
if err != nil {
t.Fatal("start process failed:" + err.Error())
return
}
defer process.Kill()
time.Sleep(time.Second)
}
// Ensure deleted message is removed.
resp, err := tests.Get("http://localhost:4001/v2/keys/message")
body := tests.ReadBody(resp)
assert.Nil(t, err, "")
assert.Equal(t, resp.StatusCode, http.StatusNotFound)
assert.Equal(t, string(body), `{"errorCode":100,"message":"Key not found","cause":"/message","index":11}`+"\n")
// Ensure TTL'd message is removed.
resp, err = tests.Get("http://localhost:4001/v2/keys/foo")
body = tests.ReadBody(resp)
assert.Nil(t, err, "")
assert.Equal(t, resp.StatusCode, 200, "")
assert.Equal(t, string(body), `{"action":"get","node":{"key":"/foo","value":"one","modifiedIndex":9,"createdIndex":9}}`)
}
开发者ID:BREWTAN,项目名称:etcd,代码行数:51,代码来源:v1_migration_test.go
示例6: 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:rwindelz,项目名称:etcd,代码行数:15,代码来源:store_test.go
示例7: TestV1WatchKeyWithIndex
// Ensures that a watcher can wait for a value to be set after a given index.
//
// $ curl -X POST localhost:4001/v1/watch/foo/bar -d index=4
// $ curl -X PUT localhost:4001/v1/keys/foo/bar -d value=XXX
// $ curl -X PUT localhost:4001/v1/keys/foo/bar -d value=YYY
//
func TestV1WatchKeyWithIndex(t *testing.T) {
tests.RunServer(func(s *server.Server) {
var body map[string]interface{}
c := make(chan bool)
go func() {
v := url.Values{}
v.Set("index", "3")
resp, _ := tests.PostForm(fmt.Sprintf("%s%s", s.URL(), "/v1/watch/foo/bar"), v)
body = tests.ReadBodyJSON(resp)
c <- true
}()
// Make sure response didn't fire early.
time.Sleep(1 * time.Millisecond)
assert.Nil(t, body, "")
// Set a value (before given index).
v := url.Values{}
v.Set("value", "XXX")
resp, _ := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v1/keys/foo/bar"), v)
tests.ReadBody(resp)
// Make sure response didn't fire early.
time.Sleep(1 * time.Millisecond)
assert.Nil(t, body, "")
// Set a value (before given index).
v.Set("value", "YYY")
resp, _ = tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v1/keys/foo/bar"), v)
tests.ReadBody(resp)
// A response should follow from the GET above.
time.Sleep(1 * time.Millisecond)
select {
case <-c:
default:
t.Fatal("cannot get watch result")
}
assert.NotNil(t, body, "")
assert.Equal(t, body["action"], "set", "")
assert.Equal(t, body["key"], "/foo/bar", "")
assert.Equal(t, body["value"], "YYY", "")
assert.Equal(t, body["index"], 3, "")
})
}
开发者ID:kennylixi,项目名称:etcd,代码行数:55,代码来源:get_handler_test.go
示例8: 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)
e, err := s.Get("/foo", true, true)
assert.Nil(t, err, "")
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:b2ornot2b,项目名称:etcd,代码行数:31,代码来源:store_test.go
示例9: TestStoreGetDirectory
// Ensure that the store can recrusively retrieve a directory listing.
// Note that hidden files should not be returned.
func TestStoreGetDirectory(t *testing.T) {
s := newStore()
s.Create("/foo", true, "", false, Permanent)
s.Create("/foo/bar", false, "X", false, Permanent)
s.Create("/foo/_hidden", false, "*", false, Permanent)
s.Create("/foo/baz", true, "", false, Permanent)
s.Create("/foo/baz/bat", false, "Y", false, Permanent)
s.Create("/foo/baz/_hidden", false, "*", false, Permanent)
s.Create("/foo/baz/ttl", false, "Y", false, time.Now().Add(time.Second*3))
e, err := s.Get("/foo", true, false)
assert.Nil(t, err, "")
assert.Equal(t, e.Action, "get", "")
assert.Equal(t, e.Node.Key, "/foo", "")
assert.Equal(t, len(e.Node.Nodes), 2, "")
assert.Equal(t, e.Node.Nodes[0].Key, "/foo/bar", "")
assert.Equal(t, e.Node.Nodes[0].Value, "X", "")
assert.Equal(t, e.Node.Nodes[0].Dir, false, "")
assert.Equal(t, e.Node.Nodes[1].Key, "/foo/baz", "")
assert.Equal(t, e.Node.Nodes[1].Dir, true, "")
assert.Equal(t, len(e.Node.Nodes[1].Nodes), 2, "")
assert.Equal(t, e.Node.Nodes[1].Nodes[0].Key, "/foo/baz/bat", "")
assert.Equal(t, e.Node.Nodes[1].Nodes[0].Value, "Y", "")
assert.Equal(t, e.Node.Nodes[1].Nodes[0].Dir, false, "")
assert.Equal(t, e.Node.Nodes[1].Nodes[1].Key, "/foo/baz/ttl", "")
assert.Equal(t, e.Node.Nodes[1].Nodes[1].Value, "Y", "")
assert.Equal(t, e.Node.Nodes[1].Nodes[1].Dir, false, "")
assert.Equal(t, e.Node.Nodes[1].Nodes[1].TTL, 3, "")
}
开发者ID:rwindelz,项目名称:etcd,代码行数:30,代码来源:store_test.go
示例10: TestStoreWatchExpire
// Ensure that the store can watch for key expiration.
func TestStoreWatchExpire(t *testing.T) {
s := newStore()
stopChan := make(chan bool)
defer func() {
stopChan <- true
}()
go mockSyncService(s.DeleteExpiredKeys, stopChan)
s.Create("/foo", false, "bar", false, time.Now().Add(500*time.Millisecond))
s.Create("/foofoo", false, "barbarbar", false, time.Now().Add(500*time.Millisecond))
w, _ := s.Watch("/", true, false, 0)
c := w.EventChan
e := nbselect(c)
assert.Nil(t, e, "")
time.Sleep(600 * time.Millisecond)
e = nbselect(c)
assert.Equal(t, e.Action, "expire", "")
assert.Equal(t, e.Node.Key, "/foo", "")
w, _ = s.Watch("/", true, false, 4)
e = nbselect(w.EventChan)
assert.Equal(t, e.Action, "expire", "")
assert.Equal(t, e.Node.Key, "/foofoo", "")
}
开发者ID:rwindelz,项目名称:etcd,代码行数:26,代码来源:store_test.go
示例11: TestV2CreateUnique
// Ensures a unique value is added to the key's children.
//
// $ curl -X POST localhost:4001/v2/keys/foo/bar
// $ curl -X POST localhost:4001/v2/keys/foo/bar
// $ curl -X POST localhost:4001/v2/keys/foo/baz
//
func TestV2CreateUnique(t *testing.T) {
tests.RunServer(func(s *server.Server) {
// POST should add index to list.
fullURL := fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar")
resp, _ := tests.PostForm(fullURL, nil)
assert.Equal(t, resp.StatusCode, http.StatusCreated)
body := tests.ReadBodyJSON(resp)
assert.Equal(t, body["action"], "create", "")
node := body["node"].(map[string]interface{})
assert.Equal(t, node["key"], "/foo/bar/3", "")
assert.Nil(t, node["dir"], "")
assert.Equal(t, node["modifiedIndex"], 3, "")
// Second POST should add next index to list.
resp, _ = tests.PostForm(fullURL, nil)
assert.Equal(t, resp.StatusCode, http.StatusCreated)
body = tests.ReadBodyJSON(resp)
node = body["node"].(map[string]interface{})
assert.Equal(t, node["key"], "/foo/bar/4", "")
// POST to a different key should add index to that list.
resp, _ = tests.PostForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/baz"), nil)
assert.Equal(t, resp.StatusCode, http.StatusCreated)
body = tests.ReadBodyJSON(resp)
node = body["node"].(map[string]interface{})
assert.Equal(t, node["key"], "/foo/baz/5", "")
})
}
开发者ID:BREWTAN,项目名称:etcd,代码行数:37,代码来源:post_handler_test.go
示例12: 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:digideskio,项目名称:etcd,代码行数:47,代码来源:store_test.go
示例13: TestStoreCreateDirectory
// Ensure that the store can create a new directory if it doesn't already exist.
func TestStoreCreateDirectory(t *testing.T) {
s := newStore()
e, err := s.Create("/foo", true, "", false, Permanent)
assert.Nil(t, err, "")
assert.Equal(t, e.Action, "create", "")
assert.Equal(t, e.Node.Key, "/foo", "")
assert.True(t, e.Node.Dir, "")
}
开发者ID:rwindelz,项目名称:etcd,代码行数:9,代码来源:store_test.go
示例14: TestV2SetDirectory
// Ensures that a directory is created
//
// $ curl -X PUT localhost:4001/v2/keys/foo/bar?dir=true
//
func TestV2SetDirectory(t *testing.T) {
tests.RunServer(func(s *server.Server) {
resp, err := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo?dir=true"), url.Values{})
assert.Equal(t, resp.StatusCode, http.StatusCreated)
body := tests.ReadBody(resp)
assert.Nil(t, err, "")
assert.Equal(t, string(body), `{"action":"set","node":{"key":"/foo","dir":true,"modifiedIndex":2,"createdIndex":2}}`, "")
})
}
开发者ID:heroku,项目名称:etcd,代码行数:13,代码来源:put_handler_test.go
示例15: TestConfigCLIArgsOverrideEnvVar
// Ensures that an environment variable field is overridden by a command line argument.
func TestConfigCLIArgsOverrideEnvVar(t *testing.T) {
os.Setenv("ETCD_ADDR", "127.0.0.1:1000")
defer os.Setenv("ETCD_ADDR", "")
c := New()
c.SystemPath = ""
assert.Nil(t, c.Load([]string{"-addr", "127.0.0.1:2000"}), "")
assert.Equal(t, c.Addr, "127.0.0.1:2000", "")
}
开发者ID:RubanDeventhiran,项目名称:etcd,代码行数:10,代码来源:config_test.go
示例16: TestStoreRecover
// Ensure that the store can recover from a previously saved state.
func TestStoreRecover(t *testing.T) {
s := newStore()
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.Nil(t, err, "")
assert.Equal(t, e.Node.Value, "bar", "")
e, err = s.Get("/foo/y", false, false)
assert.Nil(t, err, "")
assert.Equal(t, e.Node.Value, "baz", "")
}
开发者ID:rwindelz,项目名称:etcd,代码行数:19,代码来源:store_test.go
示例17: TestStoreGetValue
// Ensure that the store can retrieve an existing value.
func TestStoreGetValue(t *testing.T) {
s := newStore()
s.Create("/foo", false, "bar", false, Permanent)
e, err := s.Get("/foo", false, false)
assert.Nil(t, err, "")
assert.Equal(t, e.Action, "get", "")
assert.Equal(t, e.Node.Key, "/foo", "")
assert.Equal(t, e.Node.Value, "bar", "")
}
开发者ID:rwindelz,项目名称:etcd,代码行数:10,代码来源:store_test.go
示例18: 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:rwindelz,项目名称:etcd,代码行数:11,代码来源:store_test.go
示例19: 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()
w, _ := s.Watch("/_foo", false, false, 0)
s.Create("/_foo", false, "bar", false, Permanent)
e := nbselect(w.EventChan)
assert.Equal(t, e.Action, "create", "")
assert.Equal(t, e.Node.Key, "/_foo", "")
e = nbselect(w.EventChan)
assert.Nil(t, e, "")
}
开发者ID:rwindelz,项目名称:etcd,代码行数:11,代码来源:store_test.go
示例20: 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:rwindelz,项目名称:etcd,代码行数:11,代码来源:store_test.go
注:本文中的github.com/coreos/etcd/third_party/github.com/stretchr/testify/assert.Nil函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论