Merge pull request #784 from nyaxt/avoid_magicnum
Rename IsEtcdConflict to IsEtcdTestFailed
This commit is contained in:
commit
bec27af51a
@ -39,7 +39,7 @@ func MakeAsync(fn WorkFunc) <-chan interface{} {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
status := http.StatusInternalServerError
|
status := http.StatusInternalServerError
|
||||||
switch {
|
switch {
|
||||||
case tools.IsEtcdConflict(err):
|
case tools.IsEtcdTestFailed(err):
|
||||||
status = http.StatusConflict
|
status = http.StatusConflict
|
||||||
}
|
}
|
||||||
channel <- &api.Status{
|
channel <- &api.Status{
|
||||||
|
@ -82,14 +82,14 @@ type EtcdHelper struct {
|
|||||||
Versioning Versioning
|
Versioning Versioning
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true iff err is an etcd not found error.
|
// IsEtcdNotFound returns true iff err is an etcd not found error.
|
||||||
func IsEtcdNotFound(err error) bool {
|
func IsEtcdNotFound(err error) bool {
|
||||||
return isEtcdErrorNum(err, 100)
|
return isEtcdErrorNum(err, EtcdErrorCodeNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true iff err is an etcd write conflict.
|
// IsEtcdTestFailed returns true iff err is an etcd write conflict.
|
||||||
func IsEtcdConflict(err error) bool {
|
func IsEtcdTestFailed(err error) bool {
|
||||||
return isEtcdErrorNum(err, 101)
|
return isEtcdErrorNum(err, EtcdErrorCodeTestFailed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsEtcdWatchStoppedByUser returns true iff err is a client triggered stop.
|
// IsEtcdWatchStoppedByUser returns true iff err is a client triggered stop.
|
||||||
@ -242,7 +242,7 @@ func (h *EtcdHelper) AtomicUpdate(key string, ptrToType interface{}, tryUpdate E
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = h.Client.CompareAndSwap(key, string(data), 0, origBody, index)
|
_, err = h.Client.CompareAndSwap(key, string(data), 0, origBody, index)
|
||||||
if IsEtcdConflict(err) {
|
if IsEtcdTestFailed(err) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
@ -50,7 +50,7 @@ func init() {
|
|||||||
scheme.AddKnownTypes("v1beta1", TestResource{})
|
scheme.AddKnownTypes("v1beta1", TestResource{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIsNotFoundErr(t *testing.T) {
|
func TestIsEtcdNotFound(t *testing.T) {
|
||||||
try := func(err error, isNotFound bool) {
|
try := func(err error, isNotFound bool) {
|
||||||
if IsEtcdNotFound(err) != isNotFound {
|
if IsEtcdNotFound(err) != isNotFound {
|
||||||
t.Errorf("Expected %#v to return %v, but it did not", err, isNotFound)
|
t.Errorf("Expected %#v to return %v, but it did not", err, isNotFound)
|
||||||
|
Loading…
Reference in New Issue
Block a user