|
@@ -54,6 +54,32 @@ func TestSingleNode(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
t.Fatalf("Set 2 failed with %s %s %v", result.Key, result.Value, result.TTL)
|
|
t.Fatalf("Set 2 failed with %s %s %v", result.Key, result.Value, result.TTL)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // Add a test-and-set test
|
|
|
|
|
+
|
|
|
|
|
+ // First, we'll test we can change the value if we get it write
|
|
|
|
|
+ result, match, err := c.TestAndSet("foo", "bar", "foobar", 100)
|
|
|
|
|
+
|
|
|
|
|
+ if err != nil || result.Key != "/foo" || result.Value != "foobar" || result.PrevValue != "bar" || result.TTL != 99 || !match {
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ t.Fatal(err)
|
|
|
|
|
+ }
|
|
|
|
|
+ t.Fatalf("Set 3 failed with %s %s %v", result.Key, result.Value, result.TTL)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Next, we'll make sure we can't set it without the correct prior value
|
|
|
|
|
+ _, _, err = c.TestAndSet("foo", "bar", "foofoo", 100)
|
|
|
|
|
+
|
|
|
|
|
+ if err == nil {
|
|
|
|
|
+ t.Fatalf("Set 4 expecting error when setting key with incorrect previous value")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Finally, we'll make sure a blank previous value still counts as a test-and-set and still has to match
|
|
|
|
|
+ _, _, err = c.TestAndSet("foo", "", "barbar", 100)
|
|
|
|
|
+
|
|
|
|
|
+ if err == nil {
|
|
|
|
|
+ t.Fatalf("Set 5 expecting error when setting key with blank (incorrect) previous value")
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// TestInternalVersionFail will ensure that etcd does not come up if the internal raft
|
|
// TestInternalVersionFail will ensure that etcd does not come up if the internal raft
|