• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang tests.RunServer函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/coreos/etcd/tests.RunServer函数的典型用法代码示例。如果您正苦于以下问题:Golang RunServer函数的具体用法?Golang RunServer怎么用?Golang RunServer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了RunServer函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestV2GetKeyRecursively

// Ensures that a directory of values can be recursively retrieved for a given key.
//
//   $ curl -X PUT localhost:4001/v2/keys/foo/x -d value=XXX
//   $ curl -X PUT localhost:4001/v2/keys/foo/y/z -d value=YYY
//   $ curl localhost:4001/v2/keys/foo -d recursive=true
//
func TestV2GetKeyRecursively(t *testing.T) {
	tests.RunServer(func(s *server.Server) {
		v := url.Values{}
		v.Set("value", "XXX")
		v.Set("ttl", "10")
		resp, _ := tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/x"), v)
		tests.ReadBody(resp)

		v.Set("value", "YYY")
		resp, _ = tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/y/z"), v)
		tests.ReadBody(resp)

		resp, _ = tests.Get(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo?recursive=true"))
		body := tests.ReadBodyJSON(resp)
		assert.Equal(t, body["action"], "get", "")
		assert.Equal(t, body["key"], "/foo", "")
		assert.Equal(t, body["dir"], true, "")
		assert.Equal(t, body["modifiedIndex"], 1, "")
		assert.Equal(t, len(body["kvs"].([]interface{})), 2, "")

		kv0 := body["kvs"].([]interface{})[0].(map[string]interface{})
		assert.Equal(t, kv0["key"], "/foo/x", "")
		assert.Equal(t, kv0["value"], "XXX", "")
		assert.Equal(t, kv0["ttl"], 10, "")

		kv1 := body["kvs"].([]interface{})[1].(map[string]interface{})
		assert.Equal(t, kv1["key"], "/foo/y", "")
		assert.Equal(t, kv1["dir"], true, "")

		kvs2 := kv1["kvs"].([]interface{})[0].(map[string]interface{})
		assert.Equal(t, kvs2["key"], "/foo/y/z", "")
		assert.Equal(t, kvs2["value"], "YYY", "")
	})
}
开发者ID:ronnylt,项目名称:etcd,代码行数:40,代码来源:get_handler_test.go


示例2: 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


示例3: 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


示例4: TestV1GetKeyDir

// Ensures that a directory of values can be retrieved for a given key.
//
//   $ curl -X PUT localhost:4001/v1/keys/foo/x -d value=XXX
//   $ curl -X PUT localhost:4001/v1/keys/foo/y/z -d value=YYY
//   $ curl localhost:4001/v1/keys/foo
//
func TestV1GetKeyDir(t *testing.T) {
	tests.RunServer(func(s *server.Server) {
		v := url.Values{}
		v.Set("value", "XXX")
		resp, _ := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v1/keys/foo/x"), v)
		tests.ReadBody(resp)

		v.Set("value", "YYY")
		resp, _ = tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v1/keys/foo/y/z"), v)
		tests.ReadBody(resp)

		resp, _ = tests.Get(fmt.Sprintf("%s%s", s.URL(), "/v1/keys/foo"))
		assert.Equal(t, resp.StatusCode, http.StatusOK)
		body := tests.ReadBody(resp)
		nodes := make([]interface{}, 0)
		if err := json.Unmarshal(body, &nodes); err != nil {
			panic(fmt.Sprintf("HTTP body JSON parse error: %v", err))
		}
		assert.Equal(t, len(nodes), 2, "")

		node0 := nodes[0].(map[string]interface{})
		assert.Equal(t, node0["action"], "get", "")
		assert.Equal(t, node0["key"], "/foo/x", "")
		assert.Equal(t, node0["value"], "XXX", "")

		node1 := nodes[1].(map[string]interface{})
		assert.Equal(t, node1["action"], "get", "")
		assert.Equal(t, node1["key"], "/foo/y", "")
		assert.Equal(t, node1["dir"], true, "")
	})
}
开发者ID:kennylixi,项目名称:etcd,代码行数:37,代码来源:get_handler_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: TestModLockRenew

// Ensure that a lock can be renewed.
func TestModLockRenew(t *testing.T) {
	tests.RunServer(func(s *server.Server) {
		// Acquire lock.
		body, err := testAcquireLock(s, "foo", "", 3)
		assert.NoError(t, err)
		assert.Equal(t, body, "2")

		time.Sleep(2 * time.Second)

		// Check that we have the lock.
		body, err = testGetLockIndex(s, "foo")
		assert.NoError(t, err)
		assert.Equal(t, body, "2")

		// Renew lock.
		body, err = testRenewLock(s, "foo", "2", "", 3)
		assert.NoError(t, err)
		assert.Equal(t, body, "")

		time.Sleep(2 * time.Second)

		// Check that we still have the lock.
		body, err = testGetLockIndex(s, "foo")
		assert.NoError(t, err)
		assert.Equal(t, body, "2")

		time.Sleep(2 * time.Second)

		// Check that lock was released.
		body, err = testGetLockIndex(s, "foo")
		assert.NoError(t, err)
		assert.Equal(t, body, "")
	})
}
开发者ID:kula,项目名称:etcd,代码行数:35,代码来源:mod_lock_test.go


示例7: 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


示例8: 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


示例9: TestV2UpdateKeySuccessWithTTL

// Ensures that a key could update TTL.
//
//   $ curl -X PUT localhost:4001/v2/keys/foo -d value=XXX
//   $ curl -X PUT localhost:4001/v2/keys/foo -d value=XXX -d ttl=1000 -d prevExist=true
//   $ curl -X PUT localhost:4001/v2/keys/foo -d value=XXX -d ttl= -d prevExist=true
//
func TestV2UpdateKeySuccessWithTTL(t *testing.T) {
	tests.RunServer(func(s *server.Server) {
		v := url.Values{}
		v.Set("value", "XXX")
		resp, _ := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo"), v)
		assert.Equal(t, resp.StatusCode, http.StatusCreated)
		node := (tests.ReadBodyJSON(resp)["node"]).(map[string]interface{})
		createdIndex := node["createdIndex"]

		v.Set("ttl", "1000")
		v.Set("prevExist", "true")
		resp, _ = tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo"), v)
		assert.Equal(t, resp.StatusCode, http.StatusOK)
		node = (tests.ReadBodyJSON(resp)["node"]).(map[string]interface{})
		assert.Equal(t, node["value"], "XXX", "")
		assert.Equal(t, node["ttl"], 1000, "")
		assert.NotEqual(t, node["expiration"], "", "")
		assert.Equal(t, node["createdIndex"], createdIndex, "")

		v.Del("ttl")
		resp, _ = tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo"), v)
		assert.Equal(t, resp.StatusCode, http.StatusOK)
		node = (tests.ReadBodyJSON(resp)["node"]).(map[string]interface{})
		assert.Equal(t, node["value"], "XXX", "")
		assert.Equal(t, node["ttl"], nil, "")
		assert.Equal(t, node["expiration"], nil, "")
		assert.Equal(t, node["createdIndex"], createdIndex, "")
	})
}
开发者ID:BREWTAN,项目名称:etcd,代码行数:35,代码来源:put_handler_test.go


示例10: 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


示例11: TestDiscoverySecondPeerFirstNoResponse

// TestDiscoverySecondPeerFirstNoResponse ensures that if the first etcd
// machine stops after heartbeating that the second machine fails too.
func TestDiscoverySecondPeerFirstNoResponse(t *testing.T) {
	etcdtest.RunServer(func(s *server.Server) {
		v := url.Values{}
		v.Set("value", "started")
		resp, err := etcdtest.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/_etcd/registry/2/_state"), v)
		assert.Equal(t, resp.StatusCode, http.StatusCreated)

		v = url.Values{}
		v.Set("value", "http://127.0.0.1:49151")
		resp, err = etcdtest.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/_etcd/registry/2/ETCDTEST"), v)
		assert.Equal(t, resp.StatusCode, http.StatusCreated)

		proc, err := startServer([]string{"-retry-interval", "0.2", "-discovery", s.URL() + "/v2/keys/_etcd/registry/2"})
		if err != nil {
			t.Fatal(err.Error())
		}
		defer stopServer(proc)

		// TODO(bp): etcd will take 30 seconds to shutdown, figure this
		// out instead
		time.Sleep(1 * time.Second)

		client := http.Client{}
		_, err = client.Get("/")
		if err != nil && strings.Contains(err.Error(), "connection reset by peer") {
			t.Fatal(err.Error())
		}
	})
}
开发者ID:joshuaconner,项目名称:etcd,代码行数:31,代码来源:discovery_test.go


示例12: TestDiscoveryDownWithBackupPeers

// TestDiscoveryDownWithBackupPeers ensures that etcd runs if it is started with a
// bad discovery URL and a peer list.
func TestDiscoveryDownWithBackupPeers(t *testing.T) {
	etcdtest.RunServer(func(s *server.Server) {
		g := garbageHandler{t: t}
		ts := httptest.NewServer(&g)
		defer ts.Close()

		discover := ts.URL + "/v2/keys/_etcd/registry/1"
		u, ok := s.PeerHost("ETCDTEST")
		if !ok {
			t.Fatalf("Couldn't find the URL")
		}
		proc, err := startServer([]string{"-discovery", discover, "-peers", u})

		if err != nil {
			t.Fatal(err.Error())
		}
		defer stopServer(proc)

		client := http.Client{}
		err = assertServerFunctional(client, "http")
		if err != nil {
			t.Fatal(err.Error())
		}

		if !g.success {
			t.Fatal("Discovery server never called")
		}
	})
}
开发者ID:joshuaconner,项目名称:etcd,代码行数:31,代码来源:discovery_test.go


示例13: 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{})
		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:neildunbar,项目名称:etcd,代码行数:12,代码来源:put_handler_test.go


