v2http: change to 'NoValueOnSuccess'

This commit is contained in:
Gyu-Ho Lee 2016-08-30 10:50:41 -07:00
parent fb39e96862
commit 2da7b63809
2 changed files with 21 additions and 21 deletions

View File

@ -153,7 +153,7 @@ func (h *keysHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
defer cancel() defer cancel()
clock := clockwork.NewRealClock() clock := clockwork.NewRealClock()
startTime := clock.Now() startTime := clock.Now()
rr, noDataOnSuccess, err := parseKeyRequest(r, clock) rr, noValueOnSuccess, err := parseKeyRequest(r, clock)
if err != nil { if err != nil {
writeKeyError(w, err) writeKeyError(w, err)
return return
@ -175,7 +175,7 @@ func (h *keysHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
switch { switch {
case resp.Event != nil: case resp.Event != nil:
if err := writeKeyEvent(w, resp.Event, noDataOnSuccess, h.timer); err != nil { if err := writeKeyEvent(w, resp.Event, noValueOnSuccess, h.timer); err != nil {
// Should never be reached // Should never be reached
plog.Errorf("error writing event (%v)", err) plog.Errorf("error writing event (%v)", err)
} }
@ -450,7 +450,7 @@ func logHandleFunc(w http.ResponseWriter, r *http.Request) {
// a server Request, performing validation of supplied fields as appropriate. // a server Request, performing validation of supplied fields as appropriate.
// If any validation fails, an empty Request and non-nil error is returned. // If any validation fails, an empty Request and non-nil error is returned.
func parseKeyRequest(r *http.Request, clock clockwork.Clock) (etcdserverpb.Request, bool, error) { func parseKeyRequest(r *http.Request, clock clockwork.Clock) (etcdserverpb.Request, bool, error) {
noDataOnSuccess := false noValueOnSuccess := false
emptyReq := etcdserverpb.Request{} emptyReq := etcdserverpb.Request{}
err := r.ParseForm() err := r.ParseForm()
@ -537,10 +537,10 @@ func parseKeyRequest(r *http.Request, clock clockwork.Clock) (etcdserverpb.Reque
) )
} }
if noDataOnSuccess, err = getBool(r.Form, "noDataOnSuccess"); err != nil { if noValueOnSuccess, err = getBool(r.Form, "noValueOnSuccess"); err != nil {
return emptyReq, false, etcdErr.NewRequestError( return emptyReq, false, etcdErr.NewRequestError(
etcdErr.EcodeInvalidField, etcdErr.EcodeInvalidField,
`invalid value for "noDataOnSuccess"`, `invalid value for "noValueOnSuccess"`,
) )
} }
@ -629,13 +629,13 @@ func parseKeyRequest(r *http.Request, clock clockwork.Clock) (etcdserverpb.Reque
rr.Expiration = clock.Now().Add(expr).UnixNano() rr.Expiration = clock.Now().Add(expr).UnixNano()
} }
return rr, noDataOnSuccess, nil return rr, noValueOnSuccess, nil
} }
// writeKeyEvent trims the prefix of key path in a single Event under // writeKeyEvent trims the prefix of key path in a single Event under
// StoreKeysPrefix, serializes it and writes the resulting JSON to the given // StoreKeysPrefix, serializes it and writes the resulting JSON to the given
// ResponseWriter, along with the appropriate headers. // ResponseWriter, along with the appropriate headers.
func writeKeyEvent(w http.ResponseWriter, ev *store.Event, noDataOnSuccess bool, rt etcdserver.RaftTimer) error { func writeKeyEvent(w http.ResponseWriter, ev *store.Event, noValueOnSuccess bool, rt etcdserver.RaftTimer) error {
if ev == nil { if ev == nil {
return errors.New("cannot write empty Event!") return errors.New("cannot write empty Event!")
} }
@ -649,7 +649,7 @@ func writeKeyEvent(w http.ResponseWriter, ev *store.Event, noDataOnSuccess bool,
} }
ev = trimEventPrefix(ev, etcdserver.StoreKeysPrefix) ev = trimEventPrefix(ev, etcdserver.StoreKeysPrefix)
if noDataOnSuccess && if noValueOnSuccess &&
(ev.Action == store.Set || ev.Action == store.CompareAndSwap || (ev.Action == store.Set || ev.Action == store.CompareAndSwap ||
ev.Action == store.Create || ev.Action == store.Update) { ev.Action == store.Create || ev.Action == store.Update) {
ev.Node = nil ev.Node = nil

View File

@ -386,7 +386,7 @@ func TestGoodParseRequest(t *testing.T) {
tests := []struct { tests := []struct {
in *http.Request in *http.Request
w etcdserverpb.Request w etcdserverpb.Request
noData bool noValue bool
}{ }{
{ {
// good prefix, all other values default // good prefix, all other values default
@ -606,11 +606,11 @@ func TestGoodParseRequest(t *testing.T) {
false, false,
}, },
{ {
// noDataOnSuccess specified // noValueOnSuccess specified
mustNewForm( mustNewForm(
t, t,
"foo", "foo",
url.Values{"noDataOnSuccess": []string{"true"}}, url.Values{"noValueOnSuccess": []string{"true"}},
), ),
etcdserverpb.Request{ etcdserverpb.Request{
Method: "PUT", Method: "PUT",
@ -621,13 +621,13 @@ func TestGoodParseRequest(t *testing.T) {
} }
for i, tt := range tests { for i, tt := range tests {
got, noDataOnFailure, err := parseKeyRequest(tt.in, fc) got, noValueOnSuccess, err := parseKeyRequest(tt.in, fc)
if err != nil { if err != nil {
t.Errorf("#%d: err = %v, want %v", i, err, nil) t.Errorf("#%d: err = %v, want %v", i, err, nil)
} }
if noDataOnFailure != tt.noData { if noValueOnSuccess != tt.noValue {
t.Errorf("#%d: noData=%t, want %t", i, noDataOnFailure, tt.noData) t.Errorf("#%d: noValue=%t, want %t", i, noValueOnSuccess, tt.noValue)
} }
if !reflect.DeepEqual(got, tt.w) { if !reflect.DeepEqual(got, tt.w) {
@ -1160,7 +1160,7 @@ func TestWriteEvent(t *testing.T) {
tests := []struct { tests := []struct {
ev *store.Event ev *store.Event
noData bool noValue bool
idx string idx string
// TODO(jonboulle): check body as well as just status code // TODO(jonboulle): check body as well as just status code
code int code int
@ -1194,7 +1194,7 @@ func TestWriteEvent(t *testing.T) {
for i, tt := range tests { for i, tt := range tests {
rw := httptest.NewRecorder() rw := httptest.NewRecorder()
writeKeyEvent(rw, tt.ev, tt.noData, dummyRaftTimer{}) writeKeyEvent(rw, tt.ev, tt.noValue, dummyRaftTimer{})
if gct := rw.Header().Get("Content-Type"); gct != "application/json" { if gct := rw.Header().Get("Content-Type"); gct != "application/json" {
t.Errorf("case %d: bad Content-Type: got %q, want application/json", i, gct) t.Errorf("case %d: bad Content-Type: got %q, want application/json", i, gct)
} }
@ -1613,7 +1613,7 @@ func TestServeKeysEvent(t *testing.T) {
mustNewForm( mustNewForm(
t, t,
"foo", "foo",
url.Values{"noDataOnSuccess": []string{"true"}}, url.Values{"noValueOnSuccess": []string{"true"}},
), ),
etcdserver.Response{ etcdserver.Response{
Event: &store.Event{ Event: &store.Event{