load_test.go 1.9 KB

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