Skip to content

Commit

Permalink
etcdserver tests: test dir=true and prevExist=true
Browse files Browse the repository at this point in the history
Test that if dir=true and prevExist=true PUT only if the target node is a
directory. Otherwise return "Not a directory".
Addresses issue etcd-io#518 on github
  • Loading branch information
iankronquist committed Jan 25, 2015
1 parent 28fad9c commit ab27cb3
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions etcdserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"time"

"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
etcdErr "github.com/coreos/etcd/error"
pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
"github.com/coreos/etcd/pkg/idutil"
"github.com/coreos/etcd/pkg/pbutil"
Expand Down Expand Up @@ -294,6 +295,17 @@ func TestApplyRequest(t *testing.T) {
},
},
},
// PUT with PrevExist and Dir both true ==> IsKeyDir
{
pb.Request{Method: "PUT", ID: 1, Dir: true, PrevExist: pbutil.Boolp(true)},
Response{err: etcdErr.NewError(etcdErr.EcodeNotDir, "", 0)},
[]testutil.Action{
{
Name: "IsKeyDir",
Params: []interface{}{""},
},
},
},
// DELETE ==> Delete
{
pb.Request{Method: "DELETE", ID: 1},
Expand Down Expand Up @@ -1151,6 +1163,13 @@ type storeRecorder struct{ testutil.Recorder }

func (s *storeRecorder) Version() int { return 0 }
func (s *storeRecorder) Index() uint64 { return 0 }
func (s *storeRecorder) IsKeyDir(nodePath string) bool {
s.Record(testutil.Action{
Name: "IsKeyDir",
Params: []interface{}{nodePath},
})
return false
}
func (s *storeRecorder) Get(path string, recursive, sorted bool) (*store.Event, error) {
s.Record(testutil.Action{
Name: "Get",
Expand Down

0 comments on commit ab27cb3

Please sign in to comment.