|
1 |
| -// +build 1.6,codegen |
| 1 | +// +build go1.8,codegen |
2 | 2 |
|
3 | 3 | package api
|
4 | 4 |
|
5 | 5 | import (
|
6 | 6 | "testing"
|
7 | 7 | )
|
8 | 8 |
|
9 |
| -func TestStructNameWithFullName(t *testing.T) { |
10 |
| - a := API{ |
11 |
| - Metadata: Metadata{ |
12 |
| - ServiceFullName: "Amazon Service Name-100", |
13 |
| - }, |
14 |
| - } |
15 |
| - if a.StructName() != "ServiceName100" { |
16 |
| - t.Errorf("API struct name should have been %s, but received %s", "ServiceName100", a.StructName()) |
17 |
| - } |
18 |
| -} |
| 9 | +func TestAPI_StructName(t *testing.T) { |
| 10 | + origAliases := serviceAliases |
| 11 | + defer func() { serviceAliases = origAliases }() |
19 | 12 |
|
20 |
| -func TestStructNameWithAbbreviation(t *testing.T) { |
21 |
| - a := API{ |
22 |
| - Metadata: Metadata{ |
23 |
| - ServiceFullName: "AWS Service Name-100", |
24 |
| - ServiceAbbreviation: "AWS SN100", |
| 13 | + cases := map[string]struct { |
| 14 | + Aliases map[string]string |
| 15 | + Metadata Metadata |
| 16 | + StructName string |
| 17 | + }{ |
| 18 | + "FullName": { |
| 19 | + Metadata: Metadata{ |
| 20 | + ServiceFullName: "Amazon Service Name-100", |
| 21 | + }, |
| 22 | + StructName: "ServiceName100", |
| 23 | + }, |
| 24 | + "Abbreviation": { |
| 25 | + Metadata: Metadata{ |
| 26 | + ServiceFullName: "Amazon Service Name-100", |
| 27 | + ServiceAbbreviation: "AWS SN100", |
| 28 | + }, |
| 29 | + StructName: "SN100", |
| 30 | + }, |
| 31 | + "Lowercase Name": { |
| 32 | + Metadata: Metadata{ |
| 33 | + EndpointPrefix: "other", |
| 34 | + ServiceFullName: "AWS Lowercase service", |
| 35 | + ServiceAbbreviation: "lowercase", |
| 36 | + }, |
| 37 | + StructName: "Lowercase", |
| 38 | + }, |
| 39 | + "Lowercase Name Mixed": { |
| 40 | + Metadata: Metadata{ |
| 41 | + EndpointPrefix: "other", |
| 42 | + ServiceFullName: "AWS Lowercase service", |
| 43 | + ServiceAbbreviation: "lowercase name Goes heRe", |
| 44 | + }, |
| 45 | + StructName: "LowercaseNameGoesHeRe", |
| 46 | + }, |
| 47 | + "Alias": { |
| 48 | + Aliases: map[string]string{ |
| 49 | + "elasticloadbalancing": "ELB", |
| 50 | + }, |
| 51 | + Metadata: Metadata{ |
| 52 | + ServiceFullName: "Elastic Load Balancing", |
| 53 | + }, |
| 54 | + StructName: "ELB", |
25 | 55 | },
|
26 | 56 | }
|
27 |
| - if a.StructName() != "SN100" { |
28 |
| - t.Errorf("API struct name should have been %s, but received %s", "SN100", a.StructName()) |
29 |
| - } |
30 |
| -} |
31 | 57 |
|
32 |
| -func TestStructNameForExceptions(t *testing.T) { |
33 |
| - serviceAliases = map[string]string{} |
34 |
| - serviceAliases["elasticloadbalancing"] = "ELB" |
35 |
| - serviceAliases["config"] = "ConfigService" |
| 58 | + for k, c := range cases { |
| 59 | + t.Run(k, func(t *testing.T) { |
| 60 | + serviceAliases = c.Aliases |
36 | 61 |
|
37 |
| - a := API{ |
38 |
| - Metadata: Metadata{ |
39 |
| - ServiceFullName: "Elastic Load Balancing", |
40 |
| - }, |
41 |
| - } |
42 |
| - if a.StructName() != "ELB" { |
43 |
| - t.Errorf("API struct name should have been %s, but received %s", "ELB", a.StructName()) |
44 |
| - } |
| 62 | + a := API{ |
| 63 | + Metadata: c.Metadata, |
| 64 | + } |
45 | 65 |
|
46 |
| - a = API{ |
47 |
| - Metadata: Metadata{ |
48 |
| - ServiceFullName: "AWS Config", |
49 |
| - }, |
50 |
| - } |
51 |
| - if a.StructName() != "ConfigService" { |
52 |
| - t.Errorf("API struct name should have been %s, but received %s", "ConfigService", a.StructName()) |
| 66 | + if e, o := c.StructName, a.StructName(); e != o { |
| 67 | + t.Errorf("expect %v structName, got %v", e, o) |
| 68 | + } |
| 69 | + }) |
53 | 70 | }
|
54 | 71 | }
|
0 commit comments