File: api_test.go

package info (click to toggle)
golang-github-aws-aws-sdk-go 1.49.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 312,636 kB
  • sloc: makefile: 120
file content (95 lines) | stat: -rw-r--r-- 1,935 bytes parent folder | download | duplicates (2)
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
86
87
88
89
90
91
92
93
94
95
//go:build go1.8 && codegen
// +build go1.8,codegen

package api

import (
	"strings"
	"testing"
)

func TestAPI_StructName(t *testing.T) {
	origAliases := serviceAliaseNames
	defer func() { serviceAliaseNames = 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",
		},
	}

	for k, c := range cases {
		t.Run(k, func(t *testing.T) {
			serviceAliaseNames = c.Aliases

			a := API{
				Metadata: c.Metadata,
			}

			a.Setup()

			if e, o := c.StructName, a.StructName(); e != o {
				t.Errorf("expect %v structName, got %v", e, o)
			}
		})
	}
}

func TestAPI_Setup_documentShapes(t *testing.T) {
	api := API{
		Shapes: map[string]*Shape{
			"Document": {
				Type:     "structure",
				Document: true,
			},
		},
	}

	err := api.Setup()
	if err == nil {
		t.Fatalf("expect error, but got nil")
	}
	expect := "model contains document shapes"
	if !strings.Contains(err.Error(), expect) {
		t.Errorf("expect %s, got %v", expect, err)
	}
}