Skip to content

Commit

Permalink
Merge pull request #18 from mehcode/patch-1
Browse files Browse the repository at this point in the history
createdIndex and modifiedIndex are not present on the root node
  • Loading branch information
jimmycuadra committed Aug 5, 2017
2 parents 88f91fa + ba33021 commit bf7280f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/kv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub enum Action {
pub struct Node {
/// The new value of the etcd creation index.
#[serde(rename = "createdIndex")]
pub created_index: u64,
pub created_index: Option<u64>,
/// Whether or not the node is a directory.
pub dir: Option<bool>,
/// An ISO 8601 timestamp for when the key will expire.
Expand All @@ -87,7 +87,7 @@ pub struct Node {
pub key: Option<String>,
/// The new value of the etcd modification index.
#[serde(rename = "modifiedIndex")]
pub modified_index: u64,
pub modified_index: Option<u64>,
/// Child nodes of a directory.
pub nodes: Option<Vec<Node>>,
/// The key's time to live in seconds.
Expand Down
34 changes: 29 additions & 5 deletions tests/kv_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fn compare_and_delete() {
let work = kv::create(&client, "/test/foo", "bar", None).and_then(|res| {
let index = res.data.node.modified_index;

kv::compare_and_delete(&inner_client, "/test/foo", Some("bar"), Some(index))
kv::compare_and_delete(&inner_client, "/test/foo", Some("bar"), index)
.and_then(|res| {
assert_eq!(res.data.action, Action::CompareAndDelete);

Expand All @@ -144,7 +144,7 @@ fn compare_and_delete_only_index() {
let work = kv::create(&client, "/test/foo", "bar", None).and_then(|res| {
let index = res.data.node.modified_index;

kv::compare_and_delete(&inner_client, "/test/foo", None, Some(index)).and_then(|res| {
kv::compare_and_delete(&inner_client, "/test/foo", None, index).and_then(|res| {
assert_eq!(res.data.action, Action::CompareAndDelete);

Ok(())
Expand Down Expand Up @@ -211,7 +211,7 @@ fn test_compare_and_swap() {
"baz",
Some(100),
Some("bar"),
Some(index),
index,
).and_then(|res| {
assert_eq!(res.data.action, Action::CompareAndSwap);

Expand All @@ -231,7 +231,7 @@ fn compare_and_swap_only_index() {
let work = kv::create(&client, "/test/foo", "bar", None).and_then(|res| {
let index = res.data.node.modified_index;

kv::compare_and_swap(&inner_client, "/test/foo", "baz", None, None, Some(index))
kv::compare_and_swap(&inner_client, "/test/foo", "baz", None, None, index)
.and_then(|res| {
assert_eq!(res.data.action, Action::CompareAndSwap);

Expand Down Expand Up @@ -374,6 +374,30 @@ fn get_recursive() {
assert!(client.run(work).is_ok());
}

#[test]
fn get_root() {
let core = Core::new().unwrap();
let mut client = TestClient::new(core);
let inner_client = client.clone();

let work = kv::create(&client, "/test/foo", "bar", Some(60)).and_then(|_| {
kv::get(&inner_client, "/", GetOptions::default()).and_then(|res| {
assert_eq!(res.data.action, Action::Get);

let node = res.data.node;

assert!(node.created_index.is_none());
assert!(node.modified_index.is_none());
assert_eq!(node.nodes.unwrap().len(), 1);
assert_eq!(node.dir.unwrap(), true);

Ok(())
})
});

assert!(client.run(work).is_ok());
}

#[test]
fn https() {
let core = Core::new().unwrap();
Expand Down Expand Up @@ -656,7 +680,7 @@ fn watch_index() {
&inner_client,
"/test/foo",
WatchOptions {
index: Some(index),
index: index,
..Default::default()
},
).and_then(move |res| {
Expand Down

0 comments on commit bf7280f

Please sign in to comment.