示例14: TestV2SetKey

// Ensures that a key is set to a given value.
//
//   $ curl -X PUT localhost:4001/v2/keys/foo/bar -d value=XXX
//
func TestV2SetKey(t *testing.T) {
	tests.RunServer(func(s *server.Server) {
		v := url.Values{}
		v.Set("value", "XXX")
		resp, err := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar"), v)
		body := tests.ReadBody(resp)
		assert.Nil(t, err, "")
		assert.Equal(t, string(body), `{"action":"set","node":{"key":"/foo/bar","value":"XXX","modifiedIndex":2,"createdIndex":2}}`, "")
	})
}
开发者ID:nexagames,项目名称:etcd,代码行数:14,代码来源:put_handler_test.go


示例15: TestV2SetKeyCASWithEmptyValueSuccess

// Ensure that we can set an empty value
//
//   $ curl -X PUT localhost:4001/v2/keys/foo/bar -d value=
//
func TestV2SetKeyCASWithEmptyValueSuccess(t *testing.T) {
	tests.RunServer(func(s *server.Server) {
		v := url.Values{}
		v.Set("value", "")
		resp, _ := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar"), v)
		assert.Equal(t, resp.StatusCode, http.StatusCreated)
		body := tests.ReadBody(resp)
		assert.Equal(t, string(body), `{"action":"set","node":{"key":"/foo/bar","value":"","modifiedIndex":2,"createdIndex":2}}`)
	})
}
开发者ID:heroku,项目名称:etcd,代码行数:14,代码来源:put_handler_test.go


