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()
clock := clockwork.NewRealClock()
startTime := clock.Now()
rr, noDataOnSuccess, err := parseKeyRequest(r, clock)
rr, noValueOnSuccess, err := parseKeyRequest(r, clock)
if err != nil {
writeKeyError(w, err)
return
@ -175,7 +175,7 @@ func (h *keysHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
switch {
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
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.
// 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) {
noDataOnSuccess := false
noValueOnSuccess := false
emptyReq := etcdserverpb.Request{}
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(
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()
}
return rr, noDataOnSuccess, nil
return rr, noValueOnSuccess, nil
}
// writeKeyEvent trims the prefix of key path in a single Event under
// StoreKeysPrefix, serializes it and writes the resulting JSON to the given
// 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 {
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)
if noDataOnSuccess &&
if noValueOnSuccess &&
(ev.Action == store.Set || ev.Action == store.CompareAndSwap ||
ev.Action == store.Create || ev.Action == store.Update) {
ev.Node = nil

View File

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