func TestMissingRequiredParameters(t *testing.T) { input := &StructShape{} req := aws.NewRequest(service, &aws.Operation{}, input, nil) aws.ValidateParameters(req) assert.Error(t, req.Error) assert.Equal(t, "InvalidParameter", req.Error.(awserr.Error).Code()) assert.Equal(t, "3 validation errors:\n- missing required parameter: RequiredList\n- missing required parameter: RequiredMap\n- missing required parameter: RequiredBool", req.Error.(awserr.Error).Message()) }
func TestValidateEndpointHandlerErrorRegion(t *testing.T) { os.Clearenv() svc := service.New(nil) svc.Handlers.Clear() svc.Handlers.Validate.PushBackNamed(corehandlers.ValidateEndpointHandler) req := svc.NewRequest(&request.Operation{Name: "Operation"}, nil, nil) err := req.Build() assert.Error(t, err) assert.Equal(t, aws.ErrMissingRegion, err) }
func TestValidateEndpointHandlerErrorRegion(t *testing.T) { os.Clearenv() svc := NewService(nil) svc.Handlers.Clear() svc.Handlers.Validate.PushBack(ValidateEndpointHandler) req := NewRequest(svc, &Operation{Name: "Operation"}, nil, nil) err := req.Build() assert.Error(t, err) assert.Equal(t, ErrMissingRegion, err) }
func TestSendHandlerError(t *testing.T) { svc := service.New(&aws.Config{ HTTPClient: &http.Client{ Transport: &testSendHandlerTransport{}, }, }) svc.Handlers.Clear() svc.Handlers.Send.PushBackNamed(corehandlers.SendHandler) r := svc.NewRequest(&request.Operation{Name: "Operation"}, nil, nil) r.Send() assert.Error(t, r.Error) assert.NotNil(t, r.HTTPResponse) }
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) assert.Error(t, req.Error) assert.Equal(t, "InvalidParameter", req.Error.(awserr.Error).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", req.Error.(awserr.Error).Message()) }
func TestEC2RoleProviderFailAssume(t *testing.T) { server := initTestServer("2014-12-16T01:51:37Z", true) defer server.Close() p := &ec2rolecreds.EC2RoleProvider{ Client: ec2metadata.New(&ec2metadata.Config{Endpoint: aws.String(server.URL + "/latest")}), } creds, err := p.Retrieve() assert.Error(t, err, "Expect error") e := err.(awserr.Error) assert.Equal(t, "ErrorCode", e.Code()) assert.Equal(t, "ErrorMsg", e.Message()) assert.Nil(t, e.OrigErr()) assert.Equal(t, "", creds.AccessKeyID, "Expect access key ID to match") assert.Equal(t, "", creds.SecretAccessKey, "Expect secret access key to match") assert.Equal(t, "", creds.SessionToken, "Expect session token to match") }