示例16: TestV2CreateKeySuccess

// Ensures that a key is conditionally set only if it previously did not exist.
//
//   $ curl -X PUT localhost:4001/v2/keys/foo/bar -d value=XXX -d prevExist=false
//
func TestV2CreateKeySuccess(t *testing.T) {
	tests.RunServer(func(s *server.Server) {
		v := url.Values{}
		v.Set("value", "XXX")
		v.Set("prevExist", "false")
		resp, _ := tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar"), v)
		body := tests.ReadBodyJSON(resp)
		assert.Equal(t, body["value"], "XXX", "")
	})
}
开发者ID:ronnylt,项目名称:etcd,代码行数:14,代码来源:put_handler_test.go


示例17: TestV1CreateKeySuccess

// Ensures that a key is conditionally set if it previously did not exist.
//
//   $ curl -X PUT localhost:4001/v1/keys/foo/bar -d value=XXX -d prevValue=
//
func TestV1CreateKeySuccess(t *testing.T) {
	tests.RunServer(func(s *server.Server) {
		v := url.Values{}
		v.Set("value", "XXX")
		v.Set("prevValue", "")
		resp, _ := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v1/keys/foo/bar"), v)
		assert.Equal(t, resp.StatusCode, http.StatusOK)
		body := tests.ReadBodyJSON(resp)
		assert.Equal(t, body["value"], "XXX", "")
	})
}
开发者ID:BREWTAN,项目名称:etcd,代码行数:15,代码来源:put_handler_test.go


