Skip to content

Commit

Permalink
rules: unit tests for ErrorList.Error()
Browse files Browse the repository at this point in the history
  • Loading branch information
James DeFelice committed Jun 12, 2017
1 parent d7478ca commit 9a4f274
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 25 deletions.
15 changes: 10 additions & 5 deletions api/v1/lib/extras/executor/callrules/callrules_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,15 @@ func (rs Rules) Chain() Chain {
// It is the semantic equivalent of Rules{r1, r2, ..., rn}.Rule() and exists purely for convenience.
func Concat(rs ...Rule) Rule { return Rules(rs).Eval }

const (
MsgNoErrors = "no errors"
)

// Error implements error; returns the message of the first error in the list.
func (es ErrorList) Error() string {
switch len(es) {
case 0:
return "no errors"
return MsgNoErrors
case 1:
return es[0].Error()
default:
Expand Down Expand Up @@ -113,13 +117,14 @@ func Error2(a, b error) error {

// Err reduces an empty or singleton error list
func (es ErrorList) Err() error {
if len(es) == 0 {
switch len(es) {
case 0:
return nil
}
if len(es) == 1 {
case 1:
return es[0]
default:
return es
}
return es
}

// IsErrorList returns true if err is a non-nil error list
Expand Down
20 changes: 20 additions & 0 deletions api/v1/lib/extras/executor/callrules/callrules_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,26 @@ func TestRules(t *testing.T) {
}
}

func TestError(t *testing.T) {
a := errors.New("a")
list := ErrorList{a}

msg := list.Error()
if msg != a.Error() {
t.Errorf("expected %q instead of %q", a.Error(), msg)
}

msg = ErrorList{}.Error()
if msg != MsgNoErrors {
t.Errorf("expected %q instead of %q", MsgNoErrors, msg)
}

msg = ErrorList(nil).Error()
if msg != MsgNoErrors {
t.Errorf("expected %q instead of %q", MsgNoErrors, msg)
}
}

func TestError2(t *testing.T) {
var (
a = errors.New("a")
Expand Down
15 changes: 10 additions & 5 deletions api/v1/lib/extras/executor/eventrules/eventrules_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,15 @@ func (rs Rules) Chain() Chain {
// It is the semantic equivalent of Rules{r1, r2, ..., rn}.Rule() and exists purely for convenience.
func Concat(rs ...Rule) Rule { return Rules(rs).Eval }

const (
MsgNoErrors = "no errors"
)

// Error implements error; returns the message of the first error in the list.
func (es ErrorList) Error() string {
switch len(es) {
case 0:
return "no errors"
return MsgNoErrors
case 1:
return es[0].Error()
default:
Expand Down Expand Up @@ -112,13 +116,14 @@ func Error2(a, b error) error {

// Err reduces an empty or singleton error list
func (es ErrorList) Err() error {
if len(es) == 0 {
switch len(es) {
case 0:
return nil
}
if len(es) == 1 {
case 1:
return es[0]
default:
return es
}
return es
}

// IsErrorList returns true if err is a non-nil error list
Expand Down
20 changes: 20 additions & 0 deletions api/v1/lib/extras/executor/eventrules/eventrules_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,26 @@ func TestRules(t *testing.T) {
}
}

func TestError(t *testing.T) {
a := errors.New("a")
list := ErrorList{a}

msg := list.Error()
if msg != a.Error() {
t.Errorf("expected %q instead of %q", a.Error(), msg)
}

msg = ErrorList{}.Error()
if msg != MsgNoErrors {
t.Errorf("expected %q instead of %q", MsgNoErrors, msg)
}

msg = ErrorList(nil).Error()
if msg != MsgNoErrors {
t.Errorf("expected %q instead of %q", MsgNoErrors, msg)
}
}

func TestError2(t *testing.T) {
var (
a = errors.New("a")
Expand Down
35 changes: 30 additions & 5 deletions api/v1/lib/extras/gen/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,15 @@ func (rs Rules) Chain() Chain {
// It is the semantic equivalent of Rules{r1, r2, ..., rn}.Rule() and exists purely for convenience.
func Concat(rs ...Rule) Rule { return Rules(rs).Eval }
const (
MsgNoErrors = "no errors"
)
// Error implements error; returns the message of the first error in the list.
func (es ErrorList) Error() string {
switch len(es) {
case 0:
return "no errors"
return MsgNoErrors
case 1:
return es[0].Error()
default:
Expand Down Expand Up @@ -129,13 +133,14 @@ func Error2(a, b error) error {
// Err reduces an empty or singleton error list
func (es ErrorList) Err() error {
if len(es) == 0 {
switch len(es) {
case 0:
return nil
}
if len(es) == 1 {
case 1:
return es[0]
default:
return es
}
return es
}
// IsErrorList returns true if err is a non-nil error list
Expand Down Expand Up @@ -551,6 +556,26 @@ func TestRules(t *testing.T) {
}
}
func TestError(t *testing.T) {
a := errors.New("a")
list := ErrorList{a}
msg := list.Error()
if msg != a.Error() {
t.Errorf("expected %q instead of %q", a.Error(), msg)
}
msg = ErrorList{}.Error()
if msg != MsgNoErrors {
t.Errorf("expected %q instead of %q", MsgNoErrors, msg)
}
msg = ErrorList(nil).Error()
if msg != MsgNoErrors {
t.Errorf("expected %q instead of %q", MsgNoErrors, msg)
}
}
func TestError2(t *testing.T) {
var (
a = errors.New("a")
Expand Down
15 changes: 10 additions & 5 deletions api/v1/lib/extras/scheduler/callrules/callrules_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,15 @@ func (rs Rules) Chain() Chain {
// It is the semantic equivalent of Rules{r1, r2, ..., rn}.Rule() and exists purely for convenience.
func Concat(rs ...Rule) Rule { return Rules(rs).Eval }

const (
MsgNoErrors = "no errors"
)

// Error implements error; returns the message of the first error in the list.
func (es ErrorList) Error() string {
switch len(es) {
case 0:
return "no errors"
return MsgNoErrors
case 1:
return es[0].Error()
default:
Expand Down Expand Up @@ -113,13 +117,14 @@ func Error2(a, b error) error {

// Err reduces an empty or singleton error list
func (es ErrorList) Err() error {
if len(es) == 0 {
switch len(es) {
case 0:
return nil
}
if len(es) == 1 {
case 1:
return es[0]
default:
return es
}
return es
}

// IsErrorList returns true if err is a non-nil error list
Expand Down
20 changes: 20 additions & 0 deletions api/v1/lib/extras/scheduler/callrules/callrules_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,26 @@ func TestRules(t *testing.T) {
}
}

func TestError(t *testing.T) {
a := errors.New("a")
list := ErrorList{a}

msg := list.Error()
if msg != a.Error() {
t.Errorf("expected %q instead of %q", a.Error(), msg)
}

msg = ErrorList{}.Error()
if msg != MsgNoErrors {
t.Errorf("expected %q instead of %q", MsgNoErrors, msg)
}

msg = ErrorList(nil).Error()
if msg != MsgNoErrors {
t.Errorf("expected %q instead of %q", MsgNoErrors, msg)
}
}

func TestError2(t *testing.T) {
var (
a = errors.New("a")
Expand Down
15 changes: 10 additions & 5 deletions api/v1/lib/extras/scheduler/eventrules/eventrules_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,15 @@ func (rs Rules) Chain() Chain {
// It is the semantic equivalent of Rules{r1, r2, ..., rn}.Rule() and exists purely for convenience.
func Concat(rs ...Rule) Rule { return Rules(rs).Eval }

const (
MsgNoErrors = "no errors"
)

// Error implements error; returns the message of the first error in the list.
func (es ErrorList) Error() string {
switch len(es) {
case 0:
return "no errors"
return MsgNoErrors
case 1:
return es[0].Error()
default:
Expand Down Expand Up @@ -112,13 +116,14 @@ func Error2(a, b error) error {

// Err reduces an empty or singleton error list
func (es ErrorList) Err() error {
if len(es) == 0 {
switch len(es) {
case 0:
return nil
}
if len(es) == 1 {
case 1:
return es[0]
default:
return es
}
return es
}

// IsErrorList returns true if err is a non-nil error list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,26 @@ func TestRules(t *testing.T) {
}
}

func TestError(t *testing.T) {
a := errors.New("a")
list := ErrorList{a}

msg := list.Error()
if msg != a.Error() {
t.Errorf("expected %q instead of %q", a.Error(), msg)
}

msg = ErrorList{}.Error()
if msg != MsgNoErrors {
t.Errorf("expected %q instead of %q", MsgNoErrors, msg)
}

msg = ErrorList(nil).Error()
if msg != MsgNoErrors {
t.Errorf("expected %q instead of %q", MsgNoErrors, msg)
}
}

func TestError2(t *testing.T) {
var (
a = errors.New("a")
Expand Down

0 comments on commit 9a4f274

Please sign in to comment.