client: add dir/ttl fields into node

release-2.1
Xiang Li 2015-04-06 21:47:20 -07:00
parent 471aa1aa89
commit 666a97271d
2 changed files with 34 additions and 2 deletions

View File

@ -234,6 +234,9 @@ type Node struct {
// Key represents the unique location of this Node (e.g. "/foo/bar").
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
// is a directory, Value will be empty.
Value string `json:"value"`
@ -248,10 +251,16 @@ type Node struct {
// ModifiedIndex is the etcd index at-which this Node was last modified.
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 {
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 {

View File

@ -483,6 +483,9 @@ func assertRequest(got http.Request, wantMethod string, wantURL *url.URL, wantHe
}
func TestUnmarshalSuccessfulResponse(t *testing.T) {
var expiration time.Time
expiration.UnmarshalText([]byte("2015-04-07T04:40:23.044979686Z"))
tests := []struct {
hdr string
body string
@ -518,7 +521,7 @@ func TestUnmarshalSuccessfulResponse(t *testing.T) {
// Node
{
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{
Action: "get",
Index: 15,
@ -527,6 +530,26 @@ func TestUnmarshalSuccessfulResponse(t *testing.T) {
Value: "bar",
ModifiedIndex: 12,
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,
},