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