mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
client: add Node.TTLDuration()
This commit is contained in:
parent
0b082b7bd4
commit
ee9e336fd4
@ -274,6 +274,11 @@ func (n *Node) String() string {
|
||||
return fmt.Sprintf("{Key: %s, CreatedIndex: %d, ModifiedIndex: %d, TTL: %d}", n.Key, n.CreatedIndex, n.ModifiedIndex, n.TTL)
|
||||
}
|
||||
|
||||
// TTLDuration returns the Node's TTL as a time.Duration object
|
||||
func (n *Node) TTLDuration() time.Duration {
|
||||
return time.Duration(n.TTL) * time.Second
|
||||
}
|
||||
|
||||
type httpKeysAPI struct {
|
||||
client httpClient
|
||||
prefix string
|
||||
|
@ -1313,3 +1313,26 @@ func TestHTTPKeysAPIUpdateAction(t *testing.T) {
|
||||
kAPI := httpKeysAPI{client: &actionAssertingHTTPClient{t: t, act: act}}
|
||||
kAPI.Update(context.Background(), "/foo", "bar")
|
||||
}
|
||||
|
||||
func TestNodeTTLDuration(t *testing.T) {
|
||||
tests := []struct {
|
||||
node *Node
|
||||
want time.Duration
|
||||
}{
|
||||
{
|
||||
node: &Node{TTL: 0},
|
||||
want: 0,
|
||||
},
|
||||
{
|
||||
node: &Node{TTL: 97},
|
||||
want: 97 * time.Second,
|
||||
},
|
||||
}
|
||||
|
||||
for i, tt := range tests {
|
||||
got := tt.node.TTLDuration()
|
||||
if tt.want != got {
|
||||
t.Errorf("#%d: incorrect duration: want=%v got=%v", i, tt.want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user