Merge branch '0.2' of https://github.com/coreos/etcd into v2-handler-tests

Conflicts:
	test.sh
This commit is contained in:
Ben Johnson
2013-10-18 08:54:51 -06:00
3 changed files with 31 additions and 16 deletions

View File

@@ -30,12 +30,20 @@ func SetKeyHandler(w http.ResponseWriter, req *http.Request, s Server) error {
// If the "prevValue" is specified then test-and-set. Otherwise create a new key. // If the "prevValue" is specified then test-and-set. Otherwise create a new key.
var c raft.Command var c raft.Command
if prevValueArr, ok := req.Form["prevValue"]; ok && len(prevValueArr) > 0 { if prevValueArr, ok := req.Form["prevValue"]; ok {
c = &store.CompareAndSwapCommand{ if len(prevValueArr[0]) > 0 { // test against previous value
Key: key, c = &store.CompareAndSwapCommand{
Value: value, Key: key,
PrevValue: prevValueArr[0], Value: value,
ExpireTime: expireTime, PrevValue: prevValueArr[0],
ExpireTime: expireTime,
}
} else {
c = &store.CreateCommand{ // test against existence
Key: key,
Value: value,
ExpireTime: expireTime,
}
} }
} else { } else {

View File

@@ -55,13 +55,16 @@ func (event *Event) Response() interface{} {
Expiration: event.Expiration, Expiration: event.Expiration,
} }
if response.Action == Create || response.Action == Set { if response.Action == Set {
response.Action = "set"
if response.PrevValue == "" { if response.PrevValue == "" {
response.NewKey = true response.NewKey = true
} }
} }
if response.Action == CompareAndSwap || response.Action == Create {
response.Action = "testAndSet"
}
return response return response
} else { } else {
responses := make([]*Response, len(event.KVPairs)) responses := make([]*Response, len(event.KVPairs))

20
test.sh
View File

@@ -1,15 +1,19 @@
#!/bin/sh #!/bin/sh
set -e set -e
# Unit tests
echo "-- UNIT TESTS --"
go test -v ./server/v2/tests
go test -v ./store
# Get GOPATH, etc from build # Get GOPATH, etc from build
echo "-- BUILDING BINARY --"
. ./build . ./build
# use right GOPATH
export GOPATH="${PWD}"
# Unit tests
go test -i ./server/v2/tests
go test -v ./server/v2/tests
go test -i ./store
go test -v ./store
# Functional tests # Functional tests
echo "-- FUNCTIONAL TESTS --" go test -i ./tests/functional
ETCD_BIN_PATH=$(PWD)/etcd go test -v ./tests/functional ETCD_BIN_PATH=$(pwd)/etcd go test -v ./tests/functional