From 56e74239d6b34df8f30ef046f0b0ff4ff0866a71 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Sun, 14 Jun 2015 23:53:32 -0800 Subject: first commit --- .../awslabs/aws-sdk-go/aws/param_validator_test.go | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 Godeps/_workspace/src/github.com/awslabs/aws-sdk-go/aws/param_validator_test.go (limited to 'Godeps/_workspace/src/github.com/awslabs/aws-sdk-go/aws/param_validator_test.go') diff --git a/Godeps/_workspace/src/github.com/awslabs/aws-sdk-go/aws/param_validator_test.go b/Godeps/_workspace/src/github.com/awslabs/aws-sdk-go/aws/param_validator_test.go new file mode 100644 index 000000000..08deca15a --- /dev/null +++ b/Godeps/_workspace/src/github.com/awslabs/aws-sdk-go/aws/param_validator_test.go @@ -0,0 +1,85 @@ +package aws_test + +import ( + "testing" + + "github.com/awslabs/aws-sdk-go/aws" + "github.com/stretchr/testify/assert" +) + +var service = func() *aws.Service { + s := &aws.Service{ + Config: &aws.Config{}, + ServiceName: "mock-service", + APIVersion: "2015-01-01", + } + return s +}() + +type StructShape struct { + RequiredList []*ConditionalStructShape `required:"true"` + RequiredMap *map[string]*ConditionalStructShape `required:"true"` + RequiredBool *bool `required:"true"` + OptionalStruct *ConditionalStructShape + + hiddenParameter *string + + metadataStructureShape +} + +type metadataStructureShape struct { + SDKShapeTraits bool +} + +type ConditionalStructShape struct { + Name *string `required:"true"` + SDKShapeTraits bool +} + +func TestNoErrors(t *testing.T) { + input := &StructShape{ + RequiredList: []*ConditionalStructShape{}, + RequiredMap: &map[string]*ConditionalStructShape{ + "key1": &ConditionalStructShape{Name: aws.String("Name")}, + "key2": &ConditionalStructShape{Name: aws.String("Name")}, + }, + RequiredBool: aws.Boolean(true), + OptionalStruct: &ConditionalStructShape{Name: aws.String("Name")}, + } + + req := aws.NewRequest(service, &aws.Operation{}, input, nil) + aws.ValidateParameters(req) + assert.NoError(t, req.Error) +} + +func TestMissingRequiredParameters(t *testing.T) { + input := &StructShape{} + req := aws.NewRequest(service, &aws.Operation{}, input, nil) + aws.ValidateParameters(req) + err := aws.Error(req.Error) + + assert.Error(t, err) + assert.Equal(t, "InvalidParameter", err.Code) + assert.Equal(t, "3 validation errors:\n- missing required parameter: RequiredList\n- missing required parameter: RequiredMap\n- missing required parameter: RequiredBool", err.Message) +} + +func TestNestedMissingRequiredParameters(t *testing.T) { + input := &StructShape{ + RequiredList: []*ConditionalStructShape{&ConditionalStructShape{}}, + RequiredMap: &map[string]*ConditionalStructShape{ + "key1": &ConditionalStructShape{Name: aws.String("Name")}, + "key2": &ConditionalStructShape{}, + }, + RequiredBool: aws.Boolean(true), + OptionalStruct: &ConditionalStructShape{}, + } + + req := aws.NewRequest(service, &aws.Operation{}, input, nil) + aws.ValidateParameters(req) + err := aws.Error(req.Error) + + assert.Error(t, err) + assert.Equal(t, "InvalidParameter", err.Code) + assert.Equal(t, "3 validation errors:\n- missing required parameter: RequiredList[0].Name\n- missing required parameter: RequiredMap[\"key2\"].Name\n- missing required parameter: OptionalStruct.Name", err.Message) + +} -- cgit v1.2.3-1-g7c22