-
Notifications
You must be signed in to change notification settings - Fork 5
/
02-lease.t
103 lines (74 loc) · 2.44 KB
/
02-lease.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!perl
use strict;
use warnings;
use Net::Etcd;
use Test::More;
use Test::Exception;
use Math::Int64 qw(int64_rand int64_to_string);
use Data::Dumper;
use Cwd;
my $config;
my $dir = getcwd;
if ( $ENV{ETCD_TEST_HOST} and $ENV{ETCD_TEST_PORT} ) {
$config->{host} = $ENV{ETCD_TEST_HOST};
$config->{port} = $ENV{ETCD_TEST_PORT};
$config->{ca_file} = $ENV{ETCD_CLIENT_CA_FILE} || "$dir/t/tls/ca.pem";
$config->{key_file} = $ENV{ETCD_CLIENT_KEY_FILE} || "$dir/t/tls/client-key.pem";
$config->{cert_file} = $ENV{ETCD_CLIENT_CERT_FILE} || "$dir/t/tls/client.pem";
$config->{ssl} = 1;
plan tests => 16;
}
else {
plan skip_all =>
"Please set environment variable ETCD_TEST_HOST and ETCD_TEST_PORT.";
}
my $etcd = Net::Etcd->new($config);
my $lease;
my $int64 = int64_rand();
my $lease_id = int64_to_string($int64);
# add lease
lives_ok(
sub {
$lease = $etcd->lease( { ID => $lease_id, TTL => 20 } )->grant;
},
"add a new lease"
);
cmp_ok( $lease->is_success, '==', 1, "add lease success" );
# add lease to key
lives_ok(
sub {
$lease =
$etcd->put( { key => 'foo2', value => 'bar2', lease => $lease_id } );
},
"add a new lease to a key"
);
cmp_ok( $lease->is_success, '==', 1, "add lease to key success" );
my $key;
# validate key
lives_ok( sub { $key = $etcd->range( { key => 'foo2' } )->get_value },
"check value for key" );
cmp_ok( $key, 'eq', 'bar2', "lease key value" );
# lease keep alive
lives_ok( sub { $lease = $etcd->lease( { ID => $lease_id } )->keepalive },
"lease_keep_alive" );
#print STDERR Dumper($lease);
cmp_ok( $lease->is_success, '==', 1, "reset lease keep alive success" );
# lease ttl
lives_ok( sub { $lease = $etcd->lease( { ID => $lease_id, keys => 1 } )->ttl },
"lease_ttl" );
cmp_ok( $lease->is_success, '==', 1, "return lease_ttl success" );
#print STDERR Dumper($lease);
# lease leases
lives_ok( sub { $lease = $etcd->lease()->leases }, "lease_leases" );
cmp_ok( $lease->is_success, '==', 1, "return lease_leases success" );
#print STDERR Dumper($lease);
# revoke lease
lives_ok( sub { $lease = $etcd->lease( { ID => $lease_id } )->revoke },
"revoke lease" );
#print STDERR Dumper($lease);
cmp_ok( $lease->is_success, '==', 1, "revoke lease success" );
# validate key
lives_ok( sub { $key = $etcd->range( { key => 'foo2' } )->get_value },
"check value for revoked lease key" );
is( $key, undef, "lease key revoked" );
1;