api_test.go 1.5 KB

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