From 3f85829e87a8769b6169bde947c7f8c6aa7690b9 Mon Sep 17 00:00:00 2001 From: Chris Shoemaker Date: Sat, 21 Dec 2013 14:21:44 -0500 Subject: [PATCH] fix(v2/tests): make comments and tests agree about what's being tested In cases where the comments were incorrect, this changes them to agree with the tests. In cases where the comments were correct, this extends the tests to cover the behavior described in the comment. --- server/v2/tests/delete_handler_test.go | 2 +- server/v2/tests/put_handler_test.go | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/server/v2/tests/delete_handler_test.go b/server/v2/tests/delete_handler_test.go index b6f7fa042..34021f846 100644 --- a/server/v2/tests/delete_handler_test.go +++ b/server/v2/tests/delete_handler_test.go @@ -31,7 +31,7 @@ func TestV2DeleteKey(t *testing.T) { // Ensures that an empty directory is deleted when dir is set. // // $ curl -X PUT localhost:4001/v2/keys/foo?dir=true -// $ curl -X PUT localhost:4001/v2/keys/foo ->fail +// $ curl -X DELETE localhost:4001/v2/keys/foo ->fail // $ curl -X DELETE localhost:4001/v2/keys/foo?dir=true // func TestV2DeleteEmptyDirectory(t *testing.T) { diff --git a/server/v2/tests/put_handler_test.go b/server/v2/tests/put_handler_test.go index 7ece21aac..20eddec31 100644 --- a/server/v2/tests/put_handler_test.go +++ b/server/v2/tests/put_handler_test.go @@ -77,7 +77,7 @@ func TestV2SetKeyWithBadTTL(t *testing.T) { }) } -// Ensures that a key is conditionally set only if it previously did not exist. +// Ensures that a key is conditionally set if it previously did not exist. // // $ curl -X PUT localhost:4001/v2/keys/foo/bar -d value=XXX -d prevExist=false // @@ -93,10 +93,10 @@ func TestV2CreateKeySuccess(t *testing.T) { }) } -// Ensures that a key is not conditionally because it previously existed. +// Ensures that a key is not conditionally set because it previously existed. // -// $ curl -X PUT localhost:4001/v2/keys/foo/bar -d value=XXX // $ curl -X PUT localhost:4001/v2/keys/foo/bar -d value=XXX -d prevExist=false +// $ curl -X PUT localhost:4001/v2/keys/foo/bar -d value=XXX -d prevExist=false -> fail // func TestV2CreateKeyFail(t *testing.T) { tests.RunServer(func(s *server.Server) { @@ -158,19 +158,25 @@ func TestV2UpdateKeyFailOnValue(t *testing.T) { // Ensures that a key is not conditionally set if it previously did not exist. // -// $ curl -X PUT localhost:4001/v2/keys/foo -d value=XXX -d prevExist=true -// $ curl -X PUT localhost:4001/v2/keys/foo/bar -d value=XXX -d prevExist=true +// $ curl -X PUT localhost:4001/v2/keys/foo -d value=YYY -d prevExist=true -> fail +// $ curl -X PUT localhost:4001/v2/keys/foo/bar -d value=YYY -d prevExist=true -> fail // func TestV2UpdateKeyFailOnMissingDirectory(t *testing.T) { tests.RunServer(func(s *server.Server) { v := url.Values{} v.Set("value", "YYY") v.Set("prevExist", "true") - resp, _ := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar"), v) + resp, _ := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo"), v) body := tests.ReadBodyJSON(resp) assert.Equal(t, body["errorCode"], 100, "") assert.Equal(t, body["message"], "Key not found", "") assert.Equal(t, body["cause"], "/foo", "") + + resp, _ = tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar"), v) + body = tests.ReadBodyJSON(resp) + assert.Equal(t, body["errorCode"], 100, "") + assert.Equal(t, body["message"], "Key not found", "") + assert.Equal(t, body["cause"], "/foo", "") }) }