Switch to using the dep tool and update all the dependencies

This commit is contained in:
Nick Craig-Wood 2017-05-11 15:39:54 +01:00
parent 5135ff73cb
commit 98c2d2c41b
5321 changed files with 4483201 additions and 5922 deletions

2332
vendor/github.com/aws/aws-sdk-go/service/simpledb/api.go generated vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,11 @@
package simpledb
import "github.com/aws/aws-sdk-go/aws/client"
func init() {
initClient = func(c *client.Client) {
// SimpleDB uses custom error unmarshaling logic
c.Handlers.UnmarshalError.Clear()
c.Handlers.UnmarshalError.PushBack(unmarshalError)
}
}

View file

@ -0,0 +1,92 @@
// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
// Package simpledb provides the client and types for making API
// requests to Amazon SimpleDB.
//
// Amazon SimpleDB is a web service providing the core database functions of
// data indexing and querying in the cloud. By offloading the time and effort
// associated with building and operating a web-scale database, SimpleDB provides
// developers the freedom to focus on application development. A traditional,
// clustered relational database requires a sizable upfront capital outlay,
// is complex to design, and often requires extensive and repetitive database
// administration. Amazon SimpleDB is dramatically simpler, requiring no schema,
// automatically indexing your data and providing a simple API for storage and
// access. This approach eliminates the administrative burden of data modeling,
// index maintenance, and performance tuning. Developers gain access to this
// functionality within Amazon's proven computing environment, are able to scale
// instantly, and pay only for what they use.
//
// Visit http://aws.amazon.com/simpledb/ (http://aws.amazon.com/simpledb/) for
// more information.
//
// See simpledb package documentation for more information.
// https://docs.aws.amazon.com/sdk-for-go/api/service/simpledb/
//
// Using the Client
//
// To use the client for Amazon SimpleDB you will first need
// to create a new instance of it.
//
// When creating a client for an AWS service you'll first need to have a Session
// already created. The Session provides configuration that can be shared
// between multiple service clients. Additional configuration can be applied to
// the Session and service's client when they are constructed. The aws package's
// Config type contains several fields such as Region for the AWS Region the
// client should make API requests too. The optional Config value can be provided
// as the variadic argument for Sessions and client creation.
//
// Once the service's client is created you can use it to make API requests the
// AWS service. These clients are safe to use concurrently.
//
// // Create a session to share configuration, and load external configuration.
// sess := session.Must(session.NewSession())
//
// // Create the service's client with the session.
// svc := simpledb.New(sess)
//
// See the SDK's documentation for more information on how to use service clients.
// https://docs.aws.amazon.com/sdk-for-go/api/
//
// See aws package's Config type for more information on configuration options.
// https://docs.aws.amazon.com/sdk-for-go/api/aws/#Config
//
// See the Amazon SimpleDB client SimpleDB for more
// information on creating the service's client.
// https://docs.aws.amazon.com/sdk-for-go/api/service/simpledb/#New
//
// Once the client is created you can make an API request to the service.
// Each API method takes a input parameter, and returns the service response
// and an error.
//
// The API method will document which error codes the service can be returned
// by the operation if the service models the API operation's errors. These
// errors will also be available as const strings prefixed with "ErrCode".
//
// result, err := svc.BatchDeleteAttributes(params)
// if err != nil {
// // Cast err to awserr.Error to handle specific error codes.
// aerr, ok := err.(awserr.Error)
// if ok && aerr.Code() == <error code to check for> {
// // Specific error code handling
// }
// return err
// }
//
// fmt.Println("BatchDeleteAttributes result:")
// fmt.Println(result)
//
// Using the Client with Context
//
// The service's client also provides methods to make API requests with a Context
// value. This allows you to control the timeout, and cancellation of pending
// requests. These methods also take request Option as variadic parameter to apply
// additional configuration to the API request.
//
// ctx := context.Background()
//
// result, err := svc.BatchDeleteAttributesWithContext(ctx, params)
//
// See the request package documentation for more information on using Context pattern
// with the SDK.
// https://docs.aws.amazon.com/sdk-for-go/api/aws/request/
package simpledb

