Skip to content

Commit

Permalink
Merge branch 'issue-8'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauricio Klein committed Oct 24, 2019
2 parents a06a9be + 2b16109 commit 1bfbdbe
Showing 1 changed file with 61 additions and 8 deletions.
69 changes: 61 additions & 8 deletions chainable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ import (
"github.com/stretchr/testify/assert"
)

// a generic interface for testing purposes
type genericInterface interface {
DoThing()
}

// a generic struct for testing purposes
type genericStruct struct{}

func (gs genericStruct) DoThing() {}

// a generic error for testing purposes
var errGeneric = errors.New("a generic error")

func TestChain(t *testing.T) {
testCases := []struct {
desc string
Expand Down Expand Up @@ -51,10 +64,10 @@ func TestChain(t *testing.T) {
from: []Argument{},
funcs: []Function{
func() int { return 0 },
func(x int) error { return errors.New("a generic error") },
func(x int) error { return errGeneric },
},
returnValue: []Argument{},
err: errors.New("a generic error"),
err: errGeneric,
},
{
desc: "Without argument feedback",
Expand All @@ -66,6 +79,26 @@ func TestChain(t *testing.T) {
returnValue: []Argument{},
err: nil,
},
{
desc: "With non-primitive argument",
from: []Argument{genericStruct{}},
funcs: []Function{
func(gs genericStruct) genericStruct { return gs },
func(gs genericStruct) genericStruct { return gs },
},
returnValue: []Argument{genericStruct{}},
err: nil,
},
{
desc: "With interface argument",
from: []Argument{genericStruct{}},
funcs: []Function{
func(gi genericInterface) genericInterface { return gi },
func(gi genericInterface) genericInterface { return gi },
},
returnValue: []Argument{genericStruct{}},
err: nil,
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -100,30 +133,50 @@ func TestChainDummy(t *testing.T) {
from: []Argument{},
funcs: []Function{
func() int { return 2 },
func(x int) (int, error) { return x, errors.New("a generic error") },
func(x int) (int, error) { return x, errGeneric },
},
returnValue: []Argument{2, errors.New("a generic error")},
returnValue: []Argument{2, errGeneric},
err: nil,
},
{
desc: "With cascading error",
from: []Argument{},
funcs: []Function{
func() error { return errors.New("a generic error") },
func() error { return errGeneric },
func(e error) error { return e },
func(e error) error { return e },
},
returnValue: []Argument{errors.New("a generic error")},
returnValue: []Argument{errGeneric},
err: nil,
},
{
desc: "With cascading error",
from: []Argument{errors.New("a generic error")},
from: []Argument{errGeneric},
funcs: []Function{
func(e error) error { return e },
func(e error) error { return e },
},
returnValue: []Argument{errors.New("a generic error")},
returnValue: []Argument{errGeneric},
err: nil,
},
{
desc: "With non-primitive argument",
from: []Argument{genericStruct{}},
funcs: []Function{
func(gs genericStruct) genericStruct { return gs },
func(gs genericStruct) (genericStruct, error) { return gs, errGeneric },
},
returnValue: []Argument{genericStruct{}, errGeneric},
err: nil,
},
{
desc: "With interface argument",
from: []Argument{genericStruct{}},
funcs: []Function{
func(gi genericInterface) (genericInterface, error) { return gi, errGeneric },
func(gi genericInterface, e error) (genericInterface, error) { return gi, e },
},
returnValue: []Argument{genericStruct{}, errGeneric},
err: nil,
},
}
Expand Down

0 comments on commit 1bfbdbe

Please sign in to comment.