// nextPageTokens returns the tokens to use when asking for the next page of // data. func (r *Request) nextPageTokens() []interface{} { if r.Operation.Paginator == nil { return nil } if r.Operation.TruncationToken != "" { tr := awsutil.ValuesAtAnyPath(r.Data, r.Operation.TruncationToken) if tr == nil || len(tr) == 0 { return nil } switch v := tr[0].(type) { case bool: if v == false { return nil } } } found := false tokens := make([]interface{}, len(r.Operation.OutputTokens)) for i, outtok := range r.Operation.OutputTokens { v := awsutil.ValuesAtAnyPath(r.Data, outtok) if v != nil && len(v) > 0 { found = true tokens[i] = v[0] } } if found { return tokens } return nil }
func TestValueAtPathSuccess(t *testing.T) { assert.Equal(t, []interface{}{"initial"}, awsutil.ValuesAtPath(data, "C")) assert.Equal(t, []interface{}{"value1"}, awsutil.ValuesAtPath(data, "A[0].C")) assert.Equal(t, []interface{}{"value2"}, awsutil.ValuesAtPath(data, "A[1].C")) assert.Equal(t, []interface{}{"value3"}, awsutil.ValuesAtPath(data, "A[2].C")) assert.Equal(t, []interface{}{"value3"}, awsutil.ValuesAtAnyPath(data, "a[2].c")) assert.Equal(t, []interface{}{"value3"}, awsutil.ValuesAtPath(data, "A[-1].C")) assert.Equal(t, []interface{}{"value1", "value2", "value3"}, awsutil.ValuesAtPath(data, "A[].C")) assert.Equal(t, []interface{}{"terminal"}, awsutil.ValuesAtPath(data, "B . B . C")) assert.Equal(t, []interface{}{"terminal", "terminal2"}, awsutil.ValuesAtPath(data, "B.*.C")) assert.Equal(t, []interface{}{"initial"}, awsutil.ValuesAtPath(data, "A.D.X || C")) }
func init() { logLevel := Session.Config.LogLevel if os.Getenv("DEBUG") != "" { logLevel = aws.LogLevel(aws.LogDebug) } if os.Getenv("DEBUG_SIGNING") != "" { logLevel = aws.LogLevel(aws.LogDebugWithSigning) } if os.Getenv("DEBUG_BODY") != "" { logLevel = aws.LogLevel(aws.LogDebugWithHTTPBody) } Session.Config.LogLevel = logLevel When(`^I call the "(.+?)" API$`, func(op string) { call(op, nil, false) }) When(`^I call the "(.+?)" API with:$`, func(op string, args [][]string) { call(op, args, false) }) Then(`^the value at "(.+?)" should be a list$`, func(member string) { vals := awsutil.ValuesAtAnyPath(World["response"], member) assert.NotNil(T, vals) }) Then(`^the response should contain a "(.+?)"$`, func(member string) { vals := awsutil.ValuesAtAnyPath(World["response"], member) assert.NotEmpty(T, vals) }) When(`^I attempt to call the "(.+?)" API with:$`, func(op string, args [][]string) { call(op, args, true) }) 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) } }) 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) } }) 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 for _, row := range table { if strings.Contains(err.Message(), row[0]) { found = true break } } assert.True(T, found, fmt.Sprintf("no error messages matched: \"%s\"", err.Message())) } }) When(`^I call the "(.+?)" API with JSON:$`, func(s1 string, data string) { callWithJSON(s1, data, false) }) When(`^I attempt to call the "(.+?)" API with JSON:$`, func(s1 string, data string) { callWithJSON(s1, data, true) }) 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()) }) 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) }) Then(`^the request should fail$`, func() { err, ok := World["error"].(awserr.Error) assert.True(T, ok, "no error returned") assert.Error(T, err) }) Then(`^the request should be successful$`, func() { err, ok := World["error"].(awserr.Error) assert.False(T, ok, "error returned") assert.NoError(T, err) }) }
func init() { if os.Getenv("DEBUG") != "" { aws.DefaultConfig.LogLevel = 1 } if os.Getenv("DEBUG_BODY") != "" { aws.DefaultConfig.LogLevel = 1 aws.DefaultConfig.LogHTTPBody = true } When(`^I call the "(.+?)" API$`, func(op string) { call(op, nil, false) }) When(`^I call the "(.+?)" API with:$`, func(op string, args [][]string) { call(op, args, false) }) Then(`^the value at "(.+?)" should be a list$`, func(member string) { vals := awsutil.ValuesAtAnyPath(World["response"], member) assert.NotEmpty(T, vals) }) Then(`^the response should contain a "(.+?)"$`, func(member string) { vals := awsutil.ValuesAtAnyPath(World["response"], member) assert.NotEmpty(T, vals) }) When(`^I attempt to call the "(.+?)" API with:$`, func(op string, args [][]string) { call(op, args, true) }) 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()) } }) 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) } }) 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 for _, row := range table { if strings.Contains(err.Message(), row[0]) { found = true break } } assert.True(T, found, fmt.Sprintf("no error messages matched: \"%s\"", err.Message())) } }) }