View file

@ -0,0 +1,109 @@
// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
package simpledb
const (
// ErrCodeAttributeDoesNotExist for service response error code
// "AttributeDoesNotExist".
//
// The specified attribute does not exist.
ErrCodeAttributeDoesNotExist = "AttributeDoesNotExist"
// ErrCodeDuplicateItemName for service response error code
// "DuplicateItemName".
//
// The item name was specified more than once.
ErrCodeDuplicateItemName = "DuplicateItemName"
// ErrCodeInvalidNextToken for service response error code
// "InvalidNextToken".
//
// The specified NextToken is not valid.
ErrCodeInvalidNextToken = "InvalidNextToken"
// ErrCodeInvalidNumberPredicates for service response error code
// "InvalidNumberPredicates".
//
// Too many predicates exist in the query expression.
ErrCodeInvalidNumberPredicates = "InvalidNumberPredicates"
// ErrCodeInvalidNumberValueTests for service response error code
// "InvalidNumberValueTests".
//
// Too many predicates exist in the query expression.
ErrCodeInvalidNumberValueTests = "InvalidNumberValueTests"
// ErrCodeInvalidParameterValue for service response error code
// "InvalidParameterValue".
//
// The value for a parameter is invalid.
ErrCodeInvalidParameterValue = "InvalidParameterValue"
// ErrCodeInvalidQueryExpression for service response error code
// "InvalidQueryExpression".
//
// The specified query expression syntax is not valid.
ErrCodeInvalidQueryExpression = "InvalidQueryExpression"
// ErrCodeMissingParameter for service response error code
// "MissingParameter".
//
// The request must contain the specified missing parameter.
ErrCodeMissingParameter = "MissingParameter"
// ErrCodeNoSuchDomain for service response error code
// "NoSuchDomain".
//
// The specified domain does not exist.
ErrCodeNoSuchDomain = "NoSuchDomain"
// ErrCodeNumberDomainAttributesExceeded for service response error code
// "NumberDomainAttributesExceeded".
//
// Too many attributes in this domain.
ErrCodeNumberDomainAttributesExceeded = "NumberDomainAttributesExceeded"
// ErrCodeNumberDomainBytesExceeded for service response error code
// "NumberDomainBytesExceeded".
//
// Too many bytes in this domain.
ErrCodeNumberDomainBytesExceeded = "NumberDomainBytesExceeded"
// ErrCodeNumberDomainsExceeded for service response error code
// "NumberDomainsExceeded".
//
// Too many domains exist per this account.
ErrCodeNumberDomainsExceeded = "NumberDomainsExceeded"
// ErrCodeNumberItemAttributesExceeded for service response error code
// "NumberItemAttributesExceeded".
//
// Too many attributes in this item.
ErrCodeNumberItemAttributesExceeded = "NumberItemAttributesExceeded"
// ErrCodeNumberSubmittedAttributesExceeded for service response error code
// "NumberSubmittedAttributesExceeded".
//
// Too many attributes exist in a single call.
ErrCodeNumberSubmittedAttributesExceeded = "NumberSubmittedAttributesExceeded"
// ErrCodeNumberSubmittedItemsExceeded for service response error code
// "NumberSubmittedItemsExceeded".
//
// Too many items exist in a single call.
ErrCodeNumberSubmittedItemsExceeded = "NumberSubmittedItemsExceeded"
// ErrCodeRequestTimeout for service response error code
// "RequestTimeout".
//
// A timeout occurred when attempting to query the specified domain with specified
// query expression.
ErrCodeRequestTimeout = "RequestTimeout"
// ErrCodeTooManyRequestedAttributes for service response error code
// "TooManyRequestedAttributes".
//
// Too many attributes requested.
ErrCodeTooManyRequestedAttributes = "TooManyRequestedAttributes"
)

View file

