Skip to content

Commit

Permalink
Code generate protocol marshaler tests for idempotency token
Browse files Browse the repository at this point in the history
  • Loading branch information
jasdel committed Feb 2, 2016
1 parent 818ae5a commit 8e0e19a
Show file tree
Hide file tree
Showing 10 changed files with 902 additions and 20 deletions.
178 changes: 176 additions & 2 deletions private/protocol/ec2query/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ var _ json.Marshaler
var _ time.Time
var _ xmlutil.XMLNode
var _ xml.Attr
var _ = protocol.UnmarshalDiscardBody
var _ = awstesting.GenerateAssertions
var _ = ioutil.Discard
var _ = util.Trim("")
var _ = url.Values{}
var _ = io.EOF
var _ = aws.String

func init() {
protocol.RandReader = &awstesting.ZeroReader{}
}

//The service client's operations are safe to be used concurrently.
// It is not safe to mutate any of the client's properties though.
type InputService1ProtocolTest struct {
Expand Down Expand Up @@ -771,6 +773,130 @@ type InputService8TestShapeInputService8TestCaseOperation1Output struct {
_ struct{} `type:"structure"`
}

//The service client's operations are safe to be used concurrently.
// It is not safe to mutate any of the client's properties though.
type InputService9ProtocolTest struct {
*client.Client
}

// New creates a new instance of the InputService9ProtocolTest 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 InputService9ProtocolTest client from just a session.
// svc := inputservice9protocoltest.New(mySession)
//
// // Create a InputService9ProtocolTest client with additional configuration
// svc := inputservice9protocoltest.New(mySession, aws.NewConfig().WithRegion("us-west-2"))
func NewInputService9ProtocolTest(p client.ConfigProvider, cfgs ...*aws.Config) *InputService9ProtocolTest {
c := p.ClientConfig("inputservice9protocoltest", cfgs...)
return newInputService9ProtocolTestClient(*c.Config, c.Handlers, c.Endpoint, c.SigningRegion)
}

// newClient creates, initializes and returns a new service client instance.
func newInputService9ProtocolTestClient(cfg aws.Config, handlers request.Handlers, endpoint, signingRegion string) *InputService9ProtocolTest {
svc := &InputService9ProtocolTest{
Client: client.New(
cfg,
metadata.ClientInfo{
ServiceName: "inputservice9protocoltest",
SigningRegion: signingRegion,
Endpoint: endpoint,
APIVersion: "2014-01-01",
},
handlers,
),
}

// Handlers
svc.Handlers.Sign.PushBack(v4.Sign)
svc.Handlers.Build.PushBackNamed(ec2query.BuildHandler)
svc.Handlers.Unmarshal.PushBackNamed(ec2query.UnmarshalHandler)
svc.Handlers.UnmarshalMeta.PushBackNamed(ec2query.UnmarshalMetaHandler)
svc.Handlers.UnmarshalError.PushBackNamed(ec2query.UnmarshalErrorHandler)

return svc
}

// newRequest creates a new request for a InputService9ProtocolTest operation and runs any
// custom request initialization.
func (c *InputService9ProtocolTest) newRequest(op *request.Operation, params, data interface{}) *request.Request {
req := c.NewRequest(op, params, data)

return req
}

const opInputService9TestCaseOperation1 = "OperationName"

// InputService9TestCaseOperation1Request generates a request for the InputService9TestCaseOperation1 operation.
func (c *InputService9ProtocolTest) InputService9TestCaseOperation1Request(input *InputService9TestShapeInputShape) (req *request.Request, output *InputService9TestShapeInputService9TestCaseOperation1Output) {
op := &request.Operation{
Name: opInputService9TestCaseOperation1,
HTTPMethod: "POST",
HTTPPath: "/path",
}

if input == nil {
input = &InputService9TestShapeInputShape{}
}

req = c.newRequest(op, input, output)
req.Handlers.Unmarshal.Remove(ec2query.UnmarshalHandler)
req.Handlers.Unmarshal.PushBackNamed(protocol.UnmarshalDiscardBodyHandler)
output = &InputService9TestShapeInputService9TestCaseOperation1Output{}
req.Data = output
return
}

func (c *InputService9ProtocolTest) InputService9TestCaseOperation1(input *InputService9TestShapeInputShape) (*InputService9TestShapeInputService9TestCaseOperation1Output, error) {
req, out := c.InputService9TestCaseOperation1Request(input)
err := req.Send()
return out, err
}

const opInputService9TestCaseOperation2 = "OperationName"

// InputService9TestCaseOperation2Request generates a request for the InputService9TestCaseOperation2 operation.
func (c *InputService9ProtocolTest) InputService9TestCaseOperation2Request(input *InputService9TestShapeInputShape) (req *request.Request, output *InputService9TestShapeInputService9TestCaseOperation2Output) {
op := &request.Operation{
Name: opInputService9TestCaseOperation2,
HTTPMethod: "POST",
HTTPPath: "/path",
}

if input == nil {
input = &InputService9TestShapeInputShape{}
}

req = c.newRequest(op, input, output)
req.Handlers.Unmarshal.Remove(ec2query.UnmarshalHandler)
req.Handlers.Unmarshal.PushBackNamed(protocol.UnmarshalDiscardBodyHandler)
output = &InputService9TestShapeInputService9TestCaseOperation2Output{}
req.Data = output
return
}

func (c *InputService9ProtocolTest) InputService9TestCaseOperation2(input *InputService9TestShapeInputShape) (*InputService9TestShapeInputService9TestCaseOperation2Output, error) {
req, out := c.InputService9TestCaseOperation2Request(input)
err := req.Send()
return out, err
}

type InputService9TestShapeInputService9TestCaseOperation1Output struct {
_ struct{} `type:"structure"`
}

type InputService9TestShapeInputService9TestCaseOperation2Output struct {
_ struct{} `type:"structure"`
}

type InputService9TestShapeInputShape struct {
_ struct{} `type:"structure"`

Token *string `type:"string" idempotencyToken:"true"`
}

//
// Tests begin here
//
Expand Down Expand Up @@ -991,3 +1117,51 @@ func TestInputService8ProtocolTestTimestampValuesCase1(t *testing.T) {
// assert headers

}

func TestInputService9ProtocolTestIdempotencyTokenAutoFillCase1(t *testing.T) {
sess := session.New()
svc := NewInputService9ProtocolTest(sess, &aws.Config{Endpoint: aws.String("https://test")})
input := &InputService9TestShapeInputShape{
Token: aws.String("abc123"),
}
req, _ := svc.InputService9TestCaseOperation1Request(input)
r := req.HTTPRequest

// build request
ec2query.Build(req)
assert.NoError(t, req.Error)

// assert body
assert.NotNil(t, r.Body)
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertQuery(t, `Token=abc123`, util.Trim(string(body)))

// assert URL
awstesting.AssertURL(t, "https://test/path", r.URL.String())

// assert headers

}

func TestInputService9ProtocolTestIdempotencyTokenAutoFillCase2(t *testing.T) {
sess := session.New()
svc := NewInputService9ProtocolTest(sess, &aws.Config{Endpoint: aws.String("https://test")})
input := &InputService9TestShapeInputShape{}
req, _ := svc.InputService9TestCaseOperation2Request(input)
r := req.HTTPRequest

// build request
ec2query.Build(req)
assert.NoError(t, req.Error)

// assert body
assert.NotNil(t, r.Body)
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertQuery(t, `Token=00000000-0000-4000-8000-000000000000`, util.Trim(string(body)))

// assert URL
awstesting.AssertURL(t, "https://test/path", r.URL.String())

// assert headers

}
6 changes: 4 additions & 2 deletions private/protocol/ec2query/unmarshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ var _ json.Marshaler
var _ time.Time
var _ xmlutil.XMLNode
var _ xml.Attr
var _ = protocol.UnmarshalDiscardBody
var _ = awstesting.GenerateAssertions
var _ = ioutil.Discard
var _ = util.Trim("")
var _ = url.Values{}
var _ = io.EOF
var _ = aws.String

func init() {
protocol.RandReader = &awstesting.ZeroReader{}
}

//The service client's operations are safe to be used concurrently.
// It is not safe to mutate any of the client's properties though.
type OutputService1ProtocolTest struct {
Expand Down
Loading

0 comments on commit 8e0e19a

Please sign in to comment.