示例18: TestV2DeleteDirectoryRecursiveImpliesDir

// Ensures that a directory is deleted when recursive is set.
//
//   $ curl -X PUT localhost:4001/v2/keys/foo?dir=true
//   $ curl -X DELETE localhost:4001/v2/keys/foo?recursive=true
//
func TestV2DeleteDirectoryRecursiveImpliesDir(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{})
		tests.ReadBody(resp)
		resp, err = tests.DeleteForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo?recursive=true"), url.Values{})
		assert.Equal(t, resp.StatusCode, http.StatusOK)
		body := tests.ReadBody(resp)
		assert.Nil(t, err, "")
		assert.Equal(t, string(body), `{"action":"delete","node":{"key":"/foo","dir":true,"modifiedIndex":3,"createdIndex":2}}`, "")
	})
}
开发者ID:Web5design,项目名称:etcd,代码行数:16,代码来源:delete_handler_test.go


示例19: TestV2DeleteKeyCADWithInvalidValue

// Ensures that an error is thrown if an invalid previous value is provided.
//
//   $ curl -X PUT localhost:4001/v2/keys/foo/bar -d value=XXX
//   $ curl -X DELETE localhost:4001/v2/keys/foo/bar?prevIndex=
//
func TestV2DeleteKeyCADWithInvalidValue(t *testing.T) {
	tests.RunServer(func(s *server.Server) {
		v := url.Values{}
		v.Set("value", "XXX")
		resp, _ := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar"), v)
		tests.ReadBody(resp)
		resp, _ = tests.DeleteForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar?prevValue="), v)
		body := tests.ReadBodyJSON(resp)
		assert.Equal(t, body["errorCode"], 201)
	})
}
开发者ID:kisom,项目名称:etcd,代码行数:16,代码来源:delete_handler_test.go


示例20: TestV2DeleteKey

// Ensures that a key is deleted.
//
//   $ curl -X PUT localhost:4001/v2/keys/foo/bar -d value=XXX
//   $ curl -X DELETE localhost:4001/v2/keys/foo/bar
//
func TestV2DeleteKey(t *testing.T) {
	tests.RunServer(func(s *server.Server) {
		v := url.Values{}
		v.Set("value", "XXX")
		resp, err := tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar"), v)
		tests.ReadBody(resp)
		resp, err = tests.DeleteForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar"), url.Values{})
		body := tests.ReadBody(resp)
		assert.Nil(t, err, "")
		assert.Equal(t, string(body), `{"action":"delete","key":"/foo/bar","prevValue":"XXX","modifiedIndex":2}`, "")
	})
}
开发者ID:ronnylt,项目名称:etcd,代码行数:17,代码来源:delete_handler_test.go



注:本文中的github.com/coreos/etcd/tests.RunServer函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang context.Background函数代码示例发布时间:2022-05-23
下一篇:
Golang tests.ReadBodyJSON函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap