mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #2634 from xiang90/client-new
client: add dir/ttl fields into node
This commit is contained in:
commit
8e9f2bb9e6
@ -234,6 +234,9 @@ type Node struct {
|
|||||||
// Key represents the unique location of this Node (e.g. "/foo/bar").
|
// Key represents the unique location of this Node (e.g. "/foo/bar").
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
|
|
||||||
|
// Dir reports whether node describes a directory.
|
||||||
|
Dir bool `json:"dir,omitempty"`
|
||||||
|
|
||||||
// Value is the current data stored on this Node. If this Node
|
// Value is the current data stored on this Node. If this Node
|
||||||
// is a directory, Value will be empty.
|
// is a directory, Value will be empty.
|
||||||
Value string `json:"value"`
|
Value string `json:"value"`
|
||||||
@ -248,10 +251,16 @@ type Node struct {
|
|||||||
|
|
||||||
// ModifiedIndex is the etcd index at-which this Node was last modified.
|
// ModifiedIndex is the etcd index at-which this Node was last modified.
|
||||||
ModifiedIndex uint64 `json:"modifiedIndex"`
|
ModifiedIndex uint64 `json:"modifiedIndex"`
|
||||||
|
|
||||||
|
// Expiration is the server side expiration time of the key.
|
||||||
|
Expiration *time.Time `json:"expiration,omitempty"`
|
||||||
|
|
||||||
|
// TTL is the time to live of the key in second.
|
||||||
|
TTL int64 `json:"ttl,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) String() string {
|
func (n *Node) String() string {
|
||||||
return fmt.Sprintf("{Key: %s, CreatedIndex: %d, ModifiedIndex: %d}", n.Key, n.CreatedIndex, n.ModifiedIndex)
|
return fmt.Sprintf("{Key: %s, CreatedIndex: %d, ModifiedIndex: %d, TTL: %d}", n.Key, n.CreatedIndex, n.ModifiedIndex, n.TTL)
|
||||||
}
|
}
|
||||||
|
|
||||||
type httpKeysAPI struct {
|
type httpKeysAPI struct {
|
||||||
|
@ -483,6 +483,9 @@ func assertRequest(got http.Request, wantMethod string, wantURL *url.URL, wantHe
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestUnmarshalSuccessfulResponse(t *testing.T) {
|
func TestUnmarshalSuccessfulResponse(t *testing.T) {
|
||||||
|
var expiration time.Time
|
||||||
|
expiration.UnmarshalText([]byte("2015-04-07T04:40:23.044979686Z"))
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
hdr string
|
hdr string
|
||||||
body string
|
body string
|
||||||
@ -518,7 +521,7 @@ func TestUnmarshalSuccessfulResponse(t *testing.T) {
|
|||||||
// Node
|
// Node
|
||||||
{
|
{
|
||||||
hdr: "15",
|
hdr: "15",
|
||||||
body: `{"action":"get", "node": {"key": "/foo", "value": "bar", "modifiedIndex": 12, "createdIndex": 10}}`,
|
body: `{"action":"get", "node": {"key": "/foo", "value": "bar", "modifiedIndex": 12, "createdIndex": 10, "ttl": 10, "expiration": "2015-04-07T04:40:23.044979686Z"}}`,
|
||||||
wantRes: &Response{
|
wantRes: &Response{
|
||||||
Action: "get",
|
Action: "get",
|
||||||
Index: 15,
|
Index: 15,
|
||||||
@ -527,6 +530,26 @@ func TestUnmarshalSuccessfulResponse(t *testing.T) {
|
|||||||
Value: "bar",
|
Value: "bar",
|
||||||
ModifiedIndex: 12,
|
ModifiedIndex: 12,
|
||||||
CreatedIndex: 10,
|
CreatedIndex: 10,
|
||||||
|
TTL: 10,
|
||||||
|
Expiration: &expiration,
|
||||||
|
},
|
||||||
|
PrevNode: nil,
|
||||||
|
},
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Node Dir
|
||||||
|
{
|
||||||
|
hdr: "15",
|
||||||
|
body: `{"action":"get", "node": {"key": "/foo", "dir": true, "modifiedIndex": 12, "createdIndex": 10}}`,
|
||||||
|
wantRes: &Response{
|
||||||
|
Action: "get",
|
||||||
|
Index: 15,
|
||||||
|
Node: &Node{
|
||||||
|
Key: "/foo",
|
||||||
|
Dir: true,
|
||||||
|
ModifiedIndex: 12,
|
||||||
|
CreatedIndex: 10,
|
||||||
},
|
},
|
||||||
PrevNode: nil,
|
PrevNode: nil,
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user