本文整理汇总了Golang中github.com/coreos/etcd/third_party/github.com/stretchr/testify/assert.NoError函数的典型用法代码示例。如果您正苦于以下问题:Golang NoError函数的具体用法?Golang NoError怎么用?Golang NoError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NoError函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestModLeaderSet
// Ensure that a leader can be set and read.
func TestModLeaderSet(t *testing.T) {
tests.RunServer(func(s *server.Server) {
// Set leader.
body, status, err := testSetLeader(s, "foo", "xxx", 10)
assert.NoError(t, err)
assert.Equal(t, status, 200)
assert.Equal(t, body, "2")
// Check that the leader is set.
body, status, err = testGetLeader(s, "foo")
assert.NoError(t, err)
assert.Equal(t, status, 200)
assert.Equal(t, body, "xxx")
// Delete leader.
body, status, err = testDeleteLeader(s, "foo", "xxx")
assert.NoError(t, err)
assert.Equal(t, status, 200)
assert.Equal(t, body, "")
// Check that the leader is removed.
body, status, err = testGetLeader(s, "foo")
assert.NoError(t, err)
assert.Equal(t, status, 200)
assert.Equal(t, body, "")
})
}
开发者ID:BREWTAN,项目名称:etcd,代码行数:28,代码来源:mod_leader_test.go
示例2: TestModLockAcquireNoWait
// Ensure that a lock succeeds when timeout=0 (nowait)
func TestModLockAcquireNoWait(t *testing.T) {
tests.RunServer(func(s *server.Server) {
c := make(chan bool)
// Acquire lock with no waiting.
go func() {
body, status, err := testAcquireLockWithTimeout(s, "foo", "first", 10, 0)
assert.NoError(t, err)
assert.Equal(t, status, 200)
assert.Equal(t, body, "2")
c <- true
}()
<-c
time.Sleep(1 * time.Second)
// Check that we have the lock #1.
body, status, err := testGetLockIndex(s, "foo")
assert.NoError(t, err)
assert.Equal(t, status, 200)
assert.Equal(t, body, "2")
// Release lock #1.
_, status, err = testReleaseLock(s, "foo", "2", "")
assert.NoError(t, err)
assert.Equal(t, status, 200)
// Check that we have no lock.
body, status, err = testGetLockIndex(s, "foo")
assert.NoError(t, err)
assert.Equal(t, status, 200)
})
}
开发者ID:BREWTAN,项目名称:etcd,代码行数:34,代码来源:mod_lock_test.go
示例3: TestModLeaderRenew
// Ensure that a leader can be renewed.
func TestModLeaderRenew(t *testing.T) {
tests.RunServer(func(s *server.Server) {
// Set leader.
body, status, err := testSetLeader(s, "foo", "xxx", 2)
assert.NoError(t, err)
assert.Equal(t, status, 200)
assert.Equal(t, body, "2")
time.Sleep(1 * time.Second)
// Renew leader.
body, status, err = testSetLeader(s, "foo", "xxx", 3)
assert.NoError(t, err)
assert.Equal(t, status, 200)
assert.Equal(t, body, "2")
time.Sleep(2 * time.Second)
// Check that the leader is set.
body, status, err = testGetLeader(s, "foo")
assert.NoError(t, err)
assert.Equal(t, status, 200)
assert.Equal(t, body, "xxx")
})
}
开发者ID:BREWTAN,项目名称:etcd,代码行数:26,代码来源:mod_leader_test.go
示例4: TestStandbyAutoPromote
// Create a full cluster, disconnect a peer, wait for autodemotion, wait for autopromotion.
func TestStandbyAutoPromote(t *testing.T) {
t.Skip("functionality unimplemented")
clusterSize := 10 // DefaultActiveSize + 1
_, etcds, err := CreateCluster(clusterSize, &os.ProcAttr{Files: []*os.File{nil, os.Stdout, os.Stderr}}, false)
if err != nil {
t.Fatal("cannot create cluster")
}
defer func() {
// Wrap this in a closure so that it picks up the updated version of
// the "etcds" variable.
DestroyCluster(etcds)
}()
c := etcd.NewClient(nil)
c.SyncCluster()
time.Sleep(1 * time.Second)
// Verify that we have one standby.
result, err := c.Get("_etcd/standbys", false, true)
assert.NoError(t, err)
assert.Equal(t, len(result.Node.Nodes), 1)
// Reconfigure with a short promote delay (2 second).
resp, _ := tests.Put("http://localhost:7001/v2/admin/config", "application/json", bytes.NewBufferString(`{"activeSize":9, "promoteDelay":2}`))
if !assert.Equal(t, resp.StatusCode, 200) {
t.FailNow()
}
// Remove peer.
etcd := etcds[1]
etcds = append(etcds[:1], etcds[2:]...)
if err := etcd.Kill(); err != nil {
panic(err.Error())
}
etcd.Release()
// Wait for it to get dropped.
time.Sleep(server.PeerActivityMonitorTimeout + (2 * time.Second))
// Wait for the standby to be promoted.
time.Sleep(server.ActiveMonitorTimeout + (2 * time.Second))
// Verify that we have 9 peers.
result, err = c.Get("_etcd/machines", true, true)
assert.NoError(t, err)
assert.Equal(t, len(result.Node.Nodes), 9)
// Verify that node10 is one of those peers.
result, err = c.Get("_etcd/machines/node10", false, false)
assert.NoError(t, err)
// Verify that there are no more standbys.
result, err = c.Get("_etcd/standbys", false, true)
assert.NoError(t, err)
if assert.Equal(t, len(result.Node.Nodes), 1) {
assert.Equal(t, result.Node.Nodes[0].Key, "/_etcd/standbys/node2")
}
}
开发者ID:nvdnkpr,项目名称:etcd,代码行数:61,代码来源:standby_test.go
示例5: TestModLockAcquireAndReleaseByValue
// Ensure that a lock can be acquired with a value and released by value.
func TestModLockAcquireAndReleaseByValue(t *testing.T) {
tests.RunServer(func(s *server.Server) {
// Acquire lock.
body, status, err := testAcquireLock(s, "foo", "XXX", 10)
assert.NoError(t, err)
assert.Equal(t, status, 200)
assert.Equal(t, body, "2")
// Check that we have the lock.
body, status, err = testGetLockValue(s, "foo")
assert.NoError(t, err)
assert.Equal(t, status, 200)
assert.Equal(t, body, "XXX")
// Release lock.
body, status, err = testReleaseLock(s, "foo", "", "XXX")
assert.NoError(t, err)
assert.Equal(t, status, 200)
assert.Equal(t, body, "")
// Check that we released the lock.
body, status, err = testGetLockValue(s, "foo")
assert.NoError(t, err)
assert.Equal(t, status, 200)
assert.Equal(t, body, "")
})
}
开发者ID:kakkartushar1,项目名称:ArangoDB,代码行数:28,代码来源:mod_lock_test.go
示例6: TestStandbyAutoJoin
// Create a full cluster, disconnect a peer, wait for removal, wait for standby join.
func TestStandbyAutoJoin(t *testing.T) {
clusterSize := 5
_, etcds, err := CreateCluster(clusterSize, &os.ProcAttr{Files: []*os.File{nil, os.Stdout, os.Stderr}}, false)
if err != nil {
t.Fatal("cannot create cluster")
}
defer func() {
// Wrap this in a closure so that it picks up the updated version of
// the "etcds" variable.
DestroyCluster(etcds)
}()
c := etcd.NewClient(nil)
c.SyncCluster()
time.Sleep(1 * time.Second)
// Verify that we have five machines.
result, err := c.Get("_etcd/machines", false, true)
assert.NoError(t, err)
assert.Equal(t, len(result.Node.Nodes), 5)
// Reconfigure with a short remove delay (2 second).
resp, _ := tests.Put("http://localhost:7001/v2/admin/config", "application/json", bytes.NewBufferString(`{"activeSize":4, "removeDelay":2, "syncInterval":1}`))
if !assert.Equal(t, resp.StatusCode, 200) {
t.FailNow()
}
// Wait for a monitor cycle before checking for removal.
time.Sleep(server.ActiveMonitorTimeout + (1 * time.Second))
// Verify that we now have four peers.
result, err = c.Get("_etcd/machines", false, true)
assert.NoError(t, err)
assert.Equal(t, len(result.Node.Nodes), 4)
// Remove peer.
etcd := etcds[1]
etcds = append(etcds[:1], etcds[2:]...)
if err := etcd.Kill(); err != nil {
panic(err.Error())
}
etcd.Release()
// Wait for it to get dropped.
time.Sleep(server.PeerActivityMonitorTimeout + (1 * time.Second))
// Wait for the standby to join.
time.Sleep((1 * time.Second) + (1 * time.Second))
// Verify that we have 4 peers.
result, err = c.Get("_etcd/machines", true, true)
assert.NoError(t, err)
assert.Equal(t, len(result.Node.Nodes), 4)
// Verify that node2 is not one of those peers.
_, err = c.Get("_etcd/machines/node2", false, false)
assert.Error(t, err)
}
开发者ID:BREWTAN,项目名称:etcd,代码行数:60,代码来源:standby_test.go
示例7: TestStandbyJoinMiss
func TestStandbyJoinMiss(t *testing.T) {
clusterSize := 2
_, etcds, err := CreateCluster(clusterSize, &os.ProcAttr{Files: []*os.File{nil, os.Stdout, os.Stderr}}, false)
if err != nil {
t.Fatal("cannot create cluster")
}
defer DestroyCluster(etcds)
c := etcd.NewClient(nil)
c.SyncCluster()
time.Sleep(1 * time.Second)
// Verify that we have two machines.
result, err := c.Get("_etcd/machines", false, true)
assert.NoError(t, err)
assert.Equal(t, len(result.Node.Nodes), clusterSize)
resp, _ := tests.Put("http://localhost:7001/v2/admin/config", "application/json", bytes.NewBufferString(`{"removeDelay":4, "syncInterval":4}`))
if !assert.Equal(t, resp.StatusCode, 200) {
t.FailNow()
}
time.Sleep(time.Second)
resp, _ = tests.Delete("http://localhost:7001/v2/admin/machines/node2", "application/json", nil)
if !assert.Equal(t, resp.StatusCode, 200) {
t.FailNow()
}
// Wait for a monitor cycle before checking for removal.
time.Sleep(server.ActiveMonitorTimeout + (1 * time.Second))
// Verify that we now have one peer.
result, err = c.Get("_etcd/machines", false, true)
assert.NoError(t, err)
assert.Equal(t, len(result.Node.Nodes), 1)
// Simulate the join failure
_, err = server.NewClient(nil).AddMachine("http://localhost:7001",
&server.JoinCommand{
MinVersion: store.MinVersion(),
MaxVersion: store.MaxVersion(),
Name: "node2",
RaftURL: "http://127.0.0.1:7002",
EtcdURL: "http://127.0.0.1:4002",
})
assert.NoError(t, err)
time.Sleep(6 * time.Second)
go tests.Delete("http://localhost:7001/v2/admin/machines/node2", "application/json", nil)
time.Sleep(time.Second)
result, err = c.Get("_etcd/machines", false, true)
assert.NoError(t, err)
assert.Equal(t, len(result.Node.Nodes), 1)
}
开发者ID:jerrysearch,项目名称:etcd,代码行数:57,代码来源:standby_test.go
示例8: TestClusterConfigReload
// Ensure that the cluster configuration can be reloaded.
func TestClusterConfigReload(t *testing.T) {
procAttr := &os.ProcAttr{Files: []*os.File{nil, os.Stdout, os.Stderr}}
argGroup, etcds, err := CreateCluster(3, procAttr, false)
assert.NoError(t, err)
defer DestroyCluster(etcds)
resp, _ := tests.Put("http://localhost:7001/v2/admin/config", "application/json", bytes.NewBufferString(`{"activeSize":3, "removeDelay":60}`))
assert.Equal(t, resp.StatusCode, 200)
time.Sleep(1 * time.Second)
resp, _ = tests.Get("http://localhost:7002/v2/admin/config")
body := tests.ReadBodyJSON(resp)
assert.Equal(t, resp.StatusCode, 200)
assert.Equal(t, body["activeSize"], 3)
assert.Equal(t, body["removeDelay"], 60)
// kill all
DestroyCluster(etcds)
for i := 0; i < 3; i++ {
etcds[i], err = os.StartProcess(EtcdBinPath, argGroup[i], procAttr)
}
time.Sleep(1 * time.Second)
resp, _ = tests.Get("http://localhost:7002/v2/admin/config")
body = tests.ReadBodyJSON(resp)
assert.Equal(t, resp.StatusCode, 200)
assert.Equal(t, body["activeSize"], 3)
assert.Equal(t, body["removeDelay"], 60)
}
开发者ID:BREWTAN,项目名称:etcd,代码行数:33,代码来源:cluster_config_test.go
示例9: TestModLockAcquireNoWaitWhileLocked
// Ensure that a lock honours the timeout=0 (nowait) option when lock is already held
func TestModLockAcquireNoWaitWhileLocked(t *testing.T) {
tests.RunServer(func(s *server.Server) {
c := make(chan bool)
// Acquire lock #1.
go func() {
body, status, err := testAcquireLock(s, "foo", "first", 10)
assert.NoError(t, err)
assert.Equal(t, status, 200)
assert.Equal(t, body, "2")
c <- true
}()
<-c
// Attempt to acquire lock #2; fail if no lock immediately acquired
waiting := true
go func() {
c <- true
_, status, err := testAcquireLockWithTimeout(s, "foo", "second", 10, 0)
assert.NoError(t, err)
assert.Equal(t, status, 500)
waiting = false
}()
<-c
time.Sleep(1 * time.Second)
// Check that we have the lock #1.
body, status, err := testGetLockIndex(s, "foo")
assert.NoError(t, err)
assert.Equal(t, status, 200)
assert.Equal(t, body, "2")
// Check that we are not still waiting for lock #2.
assert.Equal(t, waiting, false)
// Release lock #1.
_, status, err = testReleaseLock(s, "foo", "2", "")
assert.NoError(t, err)
assert.Equal(t, status, 200)
// Check that we have no lock.
body, status, err = testGetLockIndex(s, "foo")
assert.NoError(t, err)
assert.Equal(t, status, 200)
})
}
开发者ID:BREWTAN,项目名称:etcd,代码行数:48,代码来源:mod_lock_test.go
示例10: TestModLockBlockUntilAcquire
// Ensure that a lock can be acquired and another process is blocked until released.
func TestModLockBlockUntilAcquire(t *testing.T) {
tests.RunServer(func(s *server.Server) {
c := make(chan bool)
// Acquire lock #1.
go func() {
body, status, err := testAcquireLock(s, "foo", "", 10)
assert.NoError(t, err)
assert.Equal(t, status, 200)
assert.Equal(t, body, "2")
c <- true
}()
<-c
// Acquire lock #2.
waiting := true
go func() {
c <- true
body, status, err := testAcquireLock(s, "foo", "", 10)
assert.NoError(t, err)
assert.Equal(t, status, 200)
assert.Equal(t, body, "4")
waiting = false
}()
<-c
time.Sleep(1 * time.Second)
// Check that we have the lock #1.
body, status, err := testGetLockIndex(s, "foo")
assert.NoError(t, err)
assert.Equal(t, status, 200)
assert.Equal(t, body, "2")
// Check that we are still waiting for lock #2.
assert.Equal(t, waiting, true)
// Release lock #1.
_, status, err = testReleaseLock(s, "foo", "2", "")
assert.NoError(t, err)
assert.Equal(t, status, 200)
// Check that we have lock #2.
body, status, err = testGetLockIndex(s, "foo")
assert.NoError(t, err)
assert.Equal(t, status, 200)
assert.Equal(t, body, "4")
// Release lock #2.
_, status, err = testReleaseLock(s, "foo", "4", "")
assert.NoError(t, err)
assert.Equal(t, status, 200)
// Check that we have no lock.
body, status, err = testGetLockIndex(s, "foo")
assert.NoError(t, err)
assert.Equal(t, status, 200)
assert.Equal(t, body, "")
})
}
开发者ID:kakkartushar1,项目名称:ArangoDB,代码行数:61,代码来源:mod_lock_test.go
示例11: TestConfigDeprecatedNameFlag
func TestConfigDeprecatedNameFlag(t *testing.T) {
_, stderr := capture(func() {
c := New()
err := c.LoadFlags([]string{"-n", "test-name"})
assert.NoError(t, err)
assert.Equal(t, c.Name, "test-name", "")
})
assert.Equal(t, stderr, "[deprecated] use -name, not -n\n", "")
}
开发者ID:RubanDeventhiran,项目名称:etcd,代码行数:9,代码来源:config_test.go
示例12: TestConfigDeprecatedPeersFileFlag
func TestConfigDeprecatedPeersFileFlag(t *testing.T) {
_, stderr := capture(func() {
c := New()
err := c.LoadFlags([]string{"-CF", "/tmp/machines"})
assert.NoError(t, err)
assert.Equal(t, c.PeersFile, "/tmp/machines", "")
})
assert.Equal(t, stderr, "[deprecated] use -peers-file, not -CF\n", "")
}
开发者ID:RubanDeventhiran,项目名称:etcd,代码行数:9,代码来源:config_test.go
示例13: TestConfigDeprecatedMaxRetryAttemptsFlag
func TestConfigDeprecatedMaxRetryAttemptsFlag(t *testing.T) {
_, stderr := capture(func() {
c := New()
err := c.LoadFlags([]string{"-r", "10"})
assert.NoError(t, err)
assert.Equal(t, c.MaxRetryAttempts, 10, "")
})
assert.Equal(t, stderr, "[deprecated] use -max-retry-attempts, not -r\n", "")
}
开发者ID:RubanDeventhiran,项目名称:etcd,代码行数:9,代码来源:config_test.go
示例14: TestConfigDeprecatedCertFileFlag
func TestConfigDeprecatedCertFileFlag(t *testing.T) {
_, stderr := capture(func() {
c := New()
err := c.LoadFlags([]string{"-clientCert", "/tmp/file.cert"})
assert.NoError(t, err)
assert.Equal(t, c.CertFile, "/tmp/file.cert", "")
})
assert.Equal(t, stderr, "[deprecated] use -cert-file, not -clientCert\n", "")
}
开发者ID:RubanDeventhiran,项目名称:etcd,代码行数:9,代码来源:config_test.go
示例15: TestConfigDeprecatedPeersFlag
func TestConfigDeprecatedPeersFlag(t *testing.T) {
_, stderr := capture(func() {
c := New()
err := c.LoadFlags([]string{"-C", "coreos.com:4001,coreos.com:4002"})
assert.NoError(t, err)
assert.Equal(t, c.Peers, []string{"coreos.com:4001", "coreos.com:4002"}, "")
})
assert.Equal(t, stderr, "[deprecated] use -peers, not -C\n", "")
}
开发者ID:RubanDeventhiran,项目名称:etcd,代码行数:9,代码来源:config_test.go
示例16: TestConfigDeprecatedMaxClusterSizeFlag
func TestConfigDeprecatedMaxClusterSizeFlag(t *testing.T) {
_, stderr := capture(func() {
c := New()
err := c.LoadFlags([]string{"-maxsize", "5"})
assert.NoError(t, err)
assert.Equal(t, c.MaxClusterSize, 5, "")
})
assert.Equal(t, stderr, "[deprecated] use -max-cluster-size, not -maxsize\n", "")
}
开发者ID:johntdyer,项目名称:golang-devops-stuff,代码行数:9,代码来源:config_test.go
示例17: TestConfigDeprecatedAddrFlag
func TestConfigDeprecatedAddrFlag(t *testing.T) {
_, stderr := capture(func() {
c := New()
err := c.LoadFlags([]string{"-c", "127.0.0.1:4002"})
assert.NoError(t, err)
assert.Equal(t, c.Addr, "127.0.0.1:4002")
})
assert.Equal(t, stderr, "[deprecated] use -addr, not -c\n")
}
开发者ID:RubanDeventhiran,项目名称:etcd,代码行数:9,代码来源:config_test.go
示例18: TestConfigDeprecatedMaxResultBufferFlag
func TestConfigDeprecatedMaxResultBufferFlag(t *testing.T) {
_, stderr := capture(func() {
c := New()
err := c.LoadFlags([]string{"-m", "512"})
assert.NoError(t, err)
assert.Equal(t, c.MaxResultBuffer, 512, "")
})
assert.Equal(t, stderr, "[deprecated] use -max-result-buffer, not -m\n", "")
}
开发者ID:johntdyer,项目名称:golang-devops-stuff,代码行数:9,代码来源:config_test.go
示例19: TestConfigDeprecatedPeerBindAddrFlag
func TestConfigDeprecatedPeerBindAddrFlag(t *testing.T) {
_, stderr := capture(func() {
c := New()
err := c.LoadFlags([]string{"-sl", "127.0.0.1:4003"})
assert.NoError(t, err)
assert.Equal(t, c.Peer.BindAddr, "127.0.0.1:4003", "")
})
assert.Equal(t, stderr, "[deprecated] use -peer-bind-addr, not -sl\n", "")
}
开发者ID:RubanDeventhiran,项目名称:etcd,代码行数:9,代码来源:config_test.go
示例20: TestConfigDeprecatedPeerKeyFileFlag
func TestConfigDeprecatedPeerKeyFileFlag(t *testing.T) {
_, stderr := capture(func() {
c := New()
err := c.LoadFlags([]string{"-serverKey", "/tmp/peer/file.key"})
assert.NoError(t, err)
assert.Equal(t, c.Peer.KeyFile, "/tmp/peer/file.key", "")
})
assert.Equal(t, stderr, "[deprecated] use -peer-key-file, not -serverKey\n", "")
}
开发者ID:RubanDeventhiran,项目名称:etcd,代码行数:9,代码来源:config_test.go
注:本文中的github.com/coreos/etcd/third_party/github.com/stretchr/testify/assert.NoError函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论