summaryrefslogtreecommitdiffstats
path: root/Godeps/_workspace/src/github.com/awslabs/aws-sdk-go/aws/param_validator_test.go
blob: 08deca15a182a3d68eeb397d1dd3532132837cd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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)

}