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

     1  //go:build codegen
     2  // +build codegen
     3  
     4  package api
     5  
     6  import (
     7  	"path/filepath"
     8  	"reflect"
     9  	"strconv"
    10  	"testing"
    11  )
    12  
    13  func TestResolvedReferences(t *testing.T) {
    14  	json := `{
    15  		"operations": {
    16  			"OperationName": {
    17  				"input": { "shape": "TestName" }
    18  			}
    19  		},
    20  		"shapes": {
    21  			"TestName": {
    22  				"type": "structure",
    23  				"members": {
    24  					"memberName1": { "shape": "OtherTest" },
    25  					"memberName2": { "shape": "OtherTest" }
    26  				}
    27  			},
    28  			"OtherTest": { "type": "string" }
    29  		}
    30  	}`
    31  	a := API{}
    32  	a.AttachString(json)
    33  	if len(a.Shapes["OtherTest"].refs) != 2 {
    34  		t.Errorf("Expected %d, but received %d", 2, len(a.Shapes["OtherTest"].refs))
    35  	}
    36  }
    37  
    38  func TestTrimModelServiceVersions(t *testing.T) {
    39  	cases := []struct {
    40  		Paths   []string
    41  		Include []string
    42  		Exclude []string
    43  	}{
    44  		{
    45  			Paths: []string{
    46  				filepath.Join("foo", "baz", "2018-01-02", "api-2.json"),
    47  				filepath.Join("foo", "baz", "2019-01-02", "api-2.json"),
    48  				filepath.Join("foo", "baz", "2017-01-02", "api-2.json"),
    49  				filepath.Join("foo", "bar", "2019-01-02", "api-2.json"),
    50  				filepath.Join("foo", "bar", "2013-04-02", "api-2.json"),
    51  				filepath.Join("foo", "bar", "2019-01-03", "api-2.json"),
    52  			},
    53  			Include: []string{
    54  				filepath.Join("foo", "baz", "2019-01-02", "api-2.json"),
    55  				filepath.Join("foo", "bar", "2019-01-03", "api-2.json"),
    56  			},
    57  			Exclude: []string{
    58  				filepath.Join("foo", "baz", "2018-01-02", "api-2.json"),
    59  				filepath.Join("foo", "baz", "2017-01-02", "api-2.json"),
    60  				filepath.Join("foo", "bar", "2019-01-02", "api-2.json"),
    61  				filepath.Join("foo", "bar", "2013-04-02", "api-2.json"),
    62  			},
    63  		},
    64  	}
    65  
    66  	for i, c := range cases {
    67  		t.Run(strconv.Itoa(i), func(t *testing.T) {
    68  			include, exclude := TrimModelServiceVersions(c.Paths)
    69  			if e, a := c.Include, include; !reflect.DeepEqual(e, a) {
    70  				t.Errorf("expect include %v, got %v", e, a)
    71  			}
    72  			if e, a := c.Exclude, exclude; !reflect.DeepEqual(e, a) {
    73  				t.Errorf("expect exclude %v, got %v", e, a)
    74  			}
    75  		})
    76  	}
    77  }