@ -0,0 +1,289 @@
// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
package simpledb_test
import (
"bytes"
"fmt"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/simpledb"
)
var _ time.Duration
var _ bytes.Buffer
func ExampleSimpleDB_BatchDeleteAttributes() {
sess := session.Must(session.NewSession())
svc := simpledb.New(sess)
params := &simpledb.BatchDeleteAttributesInput{
DomainName: aws.String("String"), // Required
Items: []*simpledb.DeletableItem{ // Required
{ // Required
Name: aws.String("String"), // Required
Attributes: []*simpledb.DeletableAttribute{
{ // Required
Name: aws.String("String"), // Required
Value: aws.String("String"),
},
// More values...
},
},
// More values...
},
}
resp, err := svc.BatchDeleteAttributes(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
func ExampleSimpleDB_BatchPutAttributes() {
sess := session.Must(session.NewSession())
svc := simpledb.New(sess)
params := &simpledb.BatchPutAttributesInput{
DomainName: aws.String("String"), // Required
Items: []*simpledb.ReplaceableItem{ // Required
{ // Required
Attributes: []*simpledb.ReplaceableAttribute{ // Required
{ // Required
Name: aws.String("String"), // Required
Value: aws.String("String"), // Required
Replace: aws.Bool(true),
},
// More values...
},
Name: aws.String("String"), // Required
},
// More values...
},
}
resp, err := svc.BatchPutAttributes(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
func ExampleSimpleDB_CreateDomain() {
sess := session.Must(session.NewSession())
svc := simpledb.New(sess)
params := &simpledb.CreateDomainInput{
DomainName: aws.String("String"), // Required
}
resp, err := svc.CreateDomain(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
func ExampleSimpleDB_DeleteAttributes() {
sess := session.Must(session.NewSession())
svc := simpledb.New(sess)
params := &simpledb.DeleteAttributesInput{
DomainName: aws.String("String"), // Required
ItemName: aws.String("String"), // Required
Attributes: []*simpledb.DeletableAttribute{
{ // Required
Name: aws.String("String"), // Required
Value: aws.String("String"),
},
// More values...
},
Expected: &simpledb.UpdateCondition{
Exists: aws.Bool(true),
Name: aws.String("String"),
Value: aws.String("String"),
},
}
resp, err := svc.DeleteAttributes(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
func ExampleSimpleDB_DeleteDomain() {
sess := session.Must(session.NewSession())
svc := simpledb.New(sess)
params := &simpledb.DeleteDomainInput{
DomainName: aws.String("String"), // Required
}
resp, err := svc.DeleteDomain(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
func ExampleSimpleDB_DomainMetadata() {
sess := session.Must(session.NewSession())
svc := simpledb.New(sess)
params := &simpledb.DomainMetadataInput{
DomainName: aws.String("String"), // Required
}
resp, err := svc.DomainMetadata(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
func ExampleSimpleDB_GetAttributes() {
sess := session.Must(session.NewSession())
svc := simpledb.New(sess)
params := &simpledb.GetAttributesInput{
DomainName: aws.String("String"), // Required
ItemName: aws.String("String"), // Required
AttributeNames: []*string{
aws.String("String"), // Required
// More values...
},
ConsistentRead: aws.Bool(true),
}
resp, err := svc.GetAttributes(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
func ExampleSimpleDB_ListDomains() {
sess := session.Must(session.NewSession())
svc := simpledb.New(sess)
params := &simpledb.ListDomainsInput{
MaxNumberOfDomains: aws.Int64(1),
NextToken: aws.String("String"),
}
resp, err := svc.ListDomains(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
func ExampleSimpleDB_PutAttributes() {
sess := session.Must(session.NewSession())
svc := simpledb.New(sess)
params := &simpledb.PutAttributesInput{
Attributes: []*simpledb.ReplaceableAttribute{ // Required
{ // Required
Name: aws.String("String"), // Required
Value: aws.String("String"), // Required
Replace: aws.Bool(true),
},
// More values...
},
DomainName: aws.String("String"), // Required
ItemName: aws.String("String"), // Required
Expected: &simpledb.UpdateCondition{
Exists: aws.Bool(true),
Name: aws.String("String"),
Value: aws.String("String"),
},
}
resp, err := svc.PutAttributes(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
func ExampleSimpleDB_Select() {
sess := session.Must(session.NewSession())
svc := simpledb.New(sess)
params := &simpledb.SelectInput{
SelectExpression: aws.String("String"), // Required
ConsistentRead: aws.Bool(true),
NextToken: aws.String("String"),
}
resp, err := svc.Select(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}

View file

@ -0,0 +1,95 @@
// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
package simpledb
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/client"
"github.com/aws/aws-sdk-go/aws/client/metadata"
"github.com/aws/aws-sdk-go/aws/corehandlers"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/private/protocol/query"
"github.com/aws/aws-sdk-go/private/signer/v2"
)
// SimpleDB provides the API operation methods for making requests to
// Amazon SimpleDB. See this package's package overview docs
// for details on the service.
//
// SimpleDB methods are safe to use concurrently. It is not safe to
// modify mutate any of the struct's properties though.
type SimpleDB struct {
*client.Client
}
// Used for custom client initialization logic
var initClient func(*client.Client)
// Used for custom request initialization logic
var initRequest func(*request.Request)
// Service information constants
const (
ServiceName = "sdb" // Service endpoint prefix API calls made to.
EndpointsID = ServiceName // Service ID for Regions and Endpoints metadata.
)
// New creates a new instance of the SimpleDB client with a session.
// If additional configuration is needed for the client instance use the optional
// aws.Config parameter to add your extra config.
//
// Example:
// // Create a SimpleDB client from just a session.
// svc := simpledb.New(mySession)
//
// // Create a SimpleDB client with additional configuration
// svc := simpledb.New(mySession, aws.NewConfig().WithRegion("us-west-2"))
func New(p client.ConfigProvider, cfgs ...*aws.Config) *SimpleDB {
c := p.ClientConfig(EndpointsID, cfgs...)
return newClient(*c.Config, c.Handlers, c.Endpoint, c.SigningRegion, c.SigningName)
}
// newClient creates, initializes and returns a new service client instance.
func newClient(cfg aws.Config, handlers request.Handlers, endpoint, signingRegion, signingName string) *SimpleDB {
svc := &SimpleDB{
Client: client.New(
cfg,
metadata.ClientInfo{
ServiceName: ServiceName,
SigningName: signingName,
SigningRegion: signingRegion,
Endpoint: endpoint,
APIVersion: "2009-04-15",
},
handlers,
),
}
// Handlers
svc.Handlers.Sign.PushBackNamed(v2.SignRequestHandler)
svc.Handlers.Sign.PushBackNamed(corehandlers.BuildContentLengthHandler)
svc.Handlers.Build.PushBackNamed(query.BuildHandler)
svc.Handlers.Unmarshal.PushBackNamed(query.UnmarshalHandler)
svc.Handlers.UnmarshalMeta.PushBackNamed(query.UnmarshalMetaHandler)
svc.Handlers.UnmarshalError.PushBackNamed(query.UnmarshalErrorHandler)
// Run custom client initialization if present
if initClient != nil {
initClient(svc.Client)
}
return svc
}
// newRequest creates a new request for a SimpleDB operation and runs any
// custom request initialization.
func (c *SimpleDB) newRequest(op *request.Operation, params, data interface{}) *request.Request {
req := c.NewRequest(op, params, data)
// Run custom request initialization if present
if initRequest != nil {
initRequest(req)
}
return req
}

View file

@ -0,0 +1,110 @@
// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
// Package simpledbiface provides an interface to enable mocking the Amazon SimpleDB service client
// for testing your code.
//
// It is important to note that this interface will have breaking changes
// when the service model is updated and adds new API operations, paginators,
// and waiters.
package simpledbiface
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/service/simpledb"
)
// SimpleDBAPI provides an interface to enable mocking the
// simpledb.SimpleDB service client's API operation,
// paginators, and waiters. This make unit testing your code that calls out
// to the SDK's service client's calls easier.
//
// The best way to use this interface is so the SDK's service client's calls
// can be stubbed out for unit testing your code with the SDK without needing
// to inject custom request handlers into the the SDK's request pipeline.
//
// // myFunc uses an SDK service client to make a request to
// // Amazon SimpleDB.
// func myFunc(svc simpledbiface.SimpleDBAPI) bool {
// // Make svc.BatchDeleteAttributes request
// }
//
// func main() {
// sess := session.New()
// svc := simpledb.New(sess)
//
// myFunc(svc)
// }
//
// In your _test.go file:
//
// // Define a mock struct to be used in your unit tests of myFunc.
// type mockSimpleDBClient struct {
// simpledbiface.SimpleDBAPI
// }
// func (m *mockSimpleDBClient) BatchDeleteAttributes(input *simpledb.BatchDeleteAttributesInput) (*simpledb.BatchDeleteAttributesOutput, error) {
// // mock response/functionality
// }
//
// func TestMyFunc(t *testing.T) {
// // Setup Test
// mockSvc := &mockSimpleDBClient{}
//
// myfunc(mockSvc)
//
// // Verify myFunc's functionality
// }
//
// It is important to note that this interface will have breaking changes
// when the service model is updated and adds new API operations, paginators,
// and waiters. Its suggested to use the pattern above for testing, or using
// tooling to generate mocks to satisfy the interfaces.
type SimpleDBAPI interface {
BatchDeleteAttributes(*simpledb.BatchDeleteAttributesInput) (*simpledb.BatchDeleteAttributesOutput, error)
BatchDeleteAttributesWithContext(aws.Context, *simpledb.BatchDeleteAttributesInput, ...request.Option) (*simpledb.BatchDeleteAttributesOutput, error)
BatchDeleteAttributesRequest(*simpledb.BatchDeleteAttributesInput) (*request.Request, *simpledb.BatchDeleteAttributesOutput)
BatchPutAttributes(*simpledb.BatchPutAttributesInput) (*simpledb.BatchPutAttributesOutput, error)
BatchPutAttributesWithContext(aws.Context, *simpledb.BatchPutAttributesInput, ...request.Option) (*simpledb.BatchPutAttributesOutput, error)
BatchPutAttributesRequest(*simpledb.BatchPutAttributesInput) (*request.Request, *simpledb.BatchPutAttributesOutput)
CreateDomain(*simpledb.CreateDomainInput) (*simpledb.CreateDomainOutput, error)
CreateDomainWithContext(aws.Context, *simpledb.CreateDomainInput, ...request.Option) (*simpledb.CreateDomainOutput, error)
CreateDomainRequest(*simpledb.CreateDomainInput) (*request.Request, *simpledb.CreateDomainOutput)
DeleteAttributes(*simpledb.DeleteAttributesInput) (*simpledb.DeleteAttributesOutput, error)
DeleteAttributesWithContext(aws.Context, *simpledb.DeleteAttributesInput, ...request.Option) (*simpledb.DeleteAttributesOutput, error)
DeleteAttributesRequest(*simpledb.DeleteAttributesInput) (*request.Request, *simpledb.DeleteAttributesOutput)
DeleteDomain(*simpledb.DeleteDomainInput) (*simpledb.DeleteDomainOutput, error)
DeleteDomainWithContext(aws.Context, *simpledb.DeleteDomainInput, ...request.Option) (*simpledb.DeleteDomainOutput, error)
DeleteDomainRequest(*simpledb.DeleteDomainInput) (*request.Request, *simpledb.DeleteDomainOutput)
DomainMetadata(*simpledb.DomainMetadataInput) (*simpledb.DomainMetadataOutput, error)
DomainMetadataWithContext(aws.Context, *simpledb.DomainMetadataInput, ...request.Option) (*simpledb.DomainMetadataOutput, error)
DomainMetadataRequest(*simpledb.DomainMetadataInput) (*request.Request, *simpledb.DomainMetadataOutput)
GetAttributes(*simpledb.GetAttributesInput) (*simpledb.GetAttributesOutput, error)
GetAttributesWithContext(aws.Context, *simpledb.GetAttributesInput, ...request.Option) (*simpledb.GetAttributesOutput, error)
GetAttributesRequest(*simpledb.GetAttributesInput) (*request.Request, *simpledb.GetAttributesOutput)
ListDomains(*simpledb.ListDomainsInput) (*simpledb.ListDomainsOutput, error)
ListDomainsWithContext(aws.Context, *simpledb.ListDomainsInput, ...request.Option) (*simpledb.ListDomainsOutput, error)
ListDomainsRequest(*simpledb.ListDomainsInput) (*request.Request, *simpledb.ListDomainsOutput)
ListDomainsPages(*simpledb.ListDomainsInput, func(*simpledb.ListDomainsOutput, bool) bool) error
ListDomainsPagesWithContext(aws.Context, *simpledb.ListDomainsInput, func(*simpledb.ListDomainsOutput, bool) bool, ...request.Option) error
PutAttributes(*simpledb.PutAttributesInput) (*simpledb.PutAttributesOutput, error)
PutAttributesWithContext(aws.Context, *simpledb.PutAttributesInput, ...request.Option) (*simpledb.PutAttributesOutput, error)
PutAttributesRequest(*simpledb.PutAttributesInput) (*request.Request, *simpledb.PutAttributesOutput)
Select(*simpledb.SelectInput) (*simpledb.SelectOutput, error)
SelectWithContext(aws.Context, *simpledb.SelectInput, ...request.Option) (*simpledb.SelectOutput, error)
SelectRequest(*simpledb.SelectInput) (*request.Request, *simpledb.SelectOutput)
SelectPages(*simpledb.SelectInput, func(*simpledb.SelectOutput, bool) bool) error
SelectPagesWithContext(aws.Context, *simpledb.SelectInput, func(*simpledb.SelectOutput, bool) bool, ...request.Option) error
}
var _ SimpleDBAPI = (*simpledb.SimpleDB)(nil)

View file

@ -0,0 +1,33 @@
package simpledb
import (
"github.com/stretchr/testify/assert"
"net/http"
"testing"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/awstesting"
)
func TestUnmarhsalErrorLeak(t *testing.T) {
req := &request.Request{
HTTPRequest: &http.Request{
Header: make(http.Header),
Body: &awstesting.ReadCloser{Size: 2048},
},
}
req.HTTPResponse = &http.Response{
Body: &awstesting.ReadCloser{Size: 2048},
Header: http.Header{
"X-Amzn-Requestid": []string{"1"},
},
StatusCode: http.StatusOK,
}
reader := req.HTTPResponse.Body.(*awstesting.ReadCloser)
unmarshalError(req)
assert.NotNil(t, req.Error)
assert.Equal(t, reader.Closed, true)
assert.Equal(t, reader.Size, 0)
}

View file

@ -0,0 +1,53 @@
package simpledb
import (
"encoding/xml"
"io"
"io/ioutil"
"strings"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/request"
)
type xmlErrorDetail struct {
Code string `xml:"Code"`
Message string `xml:"Message"`
}
type xmlErrorResponse struct {
XMLName xml.Name `xml:"Response"`
Errors []xmlErrorDetail `xml:"Errors>Error"`
RequestID string `xml:"RequestID"`
}
func unmarshalError(r *request.Request) {
defer r.HTTPResponse.Body.Close()
defer io.Copy(ioutil.Discard, r.HTTPResponse.Body)
if r.HTTPResponse.ContentLength == int64(0) {
// No body, use status code to generate an awserr.Error
r.Error = awserr.NewRequestFailure(
awserr.New(strings.Replace(r.HTTPResponse.Status, " ", "", -1), r.HTTPResponse.Status, nil),
r.HTTPResponse.StatusCode,
"",
)
return
}
resp := &xmlErrorResponse{}
err := xml.NewDecoder(r.HTTPResponse.Body).Decode(resp)
if err != nil && err != io.EOF {
r.Error = awserr.New("SerializationError", "failed to decode SimpleDB XML error response", nil)
} else if len(resp.Errors) == 0 {
r.Error = awserr.New("MissingError", "missing error code in SimpleDB XML error response", nil)
} else {
// If there are multiple error codes, return only the first as the aws.Error interface only supports
// one error code.
r.Error = awserr.NewRequestFailure(
awserr.New(resp.Errors[0].Code, resp.Errors[0].Message, nil),
r.HTTPResponse.StatusCode,
resp.RequestID,
)
}
}

View file

@ -0,0 +1,139 @@
package simpledb_test
import (
"bytes"
"io/ioutil"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/awstesting/unit"
"github.com/aws/aws-sdk-go/service/simpledb"
)
var statusCodeErrorTests = []struct {
scode int
status string
code string
message string
}{
{301, "Moved Permanently", "MovedPermanently", "Moved Permanently"},
{403, "Forbidden", "Forbidden", "Forbidden"},
{400, "Bad Request", "BadRequest", "Bad Request"},
{404, "Not Found", "NotFound", "Not Found"},
{500, "Internal Error", "InternalError", "Internal Error"},
}
func TestStatusCodeError(t *testing.T) {
for _, test := range statusCodeErrorTests {
s := simpledb.New(unit.Session)
s.Handlers.Send.Clear()
s.Handlers.Send.PushBack(func(r *request.Request) {
body := ioutil.NopCloser(bytes.NewReader([]byte{}))
r.HTTPResponse = &http.Response{
ContentLength: 0,
StatusCode: test.scode,
Status: test.status,
Body: body,
}
})
_, err := s.CreateDomain(&simpledb.CreateDomainInput{
DomainName: aws.String("test-domain"),
})
assert.Error(t, err)
assert.Equal(t, test.code, err.(awserr.Error).Code())
assert.Equal(t, test.message, err.(awserr.Error).Message())
}
}
var responseErrorTests = []struct {
scode int
status string
code string
message string
requestID string
errors []struct {
code string
message string
}
}{
{
scode: 400,
status: "Bad Request",
code: "MissingError",
message: "missing error code in SimpleDB XML error response",
requestID: "101",
errors: []struct{ code, message string }{},
},
{
scode: 403,
status: "Forbidden",
code: "AuthFailure",
message: "AWS was not able to validate the provided access keys.",
requestID: "1111",
errors: []struct{ code, message string }{
{"AuthFailure", "AWS was not able to validate the provided access keys."},
},
},
{
scode: 500,
status: "Internal Error",
code: "MissingParameter",
message: "Message #1",
requestID: "8756",
errors: []struct{ code, message string }{
{"MissingParameter", "Message #1"},
{"InternalError", "Message #2"},
},
},
}
func TestResponseError(t *testing.T) {
for _, test := range responseErrorTests {
s := simpledb.New(unit.Session)
s.Handlers.Send.Clear()
s.Handlers.Send.PushBack(func(r *request.Request) {
xml := createXMLResponse(test.requestID, test.errors)
body := ioutil.NopCloser(bytes.NewReader([]byte(xml)))
r.HTTPResponse = &http.Response{
ContentLength: int64(len(xml)),
StatusCode: test.scode,
Status: test.status,
Body: body,
}
})
_, err := s.CreateDomain(&simpledb.CreateDomainInput{
DomainName: aws.String("test-domain"),
})
assert.Error(t, err)
assert.Equal(t, test.code, err.(awserr.Error).Code())
assert.Equal(t, test.message, err.(awserr.Error).Message())
if len(test.errors) > 0 {
assert.Equal(t, test.requestID, err.(awserr.RequestFailure).RequestID())
assert.Equal(t, test.scode, err.(awserr.RequestFailure).StatusCode())
}
}
}
// createXMLResponse constructs an XML string that has one or more error messages in it.
func createXMLResponse(requestID string, errors []struct{ code, message string }) []byte {
var buf bytes.Buffer
buf.WriteString(`<?xml version="1.0"?><Response><Errors>`)
for _, e := range errors {
buf.WriteString(`<Error><Code>`)
buf.WriteString(e.code)
buf.WriteString(`</Code><Message>`)
buf.WriteString(e.message)
buf.WriteString(`</Message></Error>`)
}
buf.WriteString(`</Errors><RequestID>`)
buf.WriteString(requestID)
buf.WriteString(`</RequestID></Response>`)
return buf.Bytes()
}