github.com/aavshr/aws-sdk-go@v1.41.3/private/model/api/api_test.go (about)

     1  //go:build go1.8 && codegen
     2  // +build go1.8,codegen
     3  
     4  package api
     5  
     6  import (
     7  	"strings"
     8  	"testing"
     9  )
    10  
    11  func TestAPI_StructName(t *testing.T) {
    12  	origAliases := serviceAliaseNames
    13  	defer func() { serviceAliaseNames = origAliases }()
    14  
    15  	cases := map[string]struct {
    16  		Aliases    map[string]string
    17  		Metadata   Metadata
    18  		StructName string
    19  	}{
    20  		"FullName": {
    21  			Metadata: Metadata{
    22  				ServiceFullName: "Amazon Service Name-100",
    23  			},
    24  			StructName: "ServiceName100",
    25  		},
    26  		"Abbreviation": {
    27  			Metadata: Metadata{
    28  				ServiceFullName:     "Amazon Service Name-100",
    29  				ServiceAbbreviation: "AWS SN100",
    30  			},
    31  			StructName: "SN100",
    32  		},
    33  		"Lowercase Name": {
    34  			Metadata: Metadata{
    35  				EndpointPrefix:      "other",
    36  				ServiceFullName:     "AWS Lowercase service",
    37  				ServiceAbbreviation: "lowercase",
    38  			},
    39  			StructName: "Lowercase",
    40  		},
    41  		"Lowercase Name Mixed": {
    42  			Metadata: Metadata{
    43  				EndpointPrefix:      "other",
    44  				ServiceFullName:     "AWS Lowercase service",
    45  				ServiceAbbreviation: "lowercase name Goes heRe",
    46  			},
    47  			StructName: "LowercaseNameGoesHeRe",
    48  		},
    49  		"Alias": {
    50  			Aliases: map[string]string{
    51  				"elasticloadbalancing": "ELB",
    52  			},
    53  			Metadata: Metadata{
    54  				ServiceFullName: "Elastic Load Balancing",
    55  			},
    56  			StructName: "ELB",
    57  		},
    58  	}
    59  
    60  	for k, c := range cases {
    61  		t.Run(k, func(t *testing.T) {
    62  			serviceAliaseNames = c.Aliases
    63  
    64  			a := API{
    65  				Metadata: c.Metadata,
    66  			}
    67  
    68  			a.Setup()
    69  
    70  			if e, o := c.StructName, a.StructName(); e != o {
    71  				t.Errorf("expect %v structName, got %v", e, o)
    72  			}
    73  		})
    74  	}
    75  }
    76  
    77  func TestAPI_Setup_documentShapes(t *testing.T) {
    78  	api := API{
    79  		Shapes: map[string]*Shape{
    80  			"Document": {
    81  				Type:     "structure",
    82  				Document: true,
    83  			},
    84  		},
    85  	}
    86  
    87  	err := api.Setup()
    88  	if err == nil {
    89  		t.Fatalf("expect error, but got nil")
    90  	}
    91  	expect := "model contains document shapes"
    92  	if !strings.Contains(err.Error(), expect) {
    93  		t.Errorf("expect %s, got %v", expect, err)
    94  	}
    95  }