Update vendored deps, including AWS SDK, openpgp, ftp, ...

This commit is contained in:
Andrey Smirnov
2018-04-05 17:46:45 +03:00
parent cef4fefc40
commit 0e6ee35942
1497 changed files with 450721 additions and 68034 deletions
+107 -19
View File
@@ -10,10 +10,10 @@ import (
"io/ioutil"
"path"
"path/filepath"
"regexp"
"sort"
"strings"
"text/template"
"unicode"
)
// An API defines a service API's definition. and logic to serialize the definition.
@@ -94,23 +94,53 @@ func (a *API) InterfacePackageName() string {
return a.PackageName() + "iface"
}
var nameRegex = regexp.MustCompile(`^Amazon|AWS\s*|\(.*|\s+|\W+`)
var stripServiceNamePrefixes = []string{
"Amazon",
"AWS",
}
// StructName returns the struct name for a given API.
func (a *API) StructName() string {
if a.name == "" {
name := a.Metadata.ServiceAbbreviation
if name == "" {
name = a.Metadata.ServiceFullName
}
if len(a.name) != 0 {
return a.name
}
name = nameRegex.ReplaceAllString(name, "")
name := a.Metadata.ServiceAbbreviation
if len(name) == 0 {
name = a.Metadata.ServiceFullName
}
a.name = name
if name, ok := serviceAliases[strings.ToLower(name)]; ok {
a.name = name
name = strings.TrimSpace(name)
// Strip out prefix names not reflected in service client symbol names.
for _, prefix := range stripServiceNamePrefixes {
if strings.HasPrefix(name, prefix) {
name = name[len(prefix):]
break
}
}
// Replace all Non-letter/number values with space
runes := []rune(name)
for i := 0; i < len(runes); i++ {
if r := runes[i]; !(unicode.IsNumber(r) || unicode.IsLetter(r)) {
runes[i] = ' '
}
}
name = string(runes)
// Title case name so its readable as a symbol.
name = strings.Title(name)
// Strip out spaces.
name = strings.Replace(name, " ", "", -1)
// Swap out for alias name if one is defined.
if alias, ok := serviceAliases[strings.ToLower(name)]; ok {
name = alias
}
a.name = name
return a.name
}
@@ -307,6 +337,12 @@ var noCrossLinkServices = map[string]struct{}{
"swf": {},
}
// HasCrosslinks will return whether or not a service has crosslinking .
func HasCrosslinks(service string) bool {
_, ok := noCrossLinkServices[service]
return !ok
}
// GetCrosslinkURL returns the crosslinking URL for the shape based on the name and
// uid provided. Empty string is returned if no crosslink link could be determined.
func GetCrosslinkURL(baseURL, uid string, params ...string) string {
@@ -314,14 +350,16 @@ func GetCrosslinkURL(baseURL, uid string, params ...string) string {
return ""
}
if _, ok := noCrossLinkServices[strings.ToLower(serviceIDFromUID(uid))]; ok {
if !HasCrosslinks(strings.ToLower(ServiceIDFromUID(uid))) {
return ""
}
return strings.Join(append([]string{baseURL, "goto", "WebAPI", uid}, params...), "/")
}
func serviceIDFromUID(uid string) string {
// ServiceIDFromUID will parse the service id from the uid and return
// the service id that was found.
func ServiceIDFromUID(uid string) string {
found := 0
i := len(uid) - 1
for ; i >= 0; i-- {
@@ -363,7 +401,7 @@ var tplServiceDoc = template.Must(template.New("service docs").Funcs(template.Fu
//
// Using the Client
//
// To {{ .Metadata.ServiceFullName }} with the SDK use the New function to create
// To contact {{ .Metadata.ServiceFullName }} with the SDK use the New function to create
// a new service client. With that client you can make API requests to the service.
// These clients are safe to use concurrently.
//
@@ -450,16 +488,17 @@ func New(p client.ConfigProvider, cfgs ...*aws.Config) *{{ .StructName }} {
{{- else -}}
c := p.ClientConfig({{ EndpointsIDValue . }}, cfgs...)
{{- end }}
{{- if .Metadata.SigningName }}
if c.SigningNameDerived || len(c.SigningName) == 0{
c.SigningName = "{{ .Metadata.SigningName }}"
}
{{- end }}
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) *{{ .StructName }} {
{{- if .Metadata.SigningName }}
if len(signingName) == 0 {
signingName = "{{ .Metadata.SigningName }}"
}
{{- end }}
svc := &{{ .StructName }}{
Client: client.New(
cfg,
@@ -763,3 +802,52 @@ func (a *API) APIErrorsGoCode() string {
return strings.TrimSpace(buf.String())
}
// removeOperation removes an operation, its input/output shapes, as well as
// any references/shapes that are unique to this operation.
func (a *API) removeOperation(name string) {
fmt.Println("removing operation,", name)
op := a.Operations[name]
delete(a.Operations, name)
delete(a.Examples, name)
a.removeShape(op.InputRef.Shape)
a.removeShape(op.OutputRef.Shape)
}
// removeShape removes the given shape, and all form member's reference target
// shapes. Will also remove member reference targeted shapes if those shapes do
// not have any additional references.
func (a *API) removeShape(s *Shape) {
fmt.Println("removing shape,", s.ShapeName)
delete(a.Shapes, s.ShapeName)
for name, ref := range s.MemberRefs {
a.removeShapeRef(ref)
delete(s.MemberRefs, name)
}
for _, ref := range []*ShapeRef{&s.MemberRef, &s.KeyRef, &s.ValueRef} {
if ref.Shape == nil {
continue
}
a.removeShapeRef(ref)
*ref = ShapeRef{}
}
}
// removeShapeRef removes the shape reference from its target shape. If the
// reference was the last reference to the target shape, the shape will also be
// removed.
func (a *API) removeShapeRef(ref *ShapeRef) {
if ref.Shape == nil {
return
}
ref.Shape.removeRef(ref)
if len(ref.Shape.refs) == 0 {
a.removeShape(ref.Shape)
}
}
+60 -43
View File
@@ -1,4 +1,4 @@
// +build 1.6,codegen
// +build go1.8,codegen
package api
@@ -6,49 +6,66 @@ import (
"testing"
)
func TestStructNameWithFullName(t *testing.T) {
a := API{
Metadata: Metadata{
ServiceFullName: "Amazon Service Name-100",
func TestAPI_StructName(t *testing.T) {
origAliases := serviceAliases
defer func() { serviceAliases = origAliases }()
cases := map[string]struct {
Aliases map[string]string
Metadata Metadata
StructName string
}{
"FullName": {
Metadata: Metadata{
ServiceFullName: "Amazon Service Name-100",
},
StructName: "ServiceName100",
},
"Abbreviation": {
Metadata: Metadata{
ServiceFullName: "Amazon Service Name-100",
ServiceAbbreviation: "AWS SN100",
},
StructName: "SN100",
},
"Lowercase Name": {
Metadata: Metadata{
EndpointPrefix: "other",
ServiceFullName: "AWS Lowercase service",
ServiceAbbreviation: "lowercase",
},
StructName: "Lowercase",
},
"Lowercase Name Mixed": {
Metadata: Metadata{
EndpointPrefix: "other",
ServiceFullName: "AWS Lowercase service",
ServiceAbbreviation: "lowercase name Goes heRe",
},
StructName: "LowercaseNameGoesHeRe",
},
"Alias": {
Aliases: map[string]string{
"elasticloadbalancing": "ELB",
},
Metadata: Metadata{
ServiceFullName: "Elastic Load Balancing",
},
StructName: "ELB",
},
}
if a.StructName() != "ServiceName100" {
t.Errorf("API struct name should have been %s, but received %s", "ServiceName100", a.StructName())
}
}
func TestStructNameWithAbbreviation(t *testing.T) {
a := API{
Metadata: Metadata{
ServiceFullName: "AWS Service Name-100",
ServiceAbbreviation: "AWS SN100",
},
}
if a.StructName() != "SN100" {
t.Errorf("API struct name should have been %s, but received %s", "SN100", a.StructName())
}
}
func TestStructNameForExceptions(t *testing.T) {
serviceAliases = map[string]string{}
serviceAliases["elasticloadbalancing"] = "ELB"
serviceAliases["config"] = "ConfigService"
a := API{
Metadata: Metadata{
ServiceFullName: "Elastic Load Balancing",
},
}
if a.StructName() != "ELB" {
t.Errorf("API struct name should have been %s, but received %s", "ELB", a.StructName())
}
a = API{
Metadata: Metadata{
ServiceFullName: "AWS Config",
},
}
if a.StructName() != "ConfigService" {
t.Errorf("API struct name should have been %s, but received %s", "ConfigService", a.StructName())
for k, c := range cases {
t.Run(k, func(t *testing.T) {
serviceAliases = c.Aliases
a := API{
Metadata: c.Metadata,
}
if e, o := c.StructName, a.StructName(); e != o {
t.Errorf("expect %v structName, got %v", e, o)
}
})
}
}
+11 -3
View File
@@ -53,12 +53,20 @@ func (a *API) customizationPasses() {
func s3Customizations(a *API) {
var strExpires *Shape
var keepContentMD5Ref = map[string]struct{}{
"PutObjectInput": struct{}{},
"UploadPartInput": struct{}{},
}
for name, s := range a.Shapes {
// Remove ContentMD5 members
if _, ok := s.MemberRefs["ContentMD5"]; ok {
delete(s.MemberRefs, "ContentMD5")
// Remove ContentMD5 members unless specified otherwise.
if _, keep := keepContentMD5Ref[name]; !keep {
if _, have := s.MemberRefs["ContentMD5"]; have {
delete(s.MemberRefs, "ContentMD5")
}
}
// Generate getter methods for API operation fields used by customizations.
for _, refName := range []string{"Bucket", "SSECustomerKey", "CopySourceSSECustomerKey"} {
if ref, ok := s.MemberRefs[refName]; ok {
ref.GenerateGetter = true
+28
View File
@@ -0,0 +1,28 @@
// +build codegen
package api
func (a *API) suppressEventStreams() {
const eventStreamMemberName = "EventStream"
for name, op := range a.Operations {
outbound := hasEventStream(op.InputRef.Shape)
inbound := hasEventStream(op.OutputRef.Shape)
if !(outbound || inbound) {
continue
}
a.removeOperation(name)
}
}
func hasEventStream(topShape *Shape) bool {
for _, ref := range topShape.MemberRefs {
if ref.Shape.IsEventStream {
return true
}
}
return false
}
+79
View File
@@ -0,0 +1,79 @@
// +build go1.6,codegen
package api
import (
"testing"
)
func TestSuppressEventStream(t *testing.T) {
cases := []struct {
API *API
Ops []string
Shapes []string
}{
{
API: &API{
Operations: map[string]*Operation{
"abc": {
InputRef: ShapeRef{
ShapeName: "abcRequest",
},
OutputRef: ShapeRef{
ShapeName: "abcResponse",
},
},
"eventStreamOp": {
InputRef: ShapeRef{
ShapeName: "eventStreamOpRequest",
},
OutputRef: ShapeRef{
ShapeName: "eventStreamOpResponse",
},
},
},
Shapes: map[string]*Shape{
"abcRequest": {},
"abcResponse": {},
"eventStreamOpRequest": {},
"eventStreamOpResponse": {
MemberRefs: map[string]*ShapeRef{
"eventStreamShape": {
ShapeName: "eventStreamShape",
},
},
},
"eventStreamShape": {
IsEventStream: true,
},
},
},
Ops: []string{"Abc"},
Shapes: []string{"AbcInput", "AbcOutput"},
},
}
for _, c := range cases {
c.API.Setup()
if e, a := c.Ops, c.API.OperationNames(); !stringsEqual(e, a) {
t.Errorf("expect %v ops, got %v", e, a)
}
if e, a := c.Shapes, c.API.ShapeNames(); !stringsEqual(e, a) {
t.Errorf("expect %v ops, got %v", e, a)
}
}
}
func stringsEqual(a, b []string) bool {
if len(a) != len(b) {
return false
}
for i := 0; i < len(a); i++ {
if a[i] != b[i] {
return false
}
}
return true
}
+121 -5
View File
@@ -32,11 +32,84 @@ func buildAPI() *API {
Shape: intShape,
}
nestedComplexShape := &Shape{
API: a,
ShapeName: "NestedComplexShape",
MemberRefs: map[string]*ShapeRef{
"NestedField": stringShapeRef,
},
Type: "structure",
}
nestedComplexShapeRef := &ShapeRef{
API: a,
ShapeName: "NestedComplexShape",
Shape: nestedComplexShape,
}
nestedListShape := &Shape{
API: a,
ShapeName: "NestedListShape",
MemberRef: *nestedComplexShapeRef,
Type: "list",
}
nestedListShapeRef := &ShapeRef{
API: a,
ShapeName: "NestedListShape",
Shape: nestedListShape,
}
complexShape := &Shape{
API: a,
ShapeName: "ComplexShape",
MemberRefs: map[string]*ShapeRef{
"Field": stringShapeRef,
"List": nestedListShapeRef,
},
Type: "structure",
}
complexShapeRef := &ShapeRef{
API: a,
ShapeName: "ComplexShape",
Shape: complexShape,
}
listShape := &Shape{
API: a,
ShapeName: "ListShape",
MemberRef: *complexShapeRef,
Type: "list",
}
listShapeRef := &ShapeRef{
API: a,
ShapeName: "ListShape",
Shape: listShape,
}
listsShape := &Shape{
API: a,
ShapeName: "ListsShape",
MemberRef: *listShapeRef,
Type: "list",
}
listsShapeRef := &ShapeRef{
API: a,
ShapeName: "ListsShape",
Shape: listsShape,
}
input := &Shape{
API: a,
ShapeName: "FooInput",
MemberRefs: map[string]*ShapeRef{
"BarShape": stringShapeRef,
"BarShape": stringShapeRef,
"ComplexField": complexShapeRef,
"ListField": listShapeRef,
"ListsField": listsShapeRef,
},
Type: "structure",
}
@@ -44,7 +117,10 @@ func buildAPI() *API {
API: a,
ShapeName: "FooOutput",
MemberRefs: map[string]*ShapeRef{
"BazShape": intShapeRef,
"BazShape": intShapeRef,
"ComplexField": complexShapeRef,
"ListField": listShapeRef,
"ListsField": listsShapeRef,
},
Type: "structure",
}
@@ -91,7 +167,27 @@ func TestExampleGeneration(t *testing.T) {
"Foo": [
{
"input": {
"BarShape": "Hello world"
"BarShape": "Hello world",
"ComplexField": {
"Field": "bar",
"List": [
{
"NestedField": "qux"
}
]
},
"ListField": [
{
"Field": "baz"
}
],
"ListsField": [
[
{
"Field": "baz"
}
]
]
},
"output": {
"BazShape": 1
@@ -121,7 +217,7 @@ func TestExampleGeneration(t *testing.T) {
expected := `
import (
"fmt"
"bytes"
"strings"
"time"
"github.com/aws/aws-sdk-go/aws"
@@ -131,7 +227,7 @@ import (
)
var _ time.Duration
var _ bytes.Buffer
var _ strings.Reader
var _ aws.Config
func parseTime(layout, value string) *time.Time {
@@ -149,6 +245,26 @@ func ExampleFooService_Foo_shared00() {
svc := fooservice.New(session.New())
input := &fooservice.FooInput{
BarShape: aws.String("Hello world"),
ComplexField: &fooservice.ComplexShape{
Field: aws.String("bar"),
List: []*fooservice.NestedComplexShape{
{
NestedField: aws.String("qux"),
},
},
},
ListField: []*fooservice.ComplexShape{
{
Field: aws.String("baz"),
},
},
ListsField: [][]*fooservice.ComplexShape{
{
{
Field: aws.String("baz"),
},
},
},
}
result, err := svc.Foo(input)
+54 -88
View File
@@ -44,17 +44,20 @@ func (builder defaultExamplesBuilder) BuildShape(ref *ShapeRef, shapes map[strin
}
memName := name
passRef := ref.Shape.MemberRefs[name]
if isMap {
memName = fmt.Sprintf("%q", memName)
passRef = &ref.Shape.ValueRef
}
switch v := shape.(type) {
case map[string]interface{}:
ret += builder.BuildComplex(name, memName, ref, v)
ret += builder.BuildComplex(name, memName, passRef, v)
case []interface{}:
ret += builder.BuildList(name, memName, ref, v)
ret += builder.BuildList(name, memName, passRef, v)
default:
ret += builder.BuildScalar(name, memName, ref, v)
ret += builder.BuildScalar(name, memName, passRef, v, ref.Shape.Payload == name)
}
}
return ret
@@ -69,105 +72,86 @@ func (builder defaultExamplesBuilder) BuildList(name, memName string, ref *Shape
return ""
}
t := ""
dataType := ""
format := ""
isComplex := false
passRef := ref
isMap := false
passRef := &ref.Shape.MemberRef
ret += fmt.Sprintf("%s: %s {\n", memName, builder.GoType(ref, false))
ret += builder.buildListElements(passRef, v)
ret += "},\n"
return ret
}
if ref.Shape.MemberRefs[name] != nil {
t = builder.GoType(&ref.Shape.MemberRefs[name].Shape.MemberRef, false)
dataType = ref.Shape.MemberRefs[name].Shape.MemberRef.Shape.Type
passRef = ref.Shape.MemberRefs[name]
if dataType == "map" {
t = fmt.Sprintf("map[string]%s", builder.GoType(&ref.Shape.MemberRefs[name].Shape.MemberRef.Shape.ValueRef, false))
passRef = &ref.Shape.MemberRefs[name].Shape.MemberRef.Shape.ValueRef
isMap = true
}
} else if ref.Shape.MemberRef.Shape != nil && ref.Shape.MemberRef.Shape.MemberRefs[name] != nil {
t = builder.GoType(&ref.Shape.MemberRef.Shape.MemberRefs[name].Shape.MemberRef, false)
dataType = ref.Shape.MemberRef.Shape.MemberRefs[name].Shape.MemberRef.Shape.Type
passRef = &ref.Shape.MemberRef.Shape.MemberRefs[name].Shape.MemberRef
} else {
t = builder.GoType(&ref.Shape.MemberRef, false)
dataType = ref.Shape.MemberRef.Shape.Type
passRef = &ref.Shape.MemberRef
func (builder defaultExamplesBuilder) buildListElements(ref *ShapeRef, v []interface{}) string {
if len(v) == 0 || ref == nil {
return ""
}
ret := ""
format := ""
isComplex := false
isList := false
// get format for atomic type. If it is not an atomic type,
// get the element.
switch v[0].(type) {
case string:
format = "%s"
case bool:
format = "%t"
case float64:
if dataType == "integer" || dataType == "int64" {
switch ref.Shape.Type {
case "integer", "int64", "long":
format = "%d"
} else {
default:
format = "%f"
}
default:
if ref.Shape.MemberRefs[name] != nil {
} else {
passRef = ref.Shape.MemberRef.Shape.MemberRefs[name]
// if passRef is nil that means we are either in a map or within a nested array
if passRef == nil {
passRef = &ref.Shape.MemberRef
}
}
case []interface{}:
isList = true
case map[string]interface{}:
isComplex = true
}
ret += fmt.Sprintf("%s: []%s {\n", memName, t)
for _, elem := range v {
if isComplex {
ret += fmt.Sprintf("{\n%s\n},\n", builder.BuildShape(passRef, elem.(map[string]interface{}), isMap))
ret += fmt.Sprintf("{\n%s\n},\n", builder.BuildShape(ref, elem.(map[string]interface{}), ref.Shape.Type == "map"))
} else if isList {
ret += fmt.Sprintf("{\n%s\n},\n", builder.buildListElements(&ref.Shape.MemberRef, elem.([]interface{})))
} else {
if dataType == "integer" || dataType == "int64" || dataType == "long" {
switch ref.Shape.Type {
case "integer", "int64", "long":
elem = int(elem.(float64))
}
ret += fmt.Sprintf("%s,\n", getValue(t, fmt.Sprintf(format, elem)))
ret += fmt.Sprintf("%s,\n", getValue(ref.Shape.Type, fmt.Sprintf(format, elem)))
}
}
ret += "},\n"
return ret
}
// BuildScalar will build atomic Go types.
func (builder defaultExamplesBuilder) BuildScalar(name, memName string, ref *ShapeRef, shape interface{}) string {
func (builder defaultExamplesBuilder) BuildScalar(name, memName string, ref *ShapeRef, shape interface{}, isPayload bool) string {
if ref == nil || ref.Shape == nil {
return ""
} else if ref.Shape.MemberRefs[name] == nil {
if ref.Shape.MemberRef.Shape != nil && ref.Shape.MemberRef.Shape.MemberRefs[name] != nil {
return correctType(memName, ref.Shape.MemberRef.Shape.MemberRefs[name].Shape.Type, shape)
}
if ref.Shape.Type != "structure" && ref.Shape.Type != "map" {
return correctType(memName, ref.Shape.Type, shape)
}
return ""
}
switch v := shape.(type) {
case bool:
return convertToCorrectType(memName, ref.Shape.MemberRefs[name].Shape.Type, fmt.Sprintf("%t", v))
return convertToCorrectType(memName, ref.Shape.Type, fmt.Sprintf("%t", v))
case int:
if ref.Shape.MemberRefs[name].Shape.Type == "timestamp" {
if ref.Shape.Type == "timestamp" {
return parseTimeString(ref, memName, fmt.Sprintf("%d", v))
}
return convertToCorrectType(memName, ref.Shape.MemberRefs[name].Shape.Type, fmt.Sprintf("%d", v))
return convertToCorrectType(memName, ref.Shape.Type, fmt.Sprintf("%d", v))
case float64:
dataType := ref.Shape.MemberRefs[name].Shape.Type
dataType := ref.Shape.Type
if dataType == "integer" || dataType == "int64" || dataType == "long" {
return convertToCorrectType(memName, ref.Shape.MemberRefs[name].Shape.Type, fmt.Sprintf("%d", int(shape.(float64))))
return convertToCorrectType(memName, ref.Shape.Type, fmt.Sprintf("%d", int(shape.(float64))))
}
return convertToCorrectType(memName, ref.Shape.MemberRefs[name].Shape.Type, fmt.Sprintf("%f", v))
return convertToCorrectType(memName, ref.Shape.Type, fmt.Sprintf("%f", v))
case string:
t := ref.Shape.MemberRefs[name].Shape.Type
t := ref.Shape.Type
switch t {
case "timestamp":
return parseTimeString(ref, memName, fmt.Sprintf("%s", v))
case "blob":
if (ref.Shape.MemberRefs[name].Streaming || ref.Shape.MemberRefs[name].Shape.Streaming) && ref.Shape.Payload == name {
if (ref.Streaming || ref.Shape.Streaming) && isPayload {
return fmt.Sprintf("%s: aws.ReadSeekCloser(strings.NewReader(%q)),\n", memName, v)
}
@@ -182,47 +166,33 @@ func (builder defaultExamplesBuilder) BuildScalar(name, memName string, ref *Sha
}
func (builder defaultExamplesBuilder) BuildComplex(name, memName string, ref *ShapeRef, v map[string]interface{}) string {
t := ""
if ref == nil {
return builder.BuildShape(nil, v, true)
}
member := ref.Shape.MemberRefs[name]
if member != nil && member.Shape != nil {
t = ref.Shape.MemberRefs[name].Shape.Type
} else {
t = ref.Shape.Type
}
switch t {
switch ref.Shape.Type {
case "structure":
passRef := ref.Shape.MemberRefs[name]
// passRef will be nil if the entry is a map. In that case
// we want to pass the reference, because the previous call
// passed the value reference.
if passRef == nil {
passRef = ref
}
return fmt.Sprintf(`%s: &%s{
%s
},
`, memName, builder.GoType(passRef, true), builder.BuildShape(passRef, v, false))
`, memName, builder.GoType(ref, true), builder.BuildShape(ref, v, false))
case "map":
return fmt.Sprintf(`%s: %s{
%s
},
`, name, builder.GoType(ref.Shape.MemberRefs[name], false), builder.BuildShape(&ref.Shape.MemberRefs[name].Shape.ValueRef, v, true))
`, name, builder.GoType(ref, false), builder.BuildShape(ref, v, true))
default:
panic(fmt.Sprintf("Expected complex type but recieved %q", ref.Shape.Type))
}
return ""
}
func (builder defaultExamplesBuilder) GoType(ref *ShapeRef, elem bool) string {
if ref.Shape.Type != "structure" && ref.Shape.Type != "list" && ref.Shape.Type != "map" {
return ref.GoTypeWithPkgName()
}
prefix := ""
if ref.Shape.Type == "list" {
ref = &ref.Shape.MemberRef
prefix = "[]*"
prefix = "[]"
}
name := ref.GoTypeWithPkgName()
@@ -233,10 +203,6 @@ func (builder defaultExamplesBuilder) GoType(ref *ShapeRef, elem bool) string {
}
}
if ref.Shape.Type != "structure" && ref.Shape.Type != "list" {
return name
}
return prefix + name
}
+3 -15
View File
@@ -9,21 +9,6 @@ import (
"path/filepath"
)
// Load takes a set of files for each filetype and returns an API pointer.
// The API will be initialized once all files have been loaded and parsed.
//
// Will panic if any failure opening the definition JSON files, or there
// are unrecognized exported names.
func Load(api, docs, paginators, waiters string) *API {
a := API{}
a.Attach(api)
a.Attach(docs)
a.Attach(paginators)
a.Attach(waiters)
a.Setup()
return &a
}
// Attach opens a file by name, and unmarshal its JSON data.
// Will proceed to setup the API if not already done so.
func (a *API) Attach(filename string) {
@@ -58,8 +43,11 @@ func (a *API) Setup() {
if !a.NoRenameToplevelShapes {
a.renameToplevelShapes()
}
a.renameCollidingFields()
a.updateTopLevelShapeReferences()
a.createInputOutputShapes()
a.suppressEventStreams()
a.customizationPasses()
if !a.NoRemoveUnusedShapes {
+3 -3
View File
@@ -72,7 +72,7 @@ const op{{ .ExportedName }} = "{{ .Name }}"
// {{ .ExportedName }}Request generates a "aws/request.Request" representing the
// client's request for the {{ .ExportedName }} operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -95,7 +95,7 @@ const op{{ .ExportedName }} = "{{ .Name }}"
{{ $crosslinkURL := GetCrosslinkURL $.API.BaseCrosslinkURL $.API.Metadata.UID $.ExportedName -}}
{{ if ne $crosslinkURL "" -}}
//
// Please also see {{ $crosslinkURL }}
// See also, {{ $crosslinkURL }}
{{ end -}}
func (c *{{ .API.StructName }}) {{ .ExportedName }}Request(` +
`input {{ .InputRef.GoType }}) (req *request.Request, output {{ .OutputRef.GoType }}) {
@@ -152,7 +152,7 @@ func (c *{{ .API.StructName }}) {{ .ExportedName }}Request(` +
{{ end -}}
{{ $crosslinkURL := GetCrosslinkURL $.API.BaseCrosslinkURL $.API.Metadata.UID $.ExportedName -}}
{{ if ne $crosslinkURL "" -}}
// Please also see {{ $crosslinkURL }}
// See also, {{ $crosslinkURL }}
{{ end -}}
func (c *{{ .API.StructName }}) {{ .ExportedName }}(` +
`input {{ .InputRef.GoType }}) ({{ .OutputRef.GoType }}, error) {
+14
View File
@@ -4,6 +4,7 @@ package api
import (
"fmt"
"encoding/json"
"reflect"
"strings"
@@ -79,6 +80,19 @@ func (f paramFiller) paramsStructAny(value interface{}, shape *Shape) string {
if v.IsValid() {
return fmt.Sprintf("aws.Time(time.Unix(%d, 0))", int(v.Float()))
}
case "jsonvalue":
v, err := json.Marshal(value)
if err != nil {
panic("failed to marshal JSONValue, "+err.Error())
}
const tmpl = `func() aws.JSONValue {
var m aws.JSONValue
if err := json.Unmarshal([]byte(%q), &m); err != nil {
panic("failed to unmarshal JSONValue, "+err.Error())
}
return m
}()`
return fmt.Sprintf(tmpl, string(v))
default:
panic("Unhandled type " + shape.Type)
}
+70 -22
View File
@@ -85,25 +85,29 @@ func (r *referenceResolver) resolveReference(ref *ShapeRef) {
return
}
if shape, ok := r.API.Shapes[ref.ShapeName]; ok {
if ref.JSONValue {
ref.ShapeName = "JSONValue"
r.API.Shapes[ref.ShapeName] = jsonvalueShape
}
ref.API = r.API // resolve reference back to API
ref.Shape = shape // resolve shape reference
if r.visited[ref] {
return
}
r.visited[ref] = true
shape.refs = append(shape.refs, ref) // register the ref
// resolve shape's references, if it has any
r.resolveShape(shape)
shape, ok := r.API.Shapes[ref.ShapeName]
if !ok {
panic(fmt.Sprintf("unable resolve reference, %s", ref.ShapeName))
return
}
if ref.JSONValue {
ref.ShapeName = "JSONValue"
r.API.Shapes[ref.ShapeName] = jsonvalueShape
}
ref.API = r.API // resolve reference back to API
ref.Shape = shape // resolve shape reference
if r.visited[ref] {
return
}
r.visited[ref] = true
shape.refs = append(shape.refs, ref) // register the ref
// resolve shape's references, if it has any
r.resolveShape(shape)
}
// resolveShape resolves a shape's Member Key Value, and nested member
@@ -164,7 +168,7 @@ func (a *API) fixStutterNames() {
for name, op := range a.Operations {
newName := re.ReplaceAllString(name, "")
if newName != name {
if newName != name && len(newName) > 0 {
delete(a.Operations, name)
a.Operations[newName] = op
}
@@ -173,7 +177,7 @@ func (a *API) fixStutterNames() {
for k, s := range a.Shapes {
newName := re.ReplaceAllString(k, "")
if newName != s.ShapeName {
if newName != s.ShapeName && len(newName) > 0 {
s.Rename(newName)
}
}
@@ -244,6 +248,50 @@ func (a *API) renameExportable() {
}
}
// renameCollidingFields will rename any fields that uses an SDK or Golang
// specific name.
func (a *API) renameCollidingFields() {
for _, v := range a.Shapes {
namesWithSet := map[string]struct{}{}
for k, field := range v.MemberRefs {
if strings.HasPrefix(k, "Set") {
namesWithSet[k] = struct{}{}
}
if collides(k) {
renameCollidingField(k, v, field)
}
}
// checks if any field names collide with setters.
for name := range namesWithSet {
if field, ok := v.MemberRefs["Set"+name]; ok {
renameCollidingField(name, v, field)
}
}
}
}
func renameCollidingField(name string, v *Shape, field *ShapeRef) {
newName := name + "_"
fmt.Printf("Shape %s's field %q renamed to %q\n", v.ShapeName, name, newName)
delete(v.MemberRefs, name)
v.MemberRefs[newName] = field
}
// collides will return true if it is a name used by the SDK or Golang.
func collides(name string) bool {
switch name {
case "String",
"GoString",
"Validate":
return true
default:
return false
}
}
// createInputOutputShapes creates toplevel input/output shapes if they
// have not been defined in the API. This normalizes all APIs to always
// have an input and output structure in the signature.
@@ -278,9 +326,9 @@ func (a *API) makeIOShape(name string) *Shape {
// removeUnusedShapes removes shapes from the API which are not referenced by any
// other shape in the API.
func (a *API) removeUnusedShapes() {
for n, s := range a.Shapes {
for _, s := range a.Shapes {
if len(s.refs) == 0 {
delete(a.Shapes, n)
a.removeShape(s)
}
}
}
+44 -2
View File
@@ -22,7 +22,7 @@ func TestUniqueInputAndOutputs(t *testing.T) {
v.output = true
shamelist["FooService"]["OpBothNoRename"] = v
testCases := [][]struct {
cases := [][]struct {
expectedInput string
expectedOutput string
operation string
@@ -113,7 +113,7 @@ func TestUniqueInputAndOutputs(t *testing.T) {
},
}
for _, c := range testCases {
for _, c := range cases {
a := &API{
name: "FooService",
Operations: map[string]*Operation{},
@@ -167,3 +167,45 @@ func TestUniqueInputAndOutputs(t *testing.T) {
}
}
func TestCollidingFields(t *testing.T) {
cases := []struct {
api *API
expected []*Shapes
}{
{
&API{
name: "FooService",
Shapes: []*Shapes{
{
MemberRefs: map[string]*ShapeRef{
"String": &ShapeRef{},
"GoString": &ShapeRef{},
"Validate": &ShapeRef{},
"Foo": &ShapeRef{},
"SetFoo": &ShapeRef{},
},
},
},
},
[]*Shapes{
{
MemberRefs: map[string]*ShapeRef{
"String_": &ShapeRef{},
"GoString_": &ShapeRef{},
"Validate_": &ShapeRef{},
"Foo": &ShapeRef{},
"SetFoo_": &ShapeRef{},
},
},
},
},
}
for _, c := range testCases {
c.api.renameCollidingFields()
if !reflect.DeepEqual(c.api.Shapes, c.expected) {
t.Errorf("expected %v, but received %v", c.expected, c.api.Shapes)
}
}
}
+5 -14
View File
@@ -55,9 +55,9 @@ type Shape struct {
ShapeName string
Documentation string
MemberRefs map[string]*ShapeRef `json:"members"`
MemberRef ShapeRef `json:"member"`
KeyRef ShapeRef `json:"key"`
ValueRef ShapeRef `json:"value"`
MemberRef ShapeRef `json:"member"` // List ref
KeyRef ShapeRef `json:"key"` // map key ref
ValueRef ShapeRef `json:"value"` // map value ref
Required []string
Payload string
Type string
@@ -73,6 +73,8 @@ type Shape struct {
Min float64 // optional Minimum length (string, list) or value (number)
Max float64 // optional Maximum length (string, list) or value (number)
IsEventStream bool `json:"eventstream"`
refs []*ShapeRef // References to this shape
resolvePkg string // use this package in the goType() if present
@@ -516,17 +518,6 @@ var structShapeTmpl = template.Must(template.New("StructShape").Funcs(template.F
"GetCrosslinkURL": GetCrosslinkURL,
}).Parse(`
{{ .Docstring }}
{{ if ne $.OrigShapeName "" -}}
{{ $crosslinkURL := GetCrosslinkURL $.API.BaseCrosslinkURL $.API.Metadata.UID $.OrigShapeName -}}
{{ if ne $crosslinkURL "" -}}
// Please also see {{ $crosslinkURL }}
{{ end -}}
{{ else -}}
{{ $crosslinkURL := GetCrosslinkURL $.API.BaseCrosslinkURL $.API.Metadata.UID $.ShapeName -}}
{{ if ne $crosslinkURL "" -}}
// Please also see {{ $crosslinkURL }}
{{ end -}}
{{ end -}}
{{ $context := . -}}
type {{ .ShapeName }} struct {
_ struct{} {{ .GoTags true false }}
+13 -1
View File
@@ -132,7 +132,7 @@ func main() {
for svcName := range excludeServices {
if strings.Contains(os.Getenv("SERVICES"), svcName) {
fmt.Printf("Service %s is not supported\n", svcName)
fmt.Fprintf(os.Stderr, "Service %s is not supported\n", svcName)
os.Exit(1)
}
}
@@ -141,6 +141,10 @@ func main() {
// Remove old API versions from list
m := map[string]bool{}
// caches paths to ensure we are not overriding previously generated
// code.
servicePaths := map[string]struct{}{}
for i := range files {
idx := len(files) - 1 - i
parts := strings.Split(files[idx], string(filepath.Separator))
@@ -168,6 +172,13 @@ func main() {
continue
}
if _, ok := servicePaths[genInfo.PackageDir]; ok {
fmt.Fprintf(os.Stderr, "Path %q has already been generated", genInfo.PackageDir)
os.Exit(1)
}
servicePaths[genInfo.PackageDir] = struct{}{}
wg.Add(1)
go func(g *generateInfo, filename string) {
defer wg.Done()
@@ -183,6 +194,7 @@ func writeServiceFiles(g *generateInfo, filename string) {
if r := recover(); r != nil {
fmt.Fprintf(os.Stderr, "Error generating %s\n%s\n%s\n",
filename, r, debug.Stack())
os.Exit(1)
}
}()
+1 -1
View File
@@ -24,7 +24,7 @@ func Build(r *request.Request) {
r.Error = awserr.New("SerializationError", "failed encoding EC2 Query request", err)
}
if r.ExpireTime == 0 {
if !r.IsPresigned() {
r.HTTPRequest.Method = "POST"
r.HTTPRequest.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=utf-8")
r.SetBufferBody([]byte(body.Encode()))
+408 -37
View File
@@ -24,7 +24,6 @@ import (
"github.com/aws/aws-sdk-go/private/protocol/ec2query"
"github.com/aws/aws-sdk-go/private/protocol/xml/xmlutil"
"github.com/aws/aws-sdk-go/private/util"
"github.com/stretchr/testify/assert"
)
var _ bytes.Buffer // always import bytes
@@ -108,7 +107,7 @@ const opInputService1TestCaseOperation1 = "OperationName"
// InputService1TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the InputService1TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -261,7 +260,7 @@ const opInputService2TestCaseOperation1 = "OperationName"
// InputService2TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the InputService2TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -422,7 +421,7 @@ const opInputService3TestCaseOperation1 = "OperationName"
// InputService3TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the InputService3TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -579,7 +578,7 @@ const opInputService4TestCaseOperation1 = "OperationName"
// InputService4TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the InputService4TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -648,12 +647,36 @@ func (c *InputService4ProtocolTest) InputService4TestCaseOperation1WithContext(c
type InputService4TestShapeInputService4TestCaseOperation1Input struct {
_ struct{} `type:"structure"`
ListArg []*string `type:"list"`
ListBools []*bool `type:"list"`
ListFloats []*float64 `type:"list"`
ListIntegers []*int64 `type:"list"`
ListStrings []*string `type:"list"`
}
// SetListArg sets the ListArg field's value.
func (s *InputService4TestShapeInputService4TestCaseOperation1Input) SetListArg(v []*string) *InputService4TestShapeInputService4TestCaseOperation1Input {
s.ListArg = v
// SetListBools sets the ListBools field's value.
func (s *InputService4TestShapeInputService4TestCaseOperation1Input) SetListBools(v []*bool) *InputService4TestShapeInputService4TestCaseOperation1Input {
s.ListBools = v
return s
}
// SetListFloats sets the ListFloats field's value.
func (s *InputService4TestShapeInputService4TestCaseOperation1Input) SetListFloats(v []*float64) *InputService4TestShapeInputService4TestCaseOperation1Input {
s.ListFloats = v
return s
}
// SetListIntegers sets the ListIntegers field's value.
func (s *InputService4TestShapeInputService4TestCaseOperation1Input) SetListIntegers(v []*int64) *InputService4TestShapeInputService4TestCaseOperation1Input {
s.ListIntegers = v
return s
}
// SetListStrings sets the ListStrings field's value.
func (s *InputService4TestShapeInputService4TestCaseOperation1Input) SetListStrings(v []*string) *InputService4TestShapeInputService4TestCaseOperation1Input {
s.ListStrings = v
return s
}
@@ -724,7 +747,7 @@ const opInputService5TestCaseOperation1 = "OperationName"
// InputService5TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the InputService5TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -869,7 +892,7 @@ const opInputService6TestCaseOperation1 = "OperationName"
// InputService6TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the InputService6TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -1014,7 +1037,7 @@ const opInputService7TestCaseOperation1 = "OperationName"
// InputService7TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the InputService7TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -1160,7 +1183,7 @@ const opInputService8TestCaseOperation1 = "OperationName"
// InputService8TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the InputService8TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -1305,7 +1328,7 @@ const opInputService9TestCaseOperation1 = "OperationName"
// InputService9TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the InputService9TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -1375,7 +1398,7 @@ const opInputService9TestCaseOperation2 = "OperationName"
// InputService9TestCaseOperation2Request generates a "aws/request.Request" representing the
// client's request for the InputService9TestCaseOperation2 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -1461,6 +1484,241 @@ type InputService9TestShapeInputService9TestCaseOperation2Output struct {
_ struct{} `type:"structure"`
}
// InputService10ProtocolTest provides the API operation methods for making requests to
// . See this package's package overview docs
// for details on the service.
//
// InputService10ProtocolTest methods are safe to use concurrently. It is not safe to
// modify mutate any of the struct's properties though.
type InputService10ProtocolTest struct {
*client.Client
}
// New creates a new instance of the InputService10ProtocolTest 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 InputService10ProtocolTest client from just a session.
// svc := inputservice10protocoltest.New(mySession)
//
// // Create a InputService10ProtocolTest client with additional configuration
// svc := inputservice10protocoltest.New(mySession, aws.NewConfig().WithRegion("us-west-2"))
func NewInputService10ProtocolTest(p client.ConfigProvider, cfgs ...*aws.Config) *InputService10ProtocolTest {
c := p.ClientConfig("inputservice10protocoltest", cfgs...)
return newInputService10ProtocolTestClient(*c.Config, c.Handlers, c.Endpoint, c.SigningRegion, c.SigningName)
}
// newClient creates, initializes and returns a new service client instance.
func newInputService10ProtocolTestClient(cfg aws.Config, handlers request.Handlers, endpoint, signingRegion, signingName string) *InputService10ProtocolTest {
svc := &InputService10ProtocolTest{
Client: client.New(
cfg,
metadata.ClientInfo{
ServiceName: "inputservice10protocoltest",
SigningName: signingName,
SigningRegion: signingRegion,
Endpoint: endpoint,
APIVersion: "2014-01-01",
},
handlers,
),
}
// Handlers
svc.Handlers.Sign.PushBackNamed(v4.SignRequestHandler)
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 InputService10ProtocolTest operation and runs any
// custom request initialization.
func (c *InputService10ProtocolTest) newRequest(op *request.Operation, params, data interface{}) *request.Request {
req := c.NewRequest(op, params, data)
return req
}
const opInputService10TestCaseOperation1 = "OperationName"
// InputService10TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the InputService10TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
// the "output" return value is not valid until after Send returns without error.
//
// See InputService10TestCaseOperation1 for more information on using the InputService10TestCaseOperation1
// API call, and error handling.
//
// This method is useful when you want to inject custom logic or configuration
// into the SDK's request lifecycle. Such as custom headers, or retry logic.
//
//
// // Example sending a request using the InputService10TestCaseOperation1Request method.
// req, resp := client.InputService10TestCaseOperation1Request(params)
//
// err := req.Send()
// if err == nil { // resp is now filled
// fmt.Println(resp)
// }
func (c *InputService10ProtocolTest) InputService10TestCaseOperation1Request(input *InputService10TestShapeInputService10TestCaseOperation2Input) (req *request.Request, output *InputService10TestShapeInputService10TestCaseOperation1Output) {
op := &request.Operation{
Name: opInputService10TestCaseOperation1,
HTTPPath: "/",
}
if input == nil {
input = &InputService10TestShapeInputService10TestCaseOperation2Input{}
}
output = &InputService10TestShapeInputService10TestCaseOperation1Output{}
req = c.newRequest(op, input, output)
req.Handlers.Unmarshal.Remove(ec2query.UnmarshalHandler)
req.Handlers.Unmarshal.PushBackNamed(protocol.UnmarshalDiscardBodyHandler)
return
}
// InputService10TestCaseOperation1 API operation for .
//
// Returns awserr.Error for service API and SDK errors. Use runtime type assertions
// with awserr.Error's Code and Message methods to get detailed information about
// the error.
//
// See the AWS API reference guide for 's
// API operation InputService10TestCaseOperation1 for usage and error information.
func (c *InputService10ProtocolTest) InputService10TestCaseOperation1(input *InputService10TestShapeInputService10TestCaseOperation2Input) (*InputService10TestShapeInputService10TestCaseOperation1Output, error) {
req, out := c.InputService10TestCaseOperation1Request(input)
return out, req.Send()
}
// InputService10TestCaseOperation1WithContext is the same as InputService10TestCaseOperation1 with the addition of
// the ability to pass a context and additional request options.
//
// See InputService10TestCaseOperation1 for details on how to use this API operation.
//
// The context must be non-nil and will be used for request cancellation. If
// the context is nil a panic will occur. In the future the SDK may create
// sub-contexts for http.Requests. See https://golang.org/pkg/context/
// for more information on using Contexts.
func (c *InputService10ProtocolTest) InputService10TestCaseOperation1WithContext(ctx aws.Context, input *InputService10TestShapeInputService10TestCaseOperation2Input, opts ...request.Option) (*InputService10TestShapeInputService10TestCaseOperation1Output, error) {
req, out := c.InputService10TestCaseOperation1Request(input)
req.SetContext(ctx)
req.ApplyOptions(opts...)
return out, req.Send()
}
const opInputService10TestCaseOperation2 = "OperationName"
// InputService10TestCaseOperation2Request generates a "aws/request.Request" representing the
// client's request for the InputService10TestCaseOperation2 operation. The "output" return
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
// the "output" return value is not valid until after Send returns without error.
//
// See InputService10TestCaseOperation2 for more information on using the InputService10TestCaseOperation2
// API call, and error handling.
//
// This method is useful when you want to inject custom logic or configuration
// into the SDK's request lifecycle. Such as custom headers, or retry logic.
//
//
// // Example sending a request using the InputService10TestCaseOperation2Request method.
// req, resp := client.InputService10TestCaseOperation2Request(params)
//
// err := req.Send()
// if err == nil { // resp is now filled
// fmt.Println(resp)
// }
func (c *InputService10ProtocolTest) InputService10TestCaseOperation2Request(input *InputService10TestShapeInputService10TestCaseOperation2Input) (req *request.Request, output *InputService10TestShapeInputService10TestCaseOperation2Output) {
op := &request.Operation{
Name: opInputService10TestCaseOperation2,
HTTPPath: "/",
}
if input == nil {
input = &InputService10TestShapeInputService10TestCaseOperation2Input{}
}
output = &InputService10TestShapeInputService10TestCaseOperation2Output{}
req = c.newRequest(op, input, output)
req.Handlers.Unmarshal.Remove(ec2query.UnmarshalHandler)
req.Handlers.Unmarshal.PushBackNamed(protocol.UnmarshalDiscardBodyHandler)
return
}
// InputService10TestCaseOperation2 API operation for .
//
// Returns awserr.Error for service API and SDK errors. Use runtime type assertions
// with awserr.Error's Code and Message methods to get detailed information about
// the error.
//
// See the AWS API reference guide for 's
// API operation InputService10TestCaseOperation2 for usage and error information.
func (c *InputService10ProtocolTest) InputService10TestCaseOperation2(input *InputService10TestShapeInputService10TestCaseOperation2Input) (*InputService10TestShapeInputService10TestCaseOperation2Output, error) {
req, out := c.InputService10TestCaseOperation2Request(input)
return out, req.Send()
}
// InputService10TestCaseOperation2WithContext is the same as InputService10TestCaseOperation2 with the addition of
// the ability to pass a context and additional request options.
//
// See InputService10TestCaseOperation2 for details on how to use this API operation.
//
// The context must be non-nil and will be used for request cancellation. If
// the context is nil a panic will occur. In the future the SDK may create
// sub-contexts for http.Requests. See https://golang.org/pkg/context/
// for more information on using Contexts.
func (c *InputService10ProtocolTest) InputService10TestCaseOperation2WithContext(ctx aws.Context, input *InputService10TestShapeInputService10TestCaseOperation2Input, opts ...request.Option) (*InputService10TestShapeInputService10TestCaseOperation2Output, error) {
req, out := c.InputService10TestCaseOperation2Request(input)
req.SetContext(ctx)
req.ApplyOptions(opts...)
return out, req.Send()
}
type InputService10TestShapeInputService10TestCaseOperation1Output struct {
_ struct{} `type:"structure"`
}
type InputService10TestShapeInputService10TestCaseOperation2Input struct {
_ struct{} `type:"structure"`
FooEnum *string `type:"string" enum:"InputService10TestShapeEnumType"`
ListEnums []*string `type:"list"`
}
// SetFooEnum sets the FooEnum field's value.
func (s *InputService10TestShapeInputService10TestCaseOperation2Input) SetFooEnum(v string) *InputService10TestShapeInputService10TestCaseOperation2Input {
s.FooEnum = &v
return s
}
// SetListEnums sets the ListEnums field's value.
func (s *InputService10TestShapeInputService10TestCaseOperation2Input) SetListEnums(v []*string) *InputService10TestShapeInputService10TestCaseOperation2Input {
s.ListEnums = v
return s
}
type InputService10TestShapeInputService10TestCaseOperation2Output struct {
_ struct{} `type:"structure"`
}
const (
// EnumTypeFoo is a InputService10TestShapeEnumType enum value
EnumTypeFoo = "foo"
// EnumTypeBar is a InputService10TestShapeEnumType enum value
EnumTypeBar = "bar"
)
//
// Tests begin here
//
@@ -1476,10 +1734,14 @@ func TestInputService1ProtocolTestScalarMembersCase1(t *testing.T) {
// build request
ec2query.Build(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert body
assert.NotNil(t, r.Body)
if r.Body == nil {
t.Errorf("expect body not to be nil")
}
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertQuery(t, `Action=OperationName&Bar=val2&Foo=val1&Version=2014-01-01`, util.Trim(string(body)))
@@ -1502,10 +1764,14 @@ func TestInputService2ProtocolTestStructureWithLocationNameAndQueryNameAppliedTo
// build request
ec2query.Build(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert body
assert.NotNil(t, r.Body)
if r.Body == nil {
t.Errorf("expect body not to be nil")
}
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertQuery(t, `Action=OperationName&BarLocationName=val2&Foo=val1&Version=2014-01-01&yuckQueryName=val3`, util.Trim(string(body)))
@@ -1528,10 +1794,14 @@ func TestInputService3ProtocolTestNestedStructureMembersCase1(t *testing.T) {
// build request
ec2query.Build(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert body
assert.NotNil(t, r.Body)
if r.Body == nil {
t.Errorf("expect body not to be nil")
}
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertQuery(t, `Action=OperationName&Struct.Scalar=foo&Version=2014-01-01`, util.Trim(string(body)))
@@ -1545,7 +1815,22 @@ func TestInputService3ProtocolTestNestedStructureMembersCase1(t *testing.T) {
func TestInputService4ProtocolTestListTypesCase1(t *testing.T) {
svc := NewInputService4ProtocolTest(unit.Session, &aws.Config{Endpoint: aws.String("https://test")})
input := &InputService4TestShapeInputService4TestCaseOperation1Input{
ListArg: []*string{
ListBools: []*bool{
aws.Bool(true),
aws.Bool(false),
aws.Bool(false),
},
ListFloats: []*float64{
aws.Float64(1.1),
aws.Float64(2.718),
aws.Float64(3.14),
},
ListIntegers: []*int64{
aws.Int64(0),
aws.Int64(1),
aws.Int64(2),
},
ListStrings: []*string{
aws.String("foo"),
aws.String("bar"),
aws.String("baz"),
@@ -1556,12 +1841,16 @@ func TestInputService4ProtocolTestListTypesCase1(t *testing.T) {
// build request
ec2query.Build(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert body
assert.NotNil(t, r.Body)
if r.Body == nil {
t.Errorf("expect body not to be nil")
}
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertQuery(t, `Action=OperationName&ListArg.1=foo&ListArg.2=bar&ListArg.3=baz&Version=2014-01-01`, util.Trim(string(body)))
awstesting.AssertQuery(t, `Action=OperationName&ListBools.1=true&ListBools.2=false&ListBools.3=false&ListFloats.1=1.1&ListFloats.2=2.718&ListFloats.3=3.14&ListIntegers.1=0&ListIntegers.2=1&ListIntegers.3=2&ListStrings.1=foo&ListStrings.2=bar&ListStrings.3=baz&Version=2014-01-01`, util.Trim(string(body)))
// assert URL
awstesting.AssertURL(t, "https://test/", r.URL.String())
@@ -1584,10 +1873,14 @@ func TestInputService5ProtocolTestListWithLocationNameAppliedToMemberCase1(t *te
// build request
ec2query.Build(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert body
assert.NotNil(t, r.Body)
if r.Body == nil {
t.Errorf("expect body not to be nil")
}
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertQuery(t, `Action=OperationName&ListMemberName.1=a&ListMemberName.2=b&ListMemberName.3=c&Version=2014-01-01`, util.Trim(string(body)))
@@ -1612,10 +1905,14 @@ func TestInputService6ProtocolTestListWithLocationNameAndQueryNameCase1(t *testi
// build request
ec2query.Build(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert body
assert.NotNil(t, r.Body)
if r.Body == nil {
t.Errorf("expect body not to be nil")
}
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertQuery(t, `Action=OperationName&ListQueryName.1=a&ListQueryName.2=b&ListQueryName.3=c&Version=2014-01-01`, util.Trim(string(body)))
@@ -1636,10 +1933,14 @@ func TestInputService7ProtocolTestBase64EncodedBlobsCase1(t *testing.T) {
// build request
ec2query.Build(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert body
assert.NotNil(t, r.Body)
if r.Body == nil {
t.Errorf("expect body not to be nil")
}
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertQuery(t, `Action=OperationName&BlobArg=Zm9v&Version=2014-01-01`, util.Trim(string(body)))
@@ -1660,10 +1961,14 @@ func TestInputService8ProtocolTestTimestampValuesCase1(t *testing.T) {
// build request
ec2query.Build(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert body
assert.NotNil(t, r.Body)
if r.Body == nil {
t.Errorf("expect body not to be nil")
}
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertQuery(t, `Action=OperationName&TimeArg=2015-01-25T08%3A00%3A00Z&Version=2014-01-01`, util.Trim(string(body)))
@@ -1684,10 +1989,14 @@ func TestInputService9ProtocolTestIdempotencyTokenAutoFillCase1(t *testing.T) {
// build request
ec2query.Build(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert body
assert.NotNil(t, r.Body)
if r.Body == nil {
t.Errorf("expect body not to be nil")
}
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertQuery(t, `Action=OperationName&Token=abc123&Version=2014-01-01`, util.Trim(string(body)))
@@ -1706,10 +2015,14 @@ func TestInputService9ProtocolTestIdempotencyTokenAutoFillCase2(t *testing.T) {
// build request
ec2query.Build(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert body
assert.NotNil(t, r.Body)
if r.Body == nil {
t.Errorf("expect body not to be nil")
}
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertQuery(t, `Action=OperationName&Token=00000000-0000-4000-8000-000000000000&Version=2014-01-01`, util.Trim(string(body)))
@@ -1719,3 +2032,61 @@ func TestInputService9ProtocolTestIdempotencyTokenAutoFillCase2(t *testing.T) {
// assert headers
}
func TestInputService10ProtocolTestEnumCase1(t *testing.T) {
svc := NewInputService10ProtocolTest(unit.Session, &aws.Config{Endpoint: aws.String("https://test")})
input := &InputService10TestShapeInputService10TestCaseOperation2Input{
ListEnums: []*string{
aws.String("foo"),
aws.String(""),
aws.String("bar"),
},
}
req, _ := svc.InputService10TestCaseOperation1Request(input)
r := req.HTTPRequest
// build request
ec2query.Build(req)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert body
if r.Body == nil {
t.Errorf("expect body not to be nil")
}
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertQuery(t, `Action=OperationName&ListEnums.1=foo&ListEnums.2=&ListEnums.3=bar&Version=2014-01-01`, util.Trim(string(body)))
// assert URL
awstesting.AssertURL(t, "https://test/", r.URL.String())
// assert headers
}
func TestInputService10ProtocolTestEnumCase2(t *testing.T) {
svc := NewInputService10ProtocolTest(unit.Session, &aws.Config{Endpoint: aws.String("https://test")})
input := &InputService10TestShapeInputService10TestCaseOperation2Input{}
req, _ := svc.InputService10TestCaseOperation2Request(input)
r := req.HTTPRequest
// build request
ec2query.Build(req)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert body
if r.Body == nil {
t.Errorf("expect body not to be nil")
}
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertQuery(t, `Action=OperationName&Version=2014-01-01`, util.Trim(string(body)))
// assert URL
awstesting.AssertURL(t, "https://test/", r.URL.String())
// assert headers
}
+320 -50
View File
@@ -24,7 +24,6 @@ import (
"github.com/aws/aws-sdk-go/private/protocol/ec2query"
"github.com/aws/aws-sdk-go/private/protocol/xml/xmlutil"
"github.com/aws/aws-sdk-go/private/util"
"github.com/stretchr/testify/assert"
)
var _ bytes.Buffer // always import bytes
@@ -108,7 +107,7 @@ const opOutputService1TestCaseOperation1 = "OperationName"
// OutputService1TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService1TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -307,7 +306,7 @@ const opOutputService2TestCaseOperation1 = "OperationName"
// OutputService2TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService2TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -451,7 +450,7 @@ const opOutputService3TestCaseOperation1 = "OperationName"
// OutputService3TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService3TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -594,7 +593,7 @@ const opOutputService4TestCaseOperation1 = "OperationName"
// OutputService4TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService4TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -737,7 +736,7 @@ const opOutputService5TestCaseOperation1 = "OperationName"
// OutputService5TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService5TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -880,7 +879,7 @@ const opOutputService6TestCaseOperation1 = "OperationName"
// OutputService6TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService6TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -1035,7 +1034,7 @@ const opOutputService7TestCaseOperation1 = "OperationName"
// OutputService7TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService7TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -1178,7 +1177,7 @@ const opOutputService8TestCaseOperation1 = "OperationName"
// OutputService8TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService8TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -1321,7 +1320,7 @@ const opOutputService9TestCaseOperation1 = "OperationName"
// OutputService9TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService9TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -1401,6 +1400,165 @@ func (s *OutputService9TestShapeOutputService9TestCaseOperation1Output) SetFoo(v
return s
}
// OutputService10ProtocolTest provides the API operation methods for making requests to
// . See this package's package overview docs
// for details on the service.
//
// OutputService10ProtocolTest methods are safe to use concurrently. It is not safe to
// modify mutate any of the struct's properties though.
type OutputService10ProtocolTest struct {
*client.Client
}
// New creates a new instance of the OutputService10ProtocolTest 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 OutputService10ProtocolTest client from just a session.
// svc := outputservice10protocoltest.New(mySession)
//
// // Create a OutputService10ProtocolTest client with additional configuration
// svc := outputservice10protocoltest.New(mySession, aws.NewConfig().WithRegion("us-west-2"))
func NewOutputService10ProtocolTest(p client.ConfigProvider, cfgs ...*aws.Config) *OutputService10ProtocolTest {
c := p.ClientConfig("outputservice10protocoltest", cfgs...)
return newOutputService10ProtocolTestClient(*c.Config, c.Handlers, c.Endpoint, c.SigningRegion, c.SigningName)
}
// newClient creates, initializes and returns a new service client instance.
func newOutputService10ProtocolTestClient(cfg aws.Config, handlers request.Handlers, endpoint, signingRegion, signingName string) *OutputService10ProtocolTest {
svc := &OutputService10ProtocolTest{
Client: client.New(
cfg,
metadata.ClientInfo{
ServiceName: "outputservice10protocoltest",
SigningName: signingName,
SigningRegion: signingRegion,
Endpoint: endpoint,
APIVersion: "",
},
handlers,
),
}
// Handlers
svc.Handlers.Sign.PushBackNamed(v4.SignRequestHandler)
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 OutputService10ProtocolTest operation and runs any
// custom request initialization.
func (c *OutputService10ProtocolTest) newRequest(op *request.Operation, params, data interface{}) *request.Request {
req := c.NewRequest(op, params, data)
return req
}
const opOutputService10TestCaseOperation1 = "OperationName"
// OutputService10TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService10TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
// the "output" return value is not valid until after Send returns without error.
//
// See OutputService10TestCaseOperation1 for more information on using the OutputService10TestCaseOperation1
// API call, and error handling.
//
// This method is useful when you want to inject custom logic or configuration
// into the SDK's request lifecycle. Such as custom headers, or retry logic.
//
//
// // Example sending a request using the OutputService10TestCaseOperation1Request method.
// req, resp := client.OutputService10TestCaseOperation1Request(params)
//
// err := req.Send()
// if err == nil { // resp is now filled
// fmt.Println(resp)
// }
func (c *OutputService10ProtocolTest) OutputService10TestCaseOperation1Request(input *OutputService10TestShapeOutputService10TestCaseOperation1Input) (req *request.Request, output *OutputService10TestShapeOutputService10TestCaseOperation1Output) {
op := &request.Operation{
Name: opOutputService10TestCaseOperation1,
HTTPPath: "/",
}
if input == nil {
input = &OutputService10TestShapeOutputService10TestCaseOperation1Input{}
}
output = &OutputService10TestShapeOutputService10TestCaseOperation1Output{}
req = c.newRequest(op, input, output)
return
}
// OutputService10TestCaseOperation1 API operation for .
//
// Returns awserr.Error for service API and SDK errors. Use runtime type assertions
// with awserr.Error's Code and Message methods to get detailed information about
// the error.
//
// See the AWS API reference guide for 's
// API operation OutputService10TestCaseOperation1 for usage and error information.
func (c *OutputService10ProtocolTest) OutputService10TestCaseOperation1(input *OutputService10TestShapeOutputService10TestCaseOperation1Input) (*OutputService10TestShapeOutputService10TestCaseOperation1Output, error) {
req, out := c.OutputService10TestCaseOperation1Request(input)
return out, req.Send()
}
// OutputService10TestCaseOperation1WithContext is the same as OutputService10TestCaseOperation1 with the addition of
// the ability to pass a context and additional request options.
//
// See OutputService10TestCaseOperation1 for details on how to use this API operation.
//
// The context must be non-nil and will be used for request cancellation. If
// the context is nil a panic will occur. In the future the SDK may create
// sub-contexts for http.Requests. See https://golang.org/pkg/context/
// for more information on using Contexts.
func (c *OutputService10ProtocolTest) OutputService10TestCaseOperation1WithContext(ctx aws.Context, input *OutputService10TestShapeOutputService10TestCaseOperation1Input, opts ...request.Option) (*OutputService10TestShapeOutputService10TestCaseOperation1Output, error) {
req, out := c.OutputService10TestCaseOperation1Request(input)
req.SetContext(ctx)
req.ApplyOptions(opts...)
return out, req.Send()
}
type OutputService10TestShapeOutputService10TestCaseOperation1Input struct {
_ struct{} `type:"structure"`
}
type OutputService10TestShapeOutputService10TestCaseOperation1Output struct {
_ struct{} `type:"structure"`
FooEnum *string `type:"string" enum:"OutputService10TestShapeEC2EnumType"`
ListEnums []*string `type:"list"`
}
// SetFooEnum sets the FooEnum field's value.
func (s *OutputService10TestShapeOutputService10TestCaseOperation1Output) SetFooEnum(v string) *OutputService10TestShapeOutputService10TestCaseOperation1Output {
s.FooEnum = &v
return s
}
// SetListEnums sets the ListEnums field's value.
func (s *OutputService10TestShapeOutputService10TestCaseOperation1Output) SetListEnums(v []*string) *OutputService10TestShapeOutputService10TestCaseOperation1Output {
s.ListEnums = v
return s
}
const (
// EC2EnumTypeFoo is a OutputService10TestShapeEC2EnumType enum value
EC2EnumTypeFoo = "foo"
// EC2EnumTypeBar is a OutputService10TestShapeEC2EnumType enum value
EC2EnumTypeBar = "bar"
)
//
// Tests begin here
//
@@ -1417,18 +1575,38 @@ func TestOutputService1ProtocolTestScalarMembersCase1(t *testing.T) {
// unmarshal response
ec2query.UnmarshalMeta(req)
ec2query.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "a", *out.Char)
assert.Equal(t, 1.3, *out.Double)
assert.Equal(t, false, *out.FalseBool)
assert.Equal(t, 1.2, *out.Float)
assert.Equal(t, int64(200), *out.Long)
assert.Equal(t, int64(123), *out.Num)
assert.Equal(t, "myname", *out.Str)
assert.Equal(t, true, *out.TrueBool)
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "a", *out.Char; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := 1.3, *out.Double; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := false, *out.FalseBool; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := 1.2, *out.Float; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := int64(200), *out.Long; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := int64(123), *out.Num; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "myname", *out.Str; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := true, *out.TrueBool; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -1444,11 +1622,17 @@ func TestOutputService2ProtocolTestBlobCase1(t *testing.T) {
// unmarshal response
ec2query.UnmarshalMeta(req)
ec2query.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "value", string(out.Blob))
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "value", string(out.Blob); e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -1464,12 +1648,20 @@ func TestOutputService3ProtocolTestListsCase1(t *testing.T) {
// unmarshal response
ec2query.UnmarshalMeta(req)
ec2query.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "abc", *out.ListMember[0])
assert.Equal(t, "123", *out.ListMember[1])
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "abc", *out.ListMember[0]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "123", *out.ListMember[1]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -1485,12 +1677,20 @@ func TestOutputService4ProtocolTestListWithCustomMemberNameCase1(t *testing.T) {
// unmarshal response
ec2query.UnmarshalMeta(req)
ec2query.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "abc", *out.ListMember[0])
assert.Equal(t, "123", *out.ListMember[1])
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "abc", *out.ListMember[0]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "123", *out.ListMember[1]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -1506,12 +1706,20 @@ func TestOutputService5ProtocolTestFlattenedListCase1(t *testing.T) {
// unmarshal response
ec2query.UnmarshalMeta(req)
ec2query.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "abc", *out.ListMember[0])
assert.Equal(t, "123", *out.ListMember[1])
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "abc", *out.ListMember[0]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "123", *out.ListMember[1]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -1527,12 +1735,20 @@ func TestOutputService6ProtocolTestNormalMapCase1(t *testing.T) {
// unmarshal response
ec2query.UnmarshalMeta(req)
ec2query.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "bam", *out.Map["baz"].Foo)
assert.Equal(t, "bar", *out.Map["qux"].Foo)
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "bam", *out.Map["baz"].Foo; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "bar", *out.Map["qux"].Foo; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -1548,12 +1764,20 @@ func TestOutputService7ProtocolTestFlattenedMapCase1(t *testing.T) {
// unmarshal response
ec2query.UnmarshalMeta(req)
ec2query.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "bam", *out.Map["baz"])
assert.Equal(t, "bar", *out.Map["qux"])
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "bam", *out.Map["baz"]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "bar", *out.Map["qux"]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -1569,12 +1793,20 @@ func TestOutputService8ProtocolTestNamedMapCase1(t *testing.T) {
// unmarshal response
ec2query.UnmarshalMeta(req)
ec2query.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "bam", *out.Map["baz"])
assert.Equal(t, "bar", *out.Map["qux"])
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "bam", *out.Map["baz"]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "bar", *out.Map["qux"]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -1590,10 +1822,48 @@ func TestOutputService9ProtocolTestEmptyStringCase1(t *testing.T) {
// unmarshal response
ec2query.UnmarshalMeta(req)
ec2query.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "", *out.Foo)
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "", *out.Foo; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
func TestOutputService10ProtocolTestEnumOutputCase1(t *testing.T) {
svc := NewOutputService10ProtocolTest(unit.Session, &aws.Config{Endpoint: aws.String("https://test")})
buf := bytes.NewReader([]byte("<OperationNameResponse><FooEnum>foo</FooEnum><ListEnums><member>foo</member><member>bar</member></ListEnums></OperationNameResponse>"))
req, out := svc.OutputService10TestCaseOperation1Request(nil)
req.HTTPResponse = &http.Response{StatusCode: 200, Body: ioutil.NopCloser(buf), Header: http.Header{}}
// set headers
// unmarshal response
ec2query.UnmarshalMeta(req)
ec2query.Unmarshal(req)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "foo", *out.FooEnum; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "foo", *out.ListEnums[0]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "bar", *out.ListEnums[1]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
+14 -7
View File
@@ -12,6 +12,7 @@ import (
"strconv"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/private/protocol"
)
@@ -49,7 +50,10 @@ func buildAny(value reflect.Value, buf *bytes.Buffer, tag reflect.StructTag) err
t = "list"
}
case reflect.Map:
t = "map"
// cannot be a JSONValue map
if _, ok := value.Interface().(aws.JSONValue); !ok {
t = "map"
}
}
}
@@ -210,14 +214,11 @@ func buildScalar(v reflect.Value, buf *bytes.Buffer, tag reflect.StructTag) erro
}
buf.Write(strconv.AppendFloat(scratch[:0], f, 'f', -1, 64))
default:
switch value.Type() {
case timeType:
converted := v.Interface().(*time.Time)
switch converted := value.Interface().(type) {
case time.Time:
buf.Write(strconv.AppendInt(scratch[:0], converted.UTC().Unix(), 10))
case byteSliceType:
case []byte:
if !value.IsNil() {
converted := value.Interface().([]byte)
buf.WriteByte('"')
if len(converted) < 1024 {
// for small buffers, using Encode directly is much faster.
@@ -233,6 +234,12 @@ func buildScalar(v reflect.Value, buf *bytes.Buffer, tag reflect.StructTag) erro
}
buf.WriteByte('"')
}
case aws.JSONValue:
str, err := protocol.EncodeJSONValue(converted, protocol.QuotedEscape)
if err != nil {
return fmt.Errorf("unable to encode JSONValue, %v", err)
}
buf.WriteString(str)
default:
return fmt.Errorf("unsupported JSON value %v (%s)", value.Interface(), value.Type())
}
@@ -8,6 +8,9 @@ import (
"io/ioutil"
"reflect"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/private/protocol"
)
// UnmarshalJSON reads a stream and unmarshals the results in object v.
@@ -50,7 +53,10 @@ func unmarshalAny(value reflect.Value, data interface{}, tag reflect.StructTag)
t = "list"
}
case reflect.Map:
t = "map"
// cannot be a JSONValue map
if _, ok := value.Interface().(aws.JSONValue); !ok {
t = "map"
}
}
}
@@ -183,6 +189,13 @@ func unmarshalScalar(value reflect.Value, data interface{}, tag reflect.StructTa
return err
}
value.Set(reflect.ValueOf(b))
case aws.JSONValue:
// No need to use escaping as the value is a non-quoted string.
v, err := protocol.DecodeJSONValue(d, protocol.NoEscape)
if err != nil {
return err
}
value.Set(reflect.ValueOf(v))
default:
return errf()
}
+459 -67
View File
@@ -24,7 +24,6 @@ import (
"github.com/aws/aws-sdk-go/private/protocol/jsonrpc"
"github.com/aws/aws-sdk-go/private/protocol/xml/xmlutil"
"github.com/aws/aws-sdk-go/private/util"
"github.com/stretchr/testify/assert"
)
var _ bytes.Buffer // always import bytes
@@ -110,7 +109,7 @@ const opInputService1TestCaseOperation1 = "OperationName"
// InputService1TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the InputService1TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -258,7 +257,7 @@ const opInputService2TestCaseOperation1 = "OperationName"
// InputService2TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the InputService2TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -405,7 +404,7 @@ const opInputService3TestCaseOperation1 = "OperationName"
// InputService3TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the InputService3TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -475,7 +474,7 @@ const opInputService3TestCaseOperation2 = "OperationName"
// InputService3TestCaseOperation2Request generates a "aws/request.Request" representing the
// client's request for the InputService3TestCaseOperation2 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -635,7 +634,7 @@ const opInputService4TestCaseOperation1 = "OperationName"
// InputService4TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the InputService4TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -783,7 +782,7 @@ const opInputService5TestCaseOperation1 = "OperationName"
// InputService5TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the InputService5TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -853,7 +852,7 @@ const opInputService5TestCaseOperation2 = "OperationName"
// InputService5TestCaseOperation2Request generates a "aws/request.Request" representing the
// client's request for the InputService5TestCaseOperation2 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -923,7 +922,7 @@ const opInputService5TestCaseOperation3 = "OperationName"
// InputService5TestCaseOperation3Request generates a "aws/request.Request" representing the
// client's request for the InputService5TestCaseOperation3 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -993,7 +992,7 @@ const opInputService5TestCaseOperation4 = "OperationName"
// InputService5TestCaseOperation4Request generates a "aws/request.Request" representing the
// client's request for the InputService5TestCaseOperation4 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -1063,7 +1062,7 @@ const opInputService5TestCaseOperation5 = "OperationName"
// InputService5TestCaseOperation5Request generates a "aws/request.Request" representing the
// client's request for the InputService5TestCaseOperation5 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -1133,7 +1132,7 @@ const opInputService5TestCaseOperation6 = "OperationName"
// InputService5TestCaseOperation6Request generates a "aws/request.Request" representing the
// client's request for the InputService5TestCaseOperation6 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -1336,7 +1335,7 @@ const opInputService6TestCaseOperation1 = "OperationName"
// InputService6TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the InputService6TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -1482,7 +1481,7 @@ const opInputService7TestCaseOperation1 = "OperationName"
// InputService7TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the InputService7TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -1553,7 +1552,7 @@ const opInputService7TestCaseOperation2 = "OperationName"
// InputService7TestCaseOperation2Request generates a "aws/request.Request" representing the
// client's request for the InputService7TestCaseOperation2 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -1640,6 +1639,243 @@ type InputService7TestShapeInputService7TestCaseOperation2Output struct {
_ struct{} `type:"structure"`
}
// InputService8ProtocolTest provides the API operation methods for making requests to
// . See this package's package overview docs
// for details on the service.
//
// InputService8ProtocolTest methods are safe to use concurrently. It is not safe to
// modify mutate any of the struct's properties though.
type InputService8ProtocolTest struct {
*client.Client
}
// New creates a new instance of the InputService8ProtocolTest 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 InputService8ProtocolTest client from just a session.
// svc := inputservice8protocoltest.New(mySession)
//
// // Create a InputService8ProtocolTest client with additional configuration
// svc := inputservice8protocoltest.New(mySession, aws.NewConfig().WithRegion("us-west-2"))
func NewInputService8ProtocolTest(p client.ConfigProvider, cfgs ...*aws.Config) *InputService8ProtocolTest {
c := p.ClientConfig("inputservice8protocoltest", cfgs...)
return newInputService8ProtocolTestClient(*c.Config, c.Handlers, c.Endpoint, c.SigningRegion, c.SigningName)
}
// newClient creates, initializes and returns a new service client instance.
func newInputService8ProtocolTestClient(cfg aws.Config, handlers request.Handlers, endpoint, signingRegion, signingName string) *InputService8ProtocolTest {
svc := &InputService8ProtocolTest{
Client: client.New(
cfg,
metadata.ClientInfo{
ServiceName: "inputservice8protocoltest",
SigningName: signingName,
SigningRegion: signingRegion,
Endpoint: endpoint,
APIVersion: "2014-01-01",
},
handlers,
),
}
// Handlers
svc.Handlers.Sign.PushBackNamed(v4.SignRequestHandler)
svc.Handlers.Build.PushBackNamed(jsonrpc.BuildHandler)
svc.Handlers.Unmarshal.PushBackNamed(jsonrpc.UnmarshalHandler)
svc.Handlers.UnmarshalMeta.PushBackNamed(jsonrpc.UnmarshalMetaHandler)
svc.Handlers.UnmarshalError.PushBackNamed(jsonrpc.UnmarshalErrorHandler)
return svc
}
// newRequest creates a new request for a InputService8ProtocolTest operation and runs any
// custom request initialization.
func (c *InputService8ProtocolTest) newRequest(op *request.Operation, params, data interface{}) *request.Request {
req := c.NewRequest(op, params, data)
return req
}
const opInputService8TestCaseOperation1 = "OperationName"
// InputService8TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the InputService8TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
// the "output" return value is not valid until after Send returns without error.
//
// See InputService8TestCaseOperation1 for more information on using the InputService8TestCaseOperation1
// API call, and error handling.
//
// This method is useful when you want to inject custom logic or configuration
// into the SDK's request lifecycle. Such as custom headers, or retry logic.
//
//
// // Example sending a request using the InputService8TestCaseOperation1Request method.
// req, resp := client.InputService8TestCaseOperation1Request(params)
//
// err := req.Send()
// if err == nil { // resp is now filled
// fmt.Println(resp)
// }
func (c *InputService8ProtocolTest) InputService8TestCaseOperation1Request(input *InputService8TestShapeInputService8TestCaseOperation2Input) (req *request.Request, output *InputService8TestShapeInputService8TestCaseOperation1Output) {
op := &request.Operation{
Name: opInputService8TestCaseOperation1,
HTTPMethod: "POST",
HTTPPath: "/",
}
if input == nil {
input = &InputService8TestShapeInputService8TestCaseOperation2Input{}
}
output = &InputService8TestShapeInputService8TestCaseOperation1Output{}
req = c.newRequest(op, input, output)
req.Handlers.Unmarshal.Remove(jsonrpc.UnmarshalHandler)
req.Handlers.Unmarshal.PushBackNamed(protocol.UnmarshalDiscardBodyHandler)
return
}
// InputService8TestCaseOperation1 API operation for .
//
// Returns awserr.Error for service API and SDK errors. Use runtime type assertions
// with awserr.Error's Code and Message methods to get detailed information about
// the error.
//
// See the AWS API reference guide for 's
// API operation InputService8TestCaseOperation1 for usage and error information.
func (c *InputService8ProtocolTest) InputService8TestCaseOperation1(input *InputService8TestShapeInputService8TestCaseOperation2Input) (*InputService8TestShapeInputService8TestCaseOperation1Output, error) {
req, out := c.InputService8TestCaseOperation1Request(input)
return out, req.Send()
}
// InputService8TestCaseOperation1WithContext is the same as InputService8TestCaseOperation1 with the addition of
// the ability to pass a context and additional request options.
//
// See InputService8TestCaseOperation1 for details on how to use this API operation.
//
// The context must be non-nil and will be used for request cancellation. If
// the context is nil a panic will occur. In the future the SDK may create
// sub-contexts for http.Requests. See https://golang.org/pkg/context/
// for more information on using Contexts.
func (c *InputService8ProtocolTest) InputService8TestCaseOperation1WithContext(ctx aws.Context, input *InputService8TestShapeInputService8TestCaseOperation2Input, opts ...request.Option) (*InputService8TestShapeInputService8TestCaseOperation1Output, error) {
req, out := c.InputService8TestCaseOperation1Request(input)
req.SetContext(ctx)
req.ApplyOptions(opts...)
return out, req.Send()
}
const opInputService8TestCaseOperation2 = "OperationName"
// InputService8TestCaseOperation2Request generates a "aws/request.Request" representing the
// client's request for the InputService8TestCaseOperation2 operation. The "output" return
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
// the "output" return value is not valid until after Send returns without error.
//
// See InputService8TestCaseOperation2 for more information on using the InputService8TestCaseOperation2
// API call, and error handling.
//
// This method is useful when you want to inject custom logic or configuration
// into the SDK's request lifecycle. Such as custom headers, or retry logic.
//
//
// // Example sending a request using the InputService8TestCaseOperation2Request method.
// req, resp := client.InputService8TestCaseOperation2Request(params)
//
// err := req.Send()
// if err == nil { // resp is now filled
// fmt.Println(resp)
// }
func (c *InputService8ProtocolTest) InputService8TestCaseOperation2Request(input *InputService8TestShapeInputService8TestCaseOperation2Input) (req *request.Request, output *InputService8TestShapeInputService8TestCaseOperation2Output) {
op := &request.Operation{
Name: opInputService8TestCaseOperation2,
HTTPMethod: "POST",
HTTPPath: "/",
}
if input == nil {
input = &InputService8TestShapeInputService8TestCaseOperation2Input{}
}
output = &InputService8TestShapeInputService8TestCaseOperation2Output{}
req = c.newRequest(op, input, output)
req.Handlers.Unmarshal.Remove(jsonrpc.UnmarshalHandler)
req.Handlers.Unmarshal.PushBackNamed(protocol.UnmarshalDiscardBodyHandler)
return
}
// InputService8TestCaseOperation2 API operation for .
//
// Returns awserr.Error for service API and SDK errors. Use runtime type assertions
// with awserr.Error's Code and Message methods to get detailed information about
// the error.
//
// See the AWS API reference guide for 's
// API operation InputService8TestCaseOperation2 for usage and error information.
func (c *InputService8ProtocolTest) InputService8TestCaseOperation2(input *InputService8TestShapeInputService8TestCaseOperation2Input) (*InputService8TestShapeInputService8TestCaseOperation2Output, error) {
req, out := c.InputService8TestCaseOperation2Request(input)
return out, req.Send()
}
// InputService8TestCaseOperation2WithContext is the same as InputService8TestCaseOperation2 with the addition of
// the ability to pass a context and additional request options.
//
// See InputService8TestCaseOperation2 for details on how to use this API operation.
//
// The context must be non-nil and will be used for request cancellation. If
// the context is nil a panic will occur. In the future the SDK may create
// sub-contexts for http.Requests. See https://golang.org/pkg/context/
// for more information on using Contexts.
func (c *InputService8ProtocolTest) InputService8TestCaseOperation2WithContext(ctx aws.Context, input *InputService8TestShapeInputService8TestCaseOperation2Input, opts ...request.Option) (*InputService8TestShapeInputService8TestCaseOperation2Output, error) {
req, out := c.InputService8TestCaseOperation2Request(input)
req.SetContext(ctx)
req.ApplyOptions(opts...)
return out, req.Send()
}
type InputService8TestShapeInputService8TestCaseOperation1Output struct {
_ struct{} `type:"structure"`
}
type InputService8TestShapeInputService8TestCaseOperation2Input struct {
_ struct{} `type:"structure"`
FooEnum *string `type:"string" enum:"InputService8TestShapeEnumType"`
ListEnums []*string `type:"list"`
}
// SetFooEnum sets the FooEnum field's value.
func (s *InputService8TestShapeInputService8TestCaseOperation2Input) SetFooEnum(v string) *InputService8TestShapeInputService8TestCaseOperation2Input {
s.FooEnum = &v
return s
}
// SetListEnums sets the ListEnums field's value.
func (s *InputService8TestShapeInputService8TestCaseOperation2Input) SetListEnums(v []*string) *InputService8TestShapeInputService8TestCaseOperation2Input {
s.ListEnums = v
return s
}
type InputService8TestShapeInputService8TestCaseOperation2Output struct {
_ struct{} `type:"structure"`
}
const (
// EnumTypeFoo is a InputService8TestShapeEnumType enum value
EnumTypeFoo = "foo"
// EnumTypeBar is a InputService8TestShapeEnumType enum value
EnumTypeBar = "bar"
)
//
// Tests begin here
//
@@ -1654,10 +1890,14 @@ func TestInputService1ProtocolTestScalarMembersCase1(t *testing.T) {
// build request
jsonrpc.Build(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert body
assert.NotNil(t, r.Body)
if r.Body == nil {
t.Errorf("expect body not to be nil")
}
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertJSON(t, `{"Name":"myname"}`, util.Trim(string(body)))
@@ -1665,8 +1905,12 @@ func TestInputService1ProtocolTestScalarMembersCase1(t *testing.T) {
awstesting.AssertURL(t, "https://test/", r.URL.String())
// assert headers
assert.Equal(t, "application/x-amz-json-1.1", r.Header.Get("Content-Type"))
assert.Equal(t, "com.amazonaws.foo.OperationName", r.Header.Get("X-Amz-Target"))
if e, a := "application/x-amz-json-1.1", r.Header.Get("Content-Type"); e != a {
t.Errorf("expect %v to be %v", e, a)
}
if e, a := "com.amazonaws.foo.OperationName", r.Header.Get("X-Amz-Target"); e != a {
t.Errorf("expect %v to be %v", e, a)
}
}
@@ -1680,10 +1924,14 @@ func TestInputService2ProtocolTestTimestampValuesCase1(t *testing.T) {
// build request
jsonrpc.Build(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert body
assert.NotNil(t, r.Body)
if r.Body == nil {
t.Errorf("expect body not to be nil")
}
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertJSON(t, `{"TimeArg":1422172800}`, util.Trim(string(body)))
@@ -1691,8 +1939,12 @@ func TestInputService2ProtocolTestTimestampValuesCase1(t *testing.T) {
awstesting.AssertURL(t, "https://test/", r.URL.String())
// assert headers
assert.Equal(t, "application/x-amz-json-1.1", r.Header.Get("Content-Type"))
assert.Equal(t, "com.amazonaws.foo.OperationName", r.Header.Get("X-Amz-Target"))
if e, a := "application/x-amz-json-1.1", r.Header.Get("Content-Type"); e != a {
t.Errorf("expect %v to be %v", e, a)
}
if e, a := "com.amazonaws.foo.OperationName", r.Header.Get("X-Amz-Target"); e != a {
t.Errorf("expect %v to be %v", e, a)
}
}
@@ -1706,10 +1958,14 @@ func TestInputService3ProtocolTestBase64EncodedBlobsCase1(t *testing.T) {
// build request
jsonrpc.Build(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert body
assert.NotNil(t, r.Body)
if r.Body == nil {
t.Errorf("expect body not to be nil")
}
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertJSON(t, `{"BlobArg":"Zm9v"}`, util.Trim(string(body)))
@@ -1717,8 +1973,12 @@ func TestInputService3ProtocolTestBase64EncodedBlobsCase1(t *testing.T) {
awstesting.AssertURL(t, "https://test/", r.URL.String())
// assert headers
assert.Equal(t, "application/x-amz-json-1.1", r.Header.Get("Content-Type"))
assert.Equal(t, "com.amazonaws.foo.OperationName", r.Header.Get("X-Amz-Target"))
if e, a := "application/x-amz-json-1.1", r.Header.Get("Content-Type"); e != a {
t.Errorf("expect %v to be %v", e, a)
}
if e, a := "com.amazonaws.foo.OperationName", r.Header.Get("X-Amz-Target"); e != a {
t.Errorf("expect %v to be %v", e, a)
}
}
@@ -1735,10 +1995,14 @@ func TestInputService3ProtocolTestBase64EncodedBlobsCase2(t *testing.T) {
// build request
jsonrpc.Build(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert body
assert.NotNil(t, r.Body)
if r.Body == nil {
t.Errorf("expect body not to be nil")
}
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertJSON(t, `{"BlobMap":{"key1":"Zm9v","key2":"YmFy"}}`, util.Trim(string(body)))
@@ -1746,8 +2010,12 @@ func TestInputService3ProtocolTestBase64EncodedBlobsCase2(t *testing.T) {
awstesting.AssertURL(t, "https://test/", r.URL.String())
// assert headers
assert.Equal(t, "application/x-amz-json-1.1", r.Header.Get("Content-Type"))
assert.Equal(t, "com.amazonaws.foo.OperationName", r.Header.Get("X-Amz-Target"))
if e, a := "application/x-amz-json-1.1", r.Header.Get("Content-Type"); e != a {
t.Errorf("expect %v to be %v", e, a)
}
if e, a := "com.amazonaws.foo.OperationName", r.Header.Get("X-Amz-Target"); e != a {
t.Errorf("expect %v to be %v", e, a)
}
}
@@ -1764,10 +2032,14 @@ func TestInputService4ProtocolTestNestedBlobsCase1(t *testing.T) {
// build request
jsonrpc.Build(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert body
assert.NotNil(t, r.Body)
if r.Body == nil {
t.Errorf("expect body not to be nil")
}
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertJSON(t, `{"ListParam":["Zm9v","YmFy"]}`, util.Trim(string(body)))
@@ -1775,8 +2047,12 @@ func TestInputService4ProtocolTestNestedBlobsCase1(t *testing.T) {
awstesting.AssertURL(t, "https://test/", r.URL.String())
// assert headers
assert.Equal(t, "application/x-amz-json-1.1", r.Header.Get("Content-Type"))
assert.Equal(t, "com.amazonaws.foo.OperationName", r.Header.Get("X-Amz-Target"))
if e, a := "application/x-amz-json-1.1", r.Header.Get("Content-Type"); e != a {
t.Errorf("expect %v to be %v", e, a)
}
if e, a := "com.amazonaws.foo.OperationName", r.Header.Get("X-Amz-Target"); e != a {
t.Errorf("expect %v to be %v", e, a)
}
}
@@ -1792,10 +2068,14 @@ func TestInputService5ProtocolTestRecursiveShapesCase1(t *testing.T) {
// build request
jsonrpc.Build(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert body
assert.NotNil(t, r.Body)
if r.Body == nil {
t.Errorf("expect body not to be nil")
}
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertJSON(t, `{"RecursiveStruct":{"NoRecurse":"foo"}}`, util.Trim(string(body)))
@@ -1803,8 +2083,12 @@ func TestInputService5ProtocolTestRecursiveShapesCase1(t *testing.T) {
awstesting.AssertURL(t, "https://test/", r.URL.String())
// assert headers
assert.Equal(t, "application/x-amz-json-1.1", r.Header.Get("Content-Type"))
assert.Equal(t, "com.amazonaws.foo.OperationName", r.Header.Get("X-Amz-Target"))
if e, a := "application/x-amz-json-1.1", r.Header.Get("Content-Type"); e != a {
t.Errorf("expect %v to be %v", e, a)
}
if e, a := "com.amazonaws.foo.OperationName", r.Header.Get("X-Amz-Target"); e != a {
t.Errorf("expect %v to be %v", e, a)
}
}
@@ -1822,10 +2106,14 @@ func TestInputService5ProtocolTestRecursiveShapesCase2(t *testing.T) {
// build request
jsonrpc.Build(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert body
assert.NotNil(t, r.Body)
if r.Body == nil {
t.Errorf("expect body not to be nil")
}
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertJSON(t, `{"RecursiveStruct":{"RecursiveStruct":{"NoRecurse":"foo"}}}`, util.Trim(string(body)))
@@ -1833,8 +2121,12 @@ func TestInputService5ProtocolTestRecursiveShapesCase2(t *testing.T) {
awstesting.AssertURL(t, "https://test/", r.URL.String())
// assert headers
assert.Equal(t, "application/x-amz-json-1.1", r.Header.Get("Content-Type"))
assert.Equal(t, "com.amazonaws.foo.OperationName", r.Header.Get("X-Amz-Target"))
if e, a := "application/x-amz-json-1.1", r.Header.Get("Content-Type"); e != a {
t.Errorf("expect %v to be %v", e, a)
}
if e, a := "com.amazonaws.foo.OperationName", r.Header.Get("X-Amz-Target"); e != a {
t.Errorf("expect %v to be %v", e, a)
}
}
@@ -1856,10 +2148,14 @@ func TestInputService5ProtocolTestRecursiveShapesCase3(t *testing.T) {
// build request
jsonrpc.Build(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert body
assert.NotNil(t, r.Body)
if r.Body == nil {
t.Errorf("expect body not to be nil")
}
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertJSON(t, `{"RecursiveStruct":{"RecursiveStruct":{"RecursiveStruct":{"RecursiveStruct":{"NoRecurse":"foo"}}}}}`, util.Trim(string(body)))
@@ -1867,8 +2163,12 @@ func TestInputService5ProtocolTestRecursiveShapesCase3(t *testing.T) {
awstesting.AssertURL(t, "https://test/", r.URL.String())
// assert headers
assert.Equal(t, "application/x-amz-json-1.1", r.Header.Get("Content-Type"))
assert.Equal(t, "com.amazonaws.foo.OperationName", r.Header.Get("X-Amz-Target"))
if e, a := "application/x-amz-json-1.1", r.Header.Get("Content-Type"); e != a {
t.Errorf("expect %v to be %v", e, a)
}
if e, a := "com.amazonaws.foo.OperationName", r.Header.Get("X-Amz-Target"); e != a {
t.Errorf("expect %v to be %v", e, a)
}
}
@@ -1891,10 +2191,14 @@ func TestInputService5ProtocolTestRecursiveShapesCase4(t *testing.T) {
// build request
jsonrpc.Build(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert body
assert.NotNil(t, r.Body)
if r.Body == nil {
t.Errorf("expect body not to be nil")
}
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertJSON(t, `{"RecursiveStruct":{"RecursiveList":[{"NoRecurse":"foo"},{"NoRecurse":"bar"}]}}`, util.Trim(string(body)))
@@ -1902,8 +2206,12 @@ func TestInputService5ProtocolTestRecursiveShapesCase4(t *testing.T) {
awstesting.AssertURL(t, "https://test/", r.URL.String())
// assert headers
assert.Equal(t, "application/x-amz-json-1.1", r.Header.Get("Content-Type"))
assert.Equal(t, "com.amazonaws.foo.OperationName", r.Header.Get("X-Amz-Target"))
if e, a := "application/x-amz-json-1.1", r.Header.Get("Content-Type"); e != a {
t.Errorf("expect %v to be %v", e, a)
}
if e, a := "com.amazonaws.foo.OperationName", r.Header.Get("X-Amz-Target"); e != a {
t.Errorf("expect %v to be %v", e, a)
}
}
@@ -1928,10 +2236,14 @@ func TestInputService5ProtocolTestRecursiveShapesCase5(t *testing.T) {
// build request
jsonrpc.Build(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert body
assert.NotNil(t, r.Body)
if r.Body == nil {
t.Errorf("expect body not to be nil")
}
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertJSON(t, `{"RecursiveStruct":{"RecursiveList":[{"NoRecurse":"foo"},{"RecursiveStruct":{"NoRecurse":"bar"}}]}}`, util.Trim(string(body)))
@@ -1939,8 +2251,12 @@ func TestInputService5ProtocolTestRecursiveShapesCase5(t *testing.T) {
awstesting.AssertURL(t, "https://test/", r.URL.String())
// assert headers
assert.Equal(t, "application/x-amz-json-1.1", r.Header.Get("Content-Type"))
assert.Equal(t, "com.amazonaws.foo.OperationName", r.Header.Get("X-Amz-Target"))
if e, a := "application/x-amz-json-1.1", r.Header.Get("Content-Type"); e != a {
t.Errorf("expect %v to be %v", e, a)
}
if e, a := "com.amazonaws.foo.OperationName", r.Header.Get("X-Amz-Target"); e != a {
t.Errorf("expect %v to be %v", e, a)
}
}
@@ -1963,10 +2279,14 @@ func TestInputService5ProtocolTestRecursiveShapesCase6(t *testing.T) {
// build request
jsonrpc.Build(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert body
assert.NotNil(t, r.Body)
if r.Body == nil {
t.Errorf("expect body not to be nil")
}
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertJSON(t, `{"RecursiveStruct":{"RecursiveMap":{"foo":{"NoRecurse":"foo"},"bar":{"NoRecurse":"bar"}}}}`, util.Trim(string(body)))
@@ -1974,8 +2294,12 @@ func TestInputService5ProtocolTestRecursiveShapesCase6(t *testing.T) {
awstesting.AssertURL(t, "https://test/", r.URL.String())
// assert headers
assert.Equal(t, "application/x-amz-json-1.1", r.Header.Get("Content-Type"))
assert.Equal(t, "com.amazonaws.foo.OperationName", r.Header.Get("X-Amz-Target"))
if e, a := "application/x-amz-json-1.1", r.Header.Get("Content-Type"); e != a {
t.Errorf("expect %v to be %v", e, a)
}
if e, a := "com.amazonaws.foo.OperationName", r.Header.Get("X-Amz-Target"); e != a {
t.Errorf("expect %v to be %v", e, a)
}
}
@@ -1989,10 +2313,14 @@ func TestInputService6ProtocolTestEmptyMapsCase1(t *testing.T) {
// build request
jsonrpc.Build(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert body
assert.NotNil(t, r.Body)
if r.Body == nil {
t.Errorf("expect body not to be nil")
}
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertJSON(t, `{"Map":{}}`, util.Trim(string(body)))
@@ -2000,8 +2328,12 @@ func TestInputService6ProtocolTestEmptyMapsCase1(t *testing.T) {
awstesting.AssertURL(t, "https://test/", r.URL.String())
// assert headers
assert.Equal(t, "application/x-amz-json-1.1", r.Header.Get("Content-Type"))
assert.Equal(t, "com.amazonaws.foo.OperationName", r.Header.Get("X-Amz-Target"))
if e, a := "application/x-amz-json-1.1", r.Header.Get("Content-Type"); e != a {
t.Errorf("expect %v to be %v", e, a)
}
if e, a := "com.amazonaws.foo.OperationName", r.Header.Get("X-Amz-Target"); e != a {
t.Errorf("expect %v to be %v", e, a)
}
}
@@ -2015,10 +2347,14 @@ func TestInputService7ProtocolTestIdempotencyTokenAutoFillCase1(t *testing.T) {
// build request
jsonrpc.Build(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert body
assert.NotNil(t, r.Body)
if r.Body == nil {
t.Errorf("expect body not to be nil")
}
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertJSON(t, `{"Token":"abc123"}`, util.Trim(string(body)))
@@ -2037,10 +2373,14 @@ func TestInputService7ProtocolTestIdempotencyTokenAutoFillCase2(t *testing.T) {
// build request
jsonrpc.Build(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert body
assert.NotNil(t, r.Body)
if r.Body == nil {
t.Errorf("expect body not to be nil")
}
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertJSON(t, `{"Token":"00000000-0000-4000-8000-000000000000"}`, util.Trim(string(body)))
@@ -2050,3 +2390,55 @@ func TestInputService7ProtocolTestIdempotencyTokenAutoFillCase2(t *testing.T) {
// assert headers
}
func TestInputService8ProtocolTestEnumCase1(t *testing.T) {
svc := NewInputService8ProtocolTest(unit.Session, &aws.Config{Endpoint: aws.String("https://test")})
input := &InputService8TestShapeInputService8TestCaseOperation2Input{
FooEnum: aws.String("foo"),
ListEnums: []*string{
aws.String("foo"),
aws.String(""),
aws.String("bar"),
},
}
req, _ := svc.InputService8TestCaseOperation1Request(input)
r := req.HTTPRequest
// build request
jsonrpc.Build(req)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert body
if r.Body == nil {
t.Errorf("expect body not to be nil")
}
body, _ := ioutil.ReadAll(r.Body)
awstesting.AssertJSON(t, `{"FooEnum":"foo","ListEnums":["foo","","bar"]}`, util.Trim(string(body)))
// assert URL
awstesting.AssertURL(t, "https://test/", r.URL.String())
// assert headers
}
func TestInputService8ProtocolTestEnumCase2(t *testing.T) {
svc := NewInputService8ProtocolTest(unit.Session, &aws.Config{Endpoint: aws.String("https://test")})
input := &InputService8TestShapeInputService8TestCaseOperation2Input{}
req, _ := svc.InputService8TestCaseOperation2Request(input)
r := req.HTTPRequest
// build request
jsonrpc.Build(req)
if req.Error != nil {
t.Errorf("expect no error, got %v", req.Error)
}
// assert URL
awstesting.AssertURL(t, "https://test/", r.URL.String())
// assert headers
}
+312 -46
View File
@@ -24,7 +24,6 @@ import (
"github.com/aws/aws-sdk-go/private/protocol/jsonrpc"
"github.com/aws/aws-sdk-go/private/protocol/xml/xmlutil"
"github.com/aws/aws-sdk-go/private/util"
"github.com/stretchr/testify/assert"
)
var _ bytes.Buffer // always import bytes
@@ -108,7 +107,7 @@ const opOutputService1TestCaseOperation1 = "OperationName"
// OutputService1TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService1TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -307,7 +306,7 @@ const opOutputService2TestCaseOperation1 = "OperationName"
// OutputService2TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService2TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -472,7 +471,7 @@ const opOutputService3TestCaseOperation1 = "OperationName"
// OutputService3TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService3TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -635,7 +634,7 @@ const opOutputService4TestCaseOperation1 = "OperationName"
// OutputService4TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService4TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -703,7 +702,7 @@ const opOutputService4TestCaseOperation2 = "OperationName"
// OutputService4TestCaseOperation2Request generates a "aws/request.Request" representing the
// client's request for the OutputService4TestCaseOperation2 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -870,7 +869,7 @@ const opOutputService5TestCaseOperation1 = "OperationName"
// OutputService5TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService5TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -1013,7 +1012,7 @@ const opOutputService6TestCaseOperation1 = "OperationName"
// OutputService6TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService6TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -1093,6 +1092,165 @@ func (s *OutputService6TestShapeOutputService6TestCaseOperation1Output) SetStrTy
return s
}
// OutputService7ProtocolTest provides the API operation methods for making requests to
// . See this package's package overview docs
// for details on the service.
//
// OutputService7ProtocolTest methods are safe to use concurrently. It is not safe to
// modify mutate any of the struct's properties though.
type OutputService7ProtocolTest struct {
*client.Client
}
// New creates a new instance of the OutputService7ProtocolTest 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 OutputService7ProtocolTest client from just a session.
// svc := outputservice7protocoltest.New(mySession)
//
// // Create a OutputService7ProtocolTest client with additional configuration
// svc := outputservice7protocoltest.New(mySession, aws.NewConfig().WithRegion("us-west-2"))
func NewOutputService7ProtocolTest(p client.ConfigProvider, cfgs ...*aws.Config) *OutputService7ProtocolTest {
c := p.ClientConfig("outputservice7protocoltest", cfgs...)
return newOutputService7ProtocolTestClient(*c.Config, c.Handlers, c.Endpoint, c.SigningRegion, c.SigningName)
}
// newClient creates, initializes and returns a new service client instance.
func newOutputService7ProtocolTestClient(cfg aws.Config, handlers request.Handlers, endpoint, signingRegion, signingName string) *OutputService7ProtocolTest {
svc := &OutputService7ProtocolTest{
Client: client.New(
cfg,
metadata.ClientInfo{
ServiceName: "outputservice7protocoltest",
SigningName: signingName,
SigningRegion: signingRegion,
Endpoint: endpoint,
APIVersion: "",
},
handlers,
),
}
// Handlers
svc.Handlers.Sign.PushBackNamed(v4.SignRequestHandler)
svc.Handlers.Build.PushBackNamed(jsonrpc.BuildHandler)
svc.Handlers.Unmarshal.PushBackNamed(jsonrpc.UnmarshalHandler)
svc.Handlers.UnmarshalMeta.PushBackNamed(jsonrpc.UnmarshalMetaHandler)
svc.Handlers.UnmarshalError.PushBackNamed(jsonrpc.UnmarshalErrorHandler)
return svc
}
// newRequest creates a new request for a OutputService7ProtocolTest operation and runs any
// custom request initialization.
func (c *OutputService7ProtocolTest) newRequest(op *request.Operation, params, data interface{}) *request.Request {
req := c.NewRequest(op, params, data)
return req
}
const opOutputService7TestCaseOperation1 = "OperationName"
// OutputService7TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService7TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
// the "output" return value is not valid until after Send returns without error.
//
// See OutputService7TestCaseOperation1 for more information on using the OutputService7TestCaseOperation1
// API call, and error handling.
//
// This method is useful when you want to inject custom logic or configuration
// into the SDK's request lifecycle. Such as custom headers, or retry logic.
//
//
// // Example sending a request using the OutputService7TestCaseOperation1Request method.
// req, resp := client.OutputService7TestCaseOperation1Request(params)
//
// err := req.Send()
// if err == nil { // resp is now filled
// fmt.Println(resp)
// }
func (c *OutputService7ProtocolTest) OutputService7TestCaseOperation1Request(input *OutputService7TestShapeOutputService7TestCaseOperation1Input) (req *request.Request, output *OutputService7TestShapeOutputService7TestCaseOperation1Output) {
op := &request.Operation{
Name: opOutputService7TestCaseOperation1,
HTTPPath: "/",
}
if input == nil {
input = &OutputService7TestShapeOutputService7TestCaseOperation1Input{}
}
output = &OutputService7TestShapeOutputService7TestCaseOperation1Output{}
req = c.newRequest(op, input, output)
return
}
// OutputService7TestCaseOperation1 API operation for .
//
// Returns awserr.Error for service API and SDK errors. Use runtime type assertions
// with awserr.Error's Code and Message methods to get detailed information about
// the error.
//
// See the AWS API reference guide for 's
// API operation OutputService7TestCaseOperation1 for usage and error information.
func (c *OutputService7ProtocolTest) OutputService7TestCaseOperation1(input *OutputService7TestShapeOutputService7TestCaseOperation1Input) (*OutputService7TestShapeOutputService7TestCaseOperation1Output, error) {
req, out := c.OutputService7TestCaseOperation1Request(input)
return out, req.Send()
}
// OutputService7TestCaseOperation1WithContext is the same as OutputService7TestCaseOperation1 with the addition of
// the ability to pass a context and additional request options.
//
// See OutputService7TestCaseOperation1 for details on how to use this API operation.
//
// The context must be non-nil and will be used for request cancellation. If
// the context is nil a panic will occur. In the future the SDK may create
// sub-contexts for http.Requests. See https://golang.org/pkg/context/
// for more information on using Contexts.
func (c *OutputService7ProtocolTest) OutputService7TestCaseOperation1WithContext(ctx aws.Context, input *OutputService7TestShapeOutputService7TestCaseOperation1Input, opts ...request.Option) (*OutputService7TestShapeOutputService7TestCaseOperation1Output, error) {
req, out := c.OutputService7TestCaseOperation1Request(input)
req.SetContext(ctx)
req.ApplyOptions(opts...)
return out, req.Send()
}
type OutputService7TestShapeOutputService7TestCaseOperation1Input struct {
_ struct{} `type:"structure"`
}
type OutputService7TestShapeOutputService7TestCaseOperation1Output struct {
_ struct{} `type:"structure"`
FooEnum *string `type:"string" enum:"OutputService7TestShapeJSONEnumType"`
ListEnums []*string `type:"list"`
}
// SetFooEnum sets the FooEnum field's value.
func (s *OutputService7TestShapeOutputService7TestCaseOperation1Output) SetFooEnum(v string) *OutputService7TestShapeOutputService7TestCaseOperation1Output {
s.FooEnum = &v
return s
}
// SetListEnums sets the ListEnums field's value.
func (s *OutputService7TestShapeOutputService7TestCaseOperation1Output) SetListEnums(v []*string) *OutputService7TestShapeOutputService7TestCaseOperation1Output {
s.ListEnums = v
return s
}
const (
// JSONEnumTypeFoo is a OutputService7TestShapeJSONEnumType enum value
JSONEnumTypeFoo = "foo"
// JSONEnumTypeBar is a OutputService7TestShapeJSONEnumType enum value
JSONEnumTypeBar = "bar"
)
//
// Tests begin here
//
@@ -1109,18 +1267,38 @@ func TestOutputService1ProtocolTestScalarMembersCase1(t *testing.T) {
// unmarshal response
jsonrpc.UnmarshalMeta(req)
jsonrpc.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "a", *out.Char)
assert.Equal(t, 1.3, *out.Double)
assert.Equal(t, false, *out.FalseBool)
assert.Equal(t, 1.2, *out.Float)
assert.Equal(t, int64(200), *out.Long)
assert.Equal(t, int64(123), *out.Num)
assert.Equal(t, "myname", *out.Str)
assert.Equal(t, true, *out.TrueBool)
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "a", *out.Char; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := 1.3, *out.Double; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := false, *out.FalseBool; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := 1.2, *out.Float; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := int64(200), *out.Long; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := int64(123), *out.Num; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "myname", *out.Str; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := true, *out.TrueBool; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -1136,12 +1314,20 @@ func TestOutputService2ProtocolTestBlobMembersCase1(t *testing.T) {
// unmarshal response
jsonrpc.UnmarshalMeta(req)
jsonrpc.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "hi!", string(out.BlobMember))
assert.Equal(t, "there!", string(out.StructMember.Foo))
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "hi!", string(out.BlobMember); e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "there!", string(out.StructMember.Foo); e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -1157,12 +1343,20 @@ func TestOutputService3ProtocolTestTimestampMembersCase1(t *testing.T) {
// unmarshal response
jsonrpc.UnmarshalMeta(req)
jsonrpc.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, time.Unix(1.398796238e+09, 0).UTC().String(), out.StructMember.Foo.String())
assert.Equal(t, time.Unix(1.398796238e+09, 0).UTC().String(), out.TimeMember.String())
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := time.Unix(1.398796238e+09, 0).UTC().String(), out.StructMember.Foo.String(); e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := time.Unix(1.398796238e+09, 0).UTC().String(), out.TimeMember.String(); e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -1178,12 +1372,20 @@ func TestOutputService4ProtocolTestListsCase1(t *testing.T) {
// unmarshal response
jsonrpc.UnmarshalMeta(req)
jsonrpc.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "a", *out.ListMember[0])
assert.Equal(t, "b", *out.ListMember[1])
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "a", *out.ListMember[0]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "b", *out.ListMember[1]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -1199,16 +1401,32 @@ func TestOutputService4ProtocolTestListsCase2(t *testing.T) {
// unmarshal response
jsonrpc.UnmarshalMeta(req)
jsonrpc.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "a", *out.ListMember[0])
assert.Nil(t, out.ListMember[1])
assert.Nil(t, out.ListMemberMap[1])
assert.Nil(t, out.ListMemberMap[2])
assert.Nil(t, out.ListMemberStruct[1])
assert.Nil(t, out.ListMemberStruct[2])
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "a", *out.ListMember[0]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e := out.ListMember[1]; e != nil {
t.Errorf("expect nil, got %v", e)
}
if e := out.ListMemberMap[1]; e != nil {
t.Errorf("expect nil, got %v", e)
}
if e := out.ListMemberMap[2]; e != nil {
t.Errorf("expect nil, got %v", e)
}
if e := out.ListMemberStruct[1]; e != nil {
t.Errorf("expect nil, got %v", e)
}
if e := out.ListMemberStruct[2]; e != nil {
t.Errorf("expect nil, got %v", e)
}
}
@@ -1224,14 +1442,26 @@ func TestOutputService5ProtocolTestMapsCase1(t *testing.T) {
// unmarshal response
jsonrpc.UnmarshalMeta(req)
jsonrpc.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, int64(1), *out.MapMember["a"][0])
assert.Equal(t, int64(2), *out.MapMember["a"][1])
assert.Equal(t, int64(3), *out.MapMember["b"][0])
assert.Equal(t, int64(4), *out.MapMember["b"][1])
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := int64(1), *out.MapMember["a"][0]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := int64(2), *out.MapMember["a"][1]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := int64(3), *out.MapMember["b"][0]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := int64(4), *out.MapMember["b"][1]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -1247,9 +1477,45 @@ func TestOutputService6ProtocolTestIgnoresExtraDataCase1(t *testing.T) {
// unmarshal response
jsonrpc.UnmarshalMeta(req)
jsonrpc.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
if out == nil {
t.Errorf("expect not to be nil")
}
}
func TestOutputService7ProtocolTestEnumOutputCase1(t *testing.T) {
svc := NewOutputService7ProtocolTest(unit.Session, &aws.Config{Endpoint: aws.String("https://test")})
buf := bytes.NewReader([]byte("{\"FooEnum\": \"foo\", \"ListEnums\": [\"foo\", \"bar\"]}"))
req, out := svc.OutputService7TestCaseOperation1Request(nil)
req.HTTPResponse = &http.Response{StatusCode: 200, Body: ioutil.NopCloser(buf), Header: http.Header{}}
// set headers
// unmarshal response
jsonrpc.UnmarshalMeta(req)
jsonrpc.Unmarshal(req)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "foo", *out.FooEnum; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "foo", *out.ListEnums[0]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "bar", *out.ListEnums[1]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
+76
View File
@@ -0,0 +1,76 @@
package protocol
import (
"encoding/base64"
"encoding/json"
"fmt"
"strconv"
"github.com/aws/aws-sdk-go/aws"
)
// EscapeMode is the mode that should be use for escaping a value
type EscapeMode uint
// The modes for escaping a value before it is marshaled, and unmarshaled.
const (
NoEscape EscapeMode = iota
Base64Escape
QuotedEscape
)
// EncodeJSONValue marshals the value into a JSON string, and optionally base64
// encodes the string before returning it.
//
// Will panic if the escape mode is unknown.
func EncodeJSONValue(v aws.JSONValue, escape EscapeMode) (string, error) {
b, err := json.Marshal(v)
if err != nil {
return "", err
}
switch escape {
case NoEscape:
return string(b), nil
case Base64Escape:
return base64.StdEncoding.EncodeToString(b), nil
case QuotedEscape:
return strconv.Quote(string(b)), nil
}
panic(fmt.Sprintf("EncodeJSONValue called with unknown EscapeMode, %v", escape))
}
// DecodeJSONValue will attempt to decode the string input as a JSONValue.
// Optionally decoding base64 the value first before JSON unmarshaling.
//
// Will panic if the escape mode is unknown.
func DecodeJSONValue(v string, escape EscapeMode) (aws.JSONValue, error) {
var b []byte
var err error
switch escape {
case NoEscape:
b = []byte(v)
case Base64Escape:
b, err = base64.StdEncoding.DecodeString(v)
case QuotedEscape:
var u string
u, err = strconv.Unquote(v)
b = []byte(u)
default:
panic(fmt.Sprintf("DecodeJSONValue called with unknown EscapeMode, %v", escape))
}
if err != nil {
return nil, err
}
m := aws.JSONValue{}
err = json.Unmarshal(b, &m)
if err != nil {
return nil, err
}
return m, nil
}
+93
View File
@@ -0,0 +1,93 @@
package protocol
import (
"fmt"
"reflect"
"strings"
"testing"
"github.com/aws/aws-sdk-go/aws"
)
var testJSONValueCases = []struct {
Value aws.JSONValue
Mode EscapeMode
String string
}{
{
Value: aws.JSONValue{
"abc": 123.,
},
Mode: NoEscape,
String: `{"abc":123}`,
},
{
Value: aws.JSONValue{
"abc": 123.,
},
Mode: Base64Escape,
String: `eyJhYmMiOjEyM30=`,
},
{
Value: aws.JSONValue{
"abc": 123.,
},
Mode: QuotedEscape,
String: `"{\"abc\":123}"`,
},
}
func TestEncodeJSONValue(t *testing.T) {
for i, c := range testJSONValueCases {
str, err := EncodeJSONValue(c.Value, c.Mode)
if err != nil {
t.Fatalf("%d, expect no error, got %v", i, err)
}
if e, a := c.String, str; e != a {
t.Errorf("%d, expect %v encoded value, got %v", i, e, a)
}
}
}
func TestDecodeJSONValue(t *testing.T) {
for i, c := range testJSONValueCases {
val, err := DecodeJSONValue(c.String, c.Mode)
if err != nil {
t.Fatalf("%d, expect no error, got %v", i, err)
}
if e, a := c.Value, val; !reflect.DeepEqual(e, a) {
t.Errorf("%d, expect %v encoded value, got %v", i, e, a)
}
}
}
func TestEncodeJSONValue_PanicUnkownMode(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Errorf("expect panic, got none")
} else {
reason := fmt.Sprintf("%v", r)
if e, a := "unknown EscapeMode", reason; !strings.Contains(a, e) {
t.Errorf("expect %q to be in %v", e, a)
}
}
}()
val := aws.JSONValue{}
EncodeJSONValue(val, 123456)
}
func TestDecodeJSONValue_PanicUnkownMode(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Errorf("expect panic, got none")
} else {
reason := fmt.Sprintf("%v", r)
if e, a := "unknown EscapeMode", reason; !strings.Contains(a, e) {
t.Errorf("expect %q to be in %v", e, a)
}
}
}()
DecodeJSONValue(`{"abc":123}`, 123456)
}
+1 -1
View File
@@ -25,7 +25,7 @@ func Build(r *request.Request) {
return
}
if r.ExpireTime == 0 {
if !r.IsPresigned() {
r.HTTPRequest.Method = "POST"
r.HTTPRequest.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=utf-8")
r.SetBufferBody([]byte(body.Encode()))
File diff suppressed because it is too large Load Diff
@@ -121,6 +121,10 @@ func (q *queryParser) parseList(v url.Values, value reflect.Value, prefix string
return nil
}
if _, ok := value.Interface().([]byte); ok {
return q.parseScalar(v, value, prefix, tag)
}
// check for unflattened list member
if !q.isEC2 && tag.Get("flattened") == "" {
if listName := tag.Get("locationNameList"); listName == "" {
+416 -86
View File
@@ -24,7 +24,6 @@ import (
"github.com/aws/aws-sdk-go/private/protocol/query"
"github.com/aws/aws-sdk-go/private/protocol/xml/xmlutil"
"github.com/aws/aws-sdk-go/private/util"
"github.com/stretchr/testify/assert"
)
var _ bytes.Buffer // always import bytes
@@ -108,7 +107,7 @@ const opOutputService1TestCaseOperation1 = "OperationName"
// OutputService1TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService1TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -315,7 +314,7 @@ const opOutputService2TestCaseOperation1 = "OperationName"
// OutputService2TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService2TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -466,7 +465,7 @@ const opOutputService3TestCaseOperation1 = "OperationName"
// OutputService3TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService3TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -610,7 +609,7 @@ const opOutputService4TestCaseOperation1 = "OperationName"
// OutputService4TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService4TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -753,7 +752,7 @@ const opOutputService5TestCaseOperation1 = "OperationName"
// OutputService5TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService5TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -896,7 +895,7 @@ const opOutputService6TestCaseOperation1 = "OperationName"
// OutputService6TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService6TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -1039,7 +1038,7 @@ const opOutputService7TestCaseOperation1 = "OperationName"
// OutputService7TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService7TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -1182,7 +1181,7 @@ const opOutputService8TestCaseOperation1 = "OperationName"
// OutputService8TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService8TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -1353,7 +1352,7 @@ const opOutputService9TestCaseOperation1 = "OperationName"
// OutputService9TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService9TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -1524,7 +1523,7 @@ const opOutputService10TestCaseOperation1 = "OperationName"
// OutputService10TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService10TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -1667,7 +1666,7 @@ const opOutputService11TestCaseOperation1 = "OperationName"
// OutputService11TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService11TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -1822,7 +1821,7 @@ const opOutputService12TestCaseOperation1 = "OperationName"
// OutputService12TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService12TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -1965,7 +1964,7 @@ const opOutputService13TestCaseOperation1 = "OperationName"
// OutputService13TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService13TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -2108,7 +2107,7 @@ const opOutputService14TestCaseOperation1 = "OperationName"
// OutputService14TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService14TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -2251,7 +2250,7 @@ const opOutputService15TestCaseOperation1 = "OperationName"
// OutputService15TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService15TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request complets
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
@@ -2331,6 +2330,165 @@ func (s *OutputService15TestShapeOutputService15TestCaseOperation1Output) SetFoo
return s
}
// OutputService16ProtocolTest provides the API operation methods for making requests to
// . See this package's package overview docs
// for details on the service.
//
// OutputService16ProtocolTest methods are safe to use concurrently. It is not safe to
// modify mutate any of the struct's properties though.
type OutputService16ProtocolTest struct {
*client.Client
}
// New creates a new instance of the OutputService16ProtocolTest 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 OutputService16ProtocolTest client from just a session.
// svc := outputservice16protocoltest.New(mySession)
//
// // Create a OutputService16ProtocolTest client with additional configuration
// svc := outputservice16protocoltest.New(mySession, aws.NewConfig().WithRegion("us-west-2"))
func NewOutputService16ProtocolTest(p client.ConfigProvider, cfgs ...*aws.Config) *OutputService16ProtocolTest {
c := p.ClientConfig("outputservice16protocoltest", cfgs...)
return newOutputService16ProtocolTestClient(*c.Config, c.Handlers, c.Endpoint, c.SigningRegion, c.SigningName)
}
// newClient creates, initializes and returns a new service client instance.
func newOutputService16ProtocolTestClient(cfg aws.Config, handlers request.Handlers, endpoint, signingRegion, signingName string) *OutputService16ProtocolTest {
svc := &OutputService16ProtocolTest{
Client: client.New(
cfg,
metadata.ClientInfo{
ServiceName: "outputservice16protocoltest",
SigningName: signingName,
SigningRegion: signingRegion,
Endpoint: endpoint,
APIVersion: "",
},
handlers,
),
}
// Handlers
svc.Handlers.Sign.PushBackNamed(v4.SignRequestHandler)
svc.Handlers.Build.PushBackNamed(query.BuildHandler)
svc.Handlers.Unmarshal.PushBackNamed(query.UnmarshalHandler)
svc.Handlers.UnmarshalMeta.PushBackNamed(query.UnmarshalMetaHandler)
svc.Handlers.UnmarshalError.PushBackNamed(query.UnmarshalErrorHandler)
return svc
}
// newRequest creates a new request for a OutputService16ProtocolTest operation and runs any
// custom request initialization.
func (c *OutputService16ProtocolTest) newRequest(op *request.Operation, params, data interface{}) *request.Request {
req := c.NewRequest(op, params, data)
return req
}
const opOutputService16TestCaseOperation1 = "OperationName"
// OutputService16TestCaseOperation1Request generates a "aws/request.Request" representing the
// client's request for the OutputService16TestCaseOperation1 operation. The "output" return
// value will be populated with the request's response once the request completes
// successfuly.
//
// Use "Send" method on the returned Request to send the API call to the service.
// the "output" return value is not valid until after Send returns without error.
//
// See OutputService16TestCaseOperation1 for more information on using the OutputService16TestCaseOperation1
// API call, and error handling.
//
// This method is useful when you want to inject custom logic or configuration
// into the SDK's request lifecycle. Such as custom headers, or retry logic.
//
//
// // Example sending a request using the OutputService16TestCaseOperation1Request method.
// req, resp := client.OutputService16TestCaseOperation1Request(params)
//
// err := req.Send()
// if err == nil { // resp is now filled
// fmt.Println(resp)
// }
func (c *OutputService16ProtocolTest) OutputService16TestCaseOperation1Request(input *OutputService16TestShapeOutputService16TestCaseOperation1Input) (req *request.Request, output *OutputService16TestShapeOutputService16TestCaseOperation1Output) {
op := &request.Operation{
Name: opOutputService16TestCaseOperation1,
HTTPPath: "/",
}
if input == nil {
input = &OutputService16TestShapeOutputService16TestCaseOperation1Input{}
}
output = &OutputService16TestShapeOutputService16TestCaseOperation1Output{}
req = c.newRequest(op, input, output)
return
}
// OutputService16TestCaseOperation1 API operation for .
//
// Returns awserr.Error for service API and SDK errors. Use runtime type assertions
// with awserr.Error's Code and Message methods to get detailed information about
// the error.
//
// See the AWS API reference guide for 's
// API operation OutputService16TestCaseOperation1 for usage and error information.
func (c *OutputService16ProtocolTest) OutputService16TestCaseOperation1(input *OutputService16TestShapeOutputService16TestCaseOperation1Input) (*OutputService16TestShapeOutputService16TestCaseOperation1Output, error) {
req, out := c.OutputService16TestCaseOperation1Request(input)
return out, req.Send()
}
// OutputService16TestCaseOperation1WithContext is the same as OutputService16TestCaseOperation1 with the addition of
// the ability to pass a context and additional request options.
//
// See OutputService16TestCaseOperation1 for details on how to use this API operation.
//
// The context must be non-nil and will be used for request cancellation. If
// the context is nil a panic will occur. In the future the SDK may create
// sub-contexts for http.Requests. See https://golang.org/pkg/context/
// for more information on using Contexts.
func (c *OutputService16ProtocolTest) OutputService16TestCaseOperation1WithContext(ctx aws.Context, input *OutputService16TestShapeOutputService16TestCaseOperation1Input, opts ...request.Option) (*OutputService16TestShapeOutputService16TestCaseOperation1Output, error) {
req, out := c.OutputService16TestCaseOperation1Request(input)
req.SetContext(ctx)
req.ApplyOptions(opts...)
return out, req.Send()
}
type OutputService16TestShapeOutputService16TestCaseOperation1Input struct {
_ struct{} `type:"structure"`
}
type OutputService16TestShapeOutputService16TestCaseOperation1Output struct {
_ struct{} `type:"structure"`
FooEnum *string `type:"string" enum:"OutputService16TestShapeEC2EnumType"`
ListEnums []*string `type:"list"`
}
// SetFooEnum sets the FooEnum field's value.
func (s *OutputService16TestShapeOutputService16TestCaseOperation1Output) SetFooEnum(v string) *OutputService16TestShapeOutputService16TestCaseOperation1Output {
s.FooEnum = &v
return s
}
// SetListEnums sets the ListEnums field's value.
func (s *OutputService16TestShapeOutputService16TestCaseOperation1Output) SetListEnums(v []*string) *OutputService16TestShapeOutputService16TestCaseOperation1Output {
s.ListEnums = v
return s
}
const (
// EC2EnumTypeFoo is a OutputService16TestShapeEC2EnumType enum value
EC2EnumTypeFoo = "foo"
// EC2EnumTypeBar is a OutputService16TestShapeEC2EnumType enum value
EC2EnumTypeBar = "bar"
)
//
// Tests begin here
//
@@ -2347,19 +2505,41 @@ func TestOutputService1ProtocolTestScalarMembersCase1(t *testing.T) {
// unmarshal response
query.UnmarshalMeta(req)
query.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "a", *out.Char)
assert.Equal(t, 1.3, *out.Double)
assert.Equal(t, false, *out.FalseBool)
assert.Equal(t, 1.2, *out.Float)
assert.Equal(t, int64(200), *out.Long)
assert.Equal(t, int64(123), *out.Num)
assert.Equal(t, "myname", *out.Str)
assert.Equal(t, time.Unix(1.4221728e+09, 0).UTC().String(), out.Timestamp.String())
assert.Equal(t, true, *out.TrueBool)
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "a", *out.Char; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := 1.3, *out.Double; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := false, *out.FalseBool; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := 1.2, *out.Float; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := int64(200), *out.Long; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := int64(123), *out.Num; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "myname", *out.Str; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := time.Unix(1.4221728e+09, 0).UTC().String(), out.Timestamp.String(); e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := true, *out.TrueBool; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -2375,11 +2555,17 @@ func TestOutputService2ProtocolTestNotAllMembersInResponseCase1(t *testing.T) {
// unmarshal response
query.UnmarshalMeta(req)
query.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "myname", *out.Str)
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "myname", *out.Str; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -2395,11 +2581,17 @@ func TestOutputService3ProtocolTestBlobCase1(t *testing.T) {
// unmarshal response
query.UnmarshalMeta(req)
query.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "value", string(out.Blob))
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "value", string(out.Blob); e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -2415,12 +2607,20 @@ func TestOutputService4ProtocolTestListsCase1(t *testing.T) {
// unmarshal response
query.UnmarshalMeta(req)
query.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "abc", *out.ListMember[0])
assert.Equal(t, "123", *out.ListMember[1])
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "abc", *out.ListMember[0]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "123", *out.ListMember[1]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -2436,12 +2636,20 @@ func TestOutputService5ProtocolTestListWithCustomMemberNameCase1(t *testing.T) {
// unmarshal response
query.UnmarshalMeta(req)
query.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "abc", *out.ListMember[0])
assert.Equal(t, "123", *out.ListMember[1])
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "abc", *out.ListMember[0]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "123", *out.ListMember[1]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -2457,12 +2665,20 @@ func TestOutputService6ProtocolTestFlattenedListCase1(t *testing.T) {
// unmarshal response
query.UnmarshalMeta(req)
query.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "abc", *out.ListMember[0])
assert.Equal(t, "123", *out.ListMember[1])
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "abc", *out.ListMember[0]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "123", *out.ListMember[1]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -2478,11 +2694,17 @@ func TestOutputService7ProtocolTestFlattenedSingleElementListCase1(t *testing.T)
// unmarshal response
query.UnmarshalMeta(req)
query.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "abc", *out.ListMember[0])
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "abc", *out.ListMember[0]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -2498,16 +2720,32 @@ func TestOutputService8ProtocolTestListOfStructuresCase1(t *testing.T) {
// unmarshal response
query.UnmarshalMeta(req)
query.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "firstbar", *out.List[0].Bar)
assert.Equal(t, "firstbaz", *out.List[0].Baz)
assert.Equal(t, "firstfoo", *out.List[0].Foo)
assert.Equal(t, "secondbar", *out.List[1].Bar)
assert.Equal(t, "secondbaz", *out.List[1].Baz)
assert.Equal(t, "secondfoo", *out.List[1].Foo)
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "firstbar", *out.List[0].Bar; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "firstbaz", *out.List[0].Baz; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "firstfoo", *out.List[0].Foo; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "secondbar", *out.List[1].Bar; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "secondbaz", *out.List[1].Baz; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "secondfoo", *out.List[1].Foo; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -2523,16 +2761,32 @@ func TestOutputService9ProtocolTestFlattenedListOfStructuresCase1(t *testing.T)
// unmarshal response
query.UnmarshalMeta(req)
query.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "firstbar", *out.List[0].Bar)
assert.Equal(t, "firstbaz", *out.List[0].Baz)
assert.Equal(t, "firstfoo", *out.List[0].Foo)
assert.Equal(t, "secondbar", *out.List[1].Bar)
assert.Equal(t, "secondbaz", *out.List[1].Baz)
assert.Equal(t, "secondfoo", *out.List[1].Foo)
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "firstbar", *out.List[0].Bar; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "firstbaz", *out.List[0].Baz; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "firstfoo", *out.List[0].Foo; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "secondbar", *out.List[1].Bar; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "secondbaz", *out.List[1].Baz; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "secondfoo", *out.List[1].Foo; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -2548,12 +2802,20 @@ func TestOutputService10ProtocolTestFlattenedListWithLocationNameCase1(t *testin
// unmarshal response
query.UnmarshalMeta(req)
query.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "a", *out.List[0])
assert.Equal(t, "b", *out.List[1])
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "a", *out.List[0]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "b", *out.List[1]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -2569,12 +2831,20 @@ func TestOutputService11ProtocolTestNormalMapCase1(t *testing.T) {
// unmarshal response
query.UnmarshalMeta(req)
query.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "bam", *out.Map["baz"].Foo)
assert.Equal(t, "bar", *out.Map["qux"].Foo)
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "bam", *out.Map["baz"].Foo; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "bar", *out.Map["qux"].Foo; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -2590,12 +2860,20 @@ func TestOutputService12ProtocolTestFlattenedMapCase1(t *testing.T) {
// unmarshal response
query.UnmarshalMeta(req)
query.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "bam", *out.Map["baz"])
assert.Equal(t, "bar", *out.Map["qux"])
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "bam", *out.Map["baz"]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "bar", *out.Map["qux"]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -2611,11 +2889,17 @@ func TestOutputService13ProtocolTestFlattenedMapInShapeDefinitionCase1(t *testin
// unmarshal response
query.UnmarshalMeta(req)
query.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "bar", *out.Map["qux"])
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "bar", *out.Map["qux"]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -2631,12 +2915,20 @@ func TestOutputService14ProtocolTestNamedMapCase1(t *testing.T) {
// unmarshal response
query.UnmarshalMeta(req)
query.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "bam", *out.Map["baz"])
assert.Equal(t, "bar", *out.Map["qux"])
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "bam", *out.Map["baz"]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "bar", *out.Map["qux"]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -2652,10 +2944,48 @@ func TestOutputService15ProtocolTestEmptyStringCase1(t *testing.T) {
// unmarshal response
query.UnmarshalMeta(req)
query.Unmarshal(req)
assert.NoError(t, req.Error)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "", *out.Foo)
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "", *out.Foo; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
func TestOutputService16ProtocolTestEnumOutputCase1(t *testing.T) {
svc := NewOutputService16ProtocolTest(unit.Session, &aws.Config{Endpoint: aws.String("https://test")})
buf := bytes.NewReader([]byte("<OperationNameResponse><FooEnum>foo</FooEnum><ListEnums><member>foo</member><member>bar</member></ListEnums></OperationNameResponse>"))
req, out := svc.OutputService16TestCaseOperation1Request(nil)
req.HTTPResponse = &http.Response{StatusCode: 200, Body: ioutil.NopCloser(buf), Header: http.Header{}}
// set headers
// unmarshal response
query.UnmarshalMeta(req)
query.Unmarshal(req)
if req.Error != nil {
t.Errorf("expect not error, got %v", req.Error)
}
// assert response
if out == nil {
t.Errorf("expect not to be nil")
}
if e, a := "foo", *out.FooEnum; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "foo", *out.ListEnums[0]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "bar", *out.ListEnums[1]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
+11 -10
View File
@@ -4,7 +4,6 @@ package rest
import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"net/http"
@@ -18,6 +17,7 @@ import (
"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/private/protocol"
)
// RFC822 returns an RFC822 formatted timestamp for AWS protocols
@@ -252,13 +252,12 @@ func EscapePath(path string, encodeSep bool) string {
return buf.String()
}
func convertType(v reflect.Value, tag reflect.StructTag) (string, error) {
func convertType(v reflect.Value, tag reflect.StructTag) (str string, err error) {
v = reflect.Indirect(v)
if !v.IsValid() {
return "", errValueNotSet
}
var str string
switch value := v.Interface().(type) {
case string:
str = value
@@ -273,17 +272,19 @@ func convertType(v reflect.Value, tag reflect.StructTag) (string, error) {
case time.Time:
str = value.UTC().Format(RFC822)
case aws.JSONValue:
b, err := json.Marshal(value)
if err != nil {
return "", err
if len(value) == 0 {
return "", errValueNotSet
}
escaping := protocol.NoEscape
if tag.Get("location") == "header" {
str = base64.StdEncoding.EncodeToString(b)
} else {
str = string(b)
escaping = protocol.Base64Escape
}
str, err = protocol.EncodeJSONValue(value, escaping)
if err != nil {
return "", fmt.Errorf("unable to encode JSONValue, %v", err)
}
default:
err := fmt.Errorf("Unsupported value for param %v (%s)", v.Interface(), v.Type())
err := fmt.Errorf("unsupported value for param %v (%s)", v.Interface(), v.Type())
return "", err
}
return str, nil
+4 -10
View File
@@ -3,7 +3,6 @@ package rest
import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"io/ioutil"
@@ -16,6 +15,7 @@ import (
"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/private/protocol"
)
// UnmarshalHandler is a named request handler for unmarshaling rest protocol requests
@@ -204,17 +204,11 @@ func unmarshalHeader(v reflect.Value, header string, tag reflect.StructTag) erro
}
v.Set(reflect.ValueOf(&t))
case aws.JSONValue:
b := []byte(header)
var err error
escaping := protocol.NoEscape
if tag.Get("location") == "header" {
b, err = base64.StdEncoding.DecodeString(header)
if err != nil {
return err
}
escaping = protocol.Base64Escape
}
m := aws.JSONValue{}
err = json.Unmarshal(b, &m)
m, err := protocol.DecodeJSONValue(header, escaping)
if err != nil {
return err
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,66 +0,0 @@
package xmlutil_test
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/awstesting/unit"
"github.com/aws/aws-sdk-go/service/s3"
)
func TestUnmarshal(t *testing.T) {
xmlVal := []byte(`<?xml version="1.0" encoding="UTF-8"?>
<AccessControlPolicy xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Owner>
<ID>foo-id</ID>
<DisplayName>user</DisplayName>
</Owner>
<AccessControlList>
<Grant>
<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="type">
<ID>foo-id</ID>
<DisplayName>user</DisplayName>
</Grantee>
<Permission>FULL_CONTROL</Permission>
</Grant>
</AccessControlList>
</AccessControlPolicy>`)
var server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write(xmlVal)
}))
sess := unit.Session
sess.Config.Endpoint = &server.URL
sess.Config.S3ForcePathStyle = aws.Bool(true)
svc := s3.New(sess)
out, err := svc.GetBucketAcl(&s3.GetBucketAclInput{
Bucket: aws.String("foo"),
})
assert.NoError(t, err)
expected := &s3.GetBucketAclOutput{
Grants: []*s3.Grant{
{
Grantee: &s3.Grantee{
DisplayName: aws.String("user"),
ID: aws.String("foo-id"),
Type: aws.String("type"),
},
Permission: aws.String("FULL_CONTROL"),
},
},
Owner: &s3.Owner{
DisplayName: aws.String("user"),
ID: aws.String("foo-id"),
},
}
assert.Equal(t, expected, out)
}
+72 -30
View File
@@ -12,7 +12,6 @@ import (
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/awstesting"
"github.com/stretchr/testify/assert"
)
type signerBuilder struct {
@@ -56,8 +55,6 @@ func (sb signerBuilder) BuildSigner() signer {
}
func TestSignRequestWithAndWithoutSession(t *testing.T) {
assert := assert.New(t)
// have to create more than once, so use a function
newQuery := func() url.Values {
query := make(url.Values)
@@ -82,21 +79,45 @@ func TestSignRequestWithAndWithoutSession(t *testing.T) {
signer := builder.BuildSigner()
err := signer.Sign()
assert.NoError(err)
assert.Equal("tm4dX8Ks7pzFSVHz7qHdoJVXKRLuC4gWz9eti60d8ks=", signer.signature)
assert.Equal(8, len(signer.Query))
assert.Equal("AKID", signer.Query.Get("AWSAccessKeyId"))
assert.Equal("2015-07-16T07:56:16Z", signer.Query.Get("Timestamp"))
assert.Equal("HmacSHA256", signer.Query.Get("SignatureMethod"))
assert.Equal("2", signer.Query.Get("SignatureVersion"))
assert.Equal("tm4dX8Ks7pzFSVHz7qHdoJVXKRLuC4gWz9eti60d8ks=", signer.Query.Get("Signature"))
assert.Equal("CreateDomain", signer.Query.Get("Action"))
assert.Equal("TestDomain-1437033376", signer.Query.Get("DomainName"))
assert.Equal("2009-04-15", signer.Query.Get("Version"))
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
if e, a := "tm4dX8Ks7pzFSVHz7qHdoJVXKRLuC4gWz9eti60d8ks=", signer.signature; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := 8, len(signer.Query); e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "AKID", signer.Query.Get("AWSAccessKeyId"); e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "2015-07-16T07:56:16Z", signer.Query.Get("Timestamp"); e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "HmacSHA256", signer.Query.Get("SignatureMethod"); e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "2", signer.Query.Get("SignatureVersion"); e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "tm4dX8Ks7pzFSVHz7qHdoJVXKRLuC4gWz9eti60d8ks=", signer.Query.Get("Signature"); e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "CreateDomain", signer.Query.Get("Action"); e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "TestDomain-1437033376", signer.Query.Get("DomainName"); e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "2009-04-15", signer.Query.Get("Version"); e != a {
t.Errorf("expect %v, got %v", e, a)
}
// should not have a SecurityToken parameter
_, ok := signer.Query["SecurityToken"]
assert.False(ok)
if ok {
t.Errorf("expect SecurityToken found, was not")
}
// now sign again, this time with a security token (session)
@@ -105,15 +126,24 @@ func TestSignRequestWithAndWithoutSession(t *testing.T) {
signer = builder.BuildSigner()
err = signer.Sign()
assert.NoError(err)
assert.Equal("Ch6qv3rzXB1SLqY2vFhsgA1WQ9rnQIE2WJCigOvAJwI=", signer.signature)
assert.Equal(9, len(signer.Query)) // expect one more parameter
assert.Equal("Ch6qv3rzXB1SLqY2vFhsgA1WQ9rnQIE2WJCigOvAJwI=", signer.Query.Get("Signature"))
assert.Equal("SESSION", signer.Query.Get("SecurityToken"))
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
if e, a := "Ch6qv3rzXB1SLqY2vFhsgA1WQ9rnQIE2WJCigOvAJwI=", signer.signature; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := 9, len(signer.Query); e != a { // expect one more parameter
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "Ch6qv3rzXB1SLqY2vFhsgA1WQ9rnQIE2WJCigOvAJwI=", signer.Query.Get("Signature"); e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "SESSION", signer.Query.Get("SecurityToken"); e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
func TestMoreComplexSignRequest(t *testing.T) {
assert := assert.New(t)
query := make(url.Values)
query.Add("Action", "PutAttributes")
query.Add("DomainName", "TestDomain-1437041569")
@@ -139,12 +169,15 @@ func TestMoreComplexSignRequest(t *testing.T) {
signer := builder.BuildSigner()
err := signer.Sign()
assert.NoError(err)
assert.Equal("WNdE62UJKLKoA6XncVY/9RDbrKmcVMdQPQOTAs8SgwQ=", signer.signature)
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
if e, a := "WNdE62UJKLKoA6XncVY/9RDbrKmcVMdQPQOTAs8SgwQ=", signer.signature; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
func TestGet(t *testing.T) {
assert := assert.New(t)
svc := awstesting.NewClient(&aws.Config{
Credentials: credentials.NewStaticCredentials("AKID", "SECRET", "SESSION"),
Region: aws.String("ap-southeast-2"),
@@ -160,17 +193,24 @@ func TestGet(t *testing.T) {
)
r.Build()
assert.Equal("GET", r.HTTPRequest.Method)
assert.Equal("", r.HTTPRequest.URL.Query().Get("Signature"))
if e, a := "GET", r.HTTPRequest.Method; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "", r.HTTPRequest.URL.Query().Get("Signature"); e != a {
t.Errorf("expect %v, got %v", e, a)
}
SignSDKRequest(r)
assert.NoError(r.Error)
if r.Error != nil {
t.Fatalf("expect no error, got %v", r.Error)
}
t.Logf("Signature: %s", r.HTTPRequest.URL.Query().Get("Signature"))
assert.NotEqual("", r.HTTPRequest.URL.Query().Get("Signature"))
if len(r.HTTPRequest.URL.Query().Get("Signature")) == 0 {
t.Errorf("expect signature to be set, was not")
}
}
func TestAnonymousCredentials(t *testing.T) {
assert := assert.New(t)
svc := awstesting.NewClient(&aws.Config{
Credentials: credentials.AnonymousCredentials,
Region: aws.String("ap-southeast-2"),
@@ -191,5 +231,7 @@ func TestAnonymousCredentials(t *testing.T) {
req := r.HTTPRequest
req.ParseForm()
assert.Empty(req.PostForm.Get("Signature"))
if a := req.PostForm.Get("Signature"); len(a) != 0 {
t.Errorf("expect no signature, got %v", a)
}
}