Skip to content

Commit

Permalink
Merge pull request #496 from aws/fix-i495
Browse files Browse the repository at this point in the history
Revert "Shim gucumber.Tester to workaround stretchr/testify#263"
  • Loading branch information
jasdel committed Jan 9, 2016
2 parents d397d84 + 5b053fe commit b7b1a09
Showing 1 changed file with 32 additions and 43 deletions.
75 changes: 32 additions & 43 deletions awstesting/integration/smoke/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strconv"
"strings"

"github.com/lsegal/gucumber"
. "github.com/lsegal/gucumber"
"github.com/stretchr/testify/assert"

"github.com/aws/aws-sdk-go/aws"
Expand All @@ -19,21 +19,10 @@ import (
"github.com/aws/aws-sdk-go/aws/session"
)

// A Test is the stopgap for stretchr/testify#262 adding FailNow to assert.TestingT interface
type tester struct {
gucumber.Tester
}

func (t *tester) FailNow() {}

// T is the gucumber testing utility
var T = &tester{Tester: gucumber.T}

// Session is a shared session for all integration smoke tests to use.
var Session = session.New()

func init() {

logLevel := Session.Config.LogLevel
if os.Getenv("DEBUG") != "" {
logLevel = aws.LogLevel(aws.LogDebug)
Expand All @@ -46,46 +35,46 @@ func init() {
}
Session.Config.LogLevel = logLevel

gucumber.When(`^I call the "(.+?)" API$`, func(op string) {
When(`^I call the "(.+?)" API$`, func(op string) {
call(op, nil, false)
})

gucumber.When(`^I call the "(.+?)" API with:$`, func(op string, args [][]string) {
When(`^I call the "(.+?)" API with:$`, func(op string, args [][]string) {
call(op, args, false)
})

gucumber.Then(`^the value at "(.+?)" should be a list$`, func(member string) {
vals, _ := awsutil.ValuesAtPath(gucumber.World["response"], member)
Then(`^the value at "(.+?)" should be a list$`, func(member string) {
vals, _ := awsutil.ValuesAtPath(World["response"], member)
assert.NotNil(T, vals)
})

gucumber.Then(`^the response should contain a "(.+?)"$`, func(member string) {
vals, _ := awsutil.ValuesAtPath(gucumber.World["response"], member)
Then(`^the response should contain a "(.+?)"$`, func(member string) {
vals, _ := awsutil.ValuesAtPath(World["response"], member)
assert.NotEmpty(T, vals)
})

gucumber.When(`^I attempt to call the "(.+?)" API with:$`, func(op string, args [][]string) {
When(`^I attempt to call the "(.+?)" API with:$`, func(op string, args [][]string) {
call(op, args, true)
})

gucumber.Then(`^I expect the response error code to be "(.+?)"$`, func(code string) {
err, ok := gucumber.World["error"].(awserr.Error)
Then(`^I expect the response error code to be "(.+?)"$`, func(code string) {
err, ok := World["error"].(awserr.Error)
assert.True(T, ok, "no error returned")
if ok {
assert.Equal(T, code, err.Code(), "Error: %v", err)
}
})

gucumber.And(`^I expect the response error message to include:$`, func(data string) {
err, ok := gucumber.World["error"].(awserr.Error)
And(`^I expect the response error message to include:$`, func(data string) {
err, ok := World["error"].(awserr.Error)
assert.True(T, ok, "no error returned")
if ok {
assert.Contains(T, err.Message(), data)
}
})

gucumber.And(`^I expect the response error message to include one of:$`, func(table [][]string) {
err, ok := gucumber.World["error"].(awserr.Error)
And(`^I expect the response error message to include one of:$`, func(table [][]string) {
err, ok := World["error"].(awserr.Error)
assert.True(T, ok, "no error returned")
if ok {
found := false
Expand All @@ -100,34 +89,34 @@ func init() {
}
})

gucumber.When(`^I call the "(.+?)" API with JSON:$`, func(s1 string, data string) {
When(`^I call the "(.+?)" API with JSON:$`, func(s1 string, data string) {
callWithJSON(s1, data, false)
})

gucumber.When(`^I attempt to call the "(.+?)" API with JSON:$`, func(s1 string, data string) {
When(`^I attempt to call the "(.+?)" API with JSON:$`, func(s1 string, data string) {
callWithJSON(s1, data, true)
})

gucumber.Then(`^the error code should be "(.+?)"$`, func(s1 string) {
err, ok := gucumber.World["error"].(awserr.Error)
Then(`^the error code should be "(.+?)"$`, func(s1 string) {
err, ok := World["error"].(awserr.Error)
assert.True(T, ok, "no error returned")
assert.Equal(T, s1, err.Code())
})

gucumber.And(`^the error message should contain:$`, func(data string) {
err, ok := gucumber.World["error"].(awserr.Error)
And(`^the error message should contain:$`, func(data string) {
err, ok := World["error"].(awserr.Error)
assert.True(T, ok, "no error returned")
assert.Contains(T, err.Error(), data)
})

gucumber.Then(`^the request should fail$`, func() {
err, ok := gucumber.World["error"].(awserr.Error)
Then(`^the request should fail$`, func() {
err, ok := World["error"].(awserr.Error)
assert.True(T, ok, "no error returned")
assert.Error(T, err)
})

gucumber.Then(`^the request should be successful$`, func() {
err, ok := gucumber.World["error"].(awserr.Error)
Then(`^the request should be successful$`, func() {
err, ok := World["error"].(awserr.Error)
assert.False(T, ok, "error returned")
assert.NoError(T, err)
})
Expand All @@ -151,18 +140,18 @@ func findMethod(v reflect.Value, op string) *reflect.Value {
// call calls an operation on World["client"] by the name op using the args
// table of arguments to set.
func call(op string, args [][]string, allowError bool) {
v := reflect.ValueOf(gucumber.World["client"])
v := reflect.ValueOf(World["client"])
if m := findMethod(v, op); m != nil {
t := m.Type()
in := reflect.New(t.In(0).Elem())
fillArgs(in, args)

resps := m.Call([]reflect.Value{in})
gucumber.World["response"] = resps[0].Interface()
gucumber.World["error"] = resps[1].Interface()
World["response"] = resps[0].Interface()
World["error"] = resps[1].Interface()

if !allowError {
err, _ := gucumber.World["error"].(error)
err, _ := World["error"].(error)
assert.NoError(T, err)
}
} else {
Expand Down Expand Up @@ -206,18 +195,18 @@ func fillArgs(in reflect.Value, args [][]string) {
}

func callWithJSON(op, j string, allowError bool) {
v := reflect.ValueOf(gucumber.World["client"])
v := reflect.ValueOf(World["client"])
if m := findMethod(v, op); m != nil {
t := m.Type()
in := reflect.New(t.In(0).Elem())
fillJSON(in, j)

resps := m.Call([]reflect.Value{in})
gucumber.World["response"] = resps[0].Interface()
gucumber.World["error"] = resps[1].Interface()
World["response"] = resps[0].Interface()
World["error"] = resps[1].Interface()

if !allowError {
err, _ := gucumber.World["error"].(error)
err, _ := World["error"].(error)
assert.NoError(T, err)
}
} else {
Expand Down

0 comments on commit b7b1a09

Please sign in to comment.