passes_test.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. // +build go1.8,codegen
  2. package api
  3. import (
  4. "reflect"
  5. "strconv"
  6. "strings"
  7. "testing"
  8. )
  9. func TestUniqueInputAndOutputs(t *testing.T) {
  10. const serviceName = "FooService"
  11. shamelist[serviceName] = map[string]persistAPIType{
  12. "OpOutputNoRename": {
  13. output: true,
  14. },
  15. "OpInputNoRename": {
  16. input: true,
  17. },
  18. "OpBothNoRename": {
  19. input: true,
  20. output: true,
  21. },
  22. }
  23. cases := [][]struct {
  24. expectedInput string
  25. expectedOutput string
  26. operation string
  27. input string
  28. output string
  29. }{
  30. {
  31. {
  32. expectedInput: "FooOperationInput",
  33. expectedOutput: "FooOperationOutput",
  34. operation: "FooOperation",
  35. input: "FooInputShape",
  36. output: "FooOutputShape",
  37. },
  38. {
  39. expectedInput: "BarOperationInput",
  40. expectedOutput: "BarOperationOutput",
  41. operation: "BarOperation",
  42. input: "FooInputShape",
  43. output: "FooOutputShape",
  44. },
  45. },
  46. {
  47. {
  48. expectedInput: "FooOperationInput",
  49. expectedOutput: "FooOperationOutput",
  50. operation: "FooOperation",
  51. input: "FooInputShape",
  52. output: "FooOutputShape",
  53. },
  54. {
  55. expectedInput: "OpOutputNoRenameInput",
  56. expectedOutput: "OpOutputNoRenameOutputShape",
  57. operation: "OpOutputNoRename",
  58. input: "OpOutputNoRenameInputShape",
  59. output: "OpOutputNoRenameOutputShape",
  60. },
  61. },
  62. {
  63. {
  64. expectedInput: "FooOperationInput",
  65. expectedOutput: "FooOperationOutput",
  66. operation: "FooOperation",
  67. input: "FooInputShape",
  68. output: "FooOutputShape",
  69. },
  70. {
  71. expectedInput: "OpInputNoRenameInputShape",
  72. expectedOutput: "OpInputNoRenameOutput",
  73. operation: "OpInputNoRename",
  74. input: "OpInputNoRenameInputShape",
  75. output: "OpInputNoRenameOutputShape",
  76. },
  77. },
  78. {
  79. {
  80. expectedInput: "FooOperationInput",
  81. expectedOutput: "FooOperationOutput",
  82. operation: "FooOperation",
  83. input: "FooInputShape",
  84. output: "FooOutputShape",
  85. },
  86. {
  87. expectedInput: "OpInputNoRenameInputShape",
  88. expectedOutput: "OpInputNoRenameOutputShape",
  89. operation: "OpBothNoRename",
  90. input: "OpInputNoRenameInputShape",
  91. output: "OpInputNoRenameOutputShape",
  92. },
  93. },
  94. }
  95. for i, c := range cases {
  96. t.Run(strconv.Itoa(i), func(t *testing.T) {
  97. a := &API{
  98. name: serviceName,
  99. Operations: map[string]*Operation{},
  100. Shapes: map[string]*Shape{},
  101. }
  102. expected := map[string][]string{}
  103. for _, op := range c {
  104. o := &Operation{
  105. Name: op.operation,
  106. ExportedName: op.operation,
  107. InputRef: ShapeRef{
  108. API: a,
  109. ShapeName: op.input,
  110. Shape: &Shape{
  111. API: a,
  112. ShapeName: op.input,
  113. },
  114. },
  115. OutputRef: ShapeRef{
  116. API: a,
  117. ShapeName: op.input,
  118. Shape: &Shape{
  119. API: a,
  120. ShapeName: op.input,
  121. },
  122. },
  123. }
  124. o.InputRef.Shape.refs = append(o.InputRef.Shape.refs, &o.InputRef)
  125. o.OutputRef.Shape.refs = append(o.OutputRef.Shape.refs, &o.OutputRef)
  126. a.Operations[o.Name] = o
  127. a.Shapes[op.input] = o.InputRef.Shape
  128. a.Shapes[op.output] = o.OutputRef.Shape
  129. expected[op.operation] = append(expected[op.operation],
  130. op.expectedInput,
  131. op.expectedOutput,
  132. )
  133. }
  134. a.fixStutterNames()
  135. a.applyShapeNameAliases()
  136. a.createInputOutputShapes()
  137. for k, v := range expected {
  138. if a.Operations[k].InputRef.Shape.ShapeName != v[0] {
  139. t.Errorf("Error %s case: Expected %q, but received %q", k, v[0], a.Operations[k].InputRef.Shape.ShapeName)
  140. }
  141. if a.Operations[k].OutputRef.Shape.ShapeName != v[1] {
  142. t.Errorf("Error %s case: Expected %q, but received %q", k, v[1], a.Operations[k].OutputRef.Shape.ShapeName)
  143. }
  144. }
  145. })
  146. }
  147. }
  148. func TestCollidingFields(t *testing.T) {
  149. cases := map[string]struct {
  150. MemberRefs map[string]*ShapeRef
  151. Expect []string
  152. IsException bool
  153. }{
  154. "SimpleMembers": {
  155. MemberRefs: map[string]*ShapeRef{
  156. "Code": {},
  157. "Foo": {},
  158. "GoString": {},
  159. "Message": {},
  160. "OrigErr": {},
  161. "SetFoo": {},
  162. "String": {},
  163. "Validate": {},
  164. },
  165. Expect: []string{
  166. "Code",
  167. "Foo",
  168. "GoString_",
  169. "Message",
  170. "OrigErr",
  171. "SetFoo_",
  172. "String_",
  173. "Validate_",
  174. },
  175. },
  176. "ExceptionShape": {
  177. IsException: true,
  178. MemberRefs: map[string]*ShapeRef{
  179. "Code": {},
  180. "Message": {},
  181. "OrigErr": {},
  182. "Other": {},
  183. "String": {},
  184. },
  185. Expect: []string{
  186. "Code_",
  187. "Message_",
  188. "OrigErr_",
  189. "Other",
  190. "String_",
  191. },
  192. },
  193. }
  194. for k, c := range cases {
  195. t.Run(k, func(t *testing.T) {
  196. a := &API{
  197. Shapes: map[string]*Shape{
  198. "shapename": {
  199. ShapeName: k,
  200. MemberRefs: c.MemberRefs,
  201. Exception: c.IsException,
  202. },
  203. },
  204. }
  205. a.renameCollidingFields()
  206. for i, name := range a.Shapes["shapename"].MemberNames() {
  207. if e, a := c.Expect[i], name; e != a {
  208. t.Errorf("expect %v, got %v", e, a)
  209. }
  210. }
  211. })
  212. }
  213. }
  214. func TestSupressHTTP2EventStreams(t *testing.T) {
  215. const baseModel = `
  216. {
  217. "version":"2.0",
  218. "metadata":{
  219. "apiVersion":"0000-00-00",
  220. "endpointPrefix":"rpcservice",
  221. "jsonVersion":"1.1",
  222. "protocol":"json",
  223. "protocolSettings":{"h2":"{h2Option}"},
  224. "serviceAbbreviation":"RPCService",
  225. "serviceFullName":"RPC Service",
  226. "serviceId":"RPCService",
  227. "signatureVersion":"v4",
  228. "targetPrefix":"RPCService_00000000",
  229. "uid":"RPCService-0000-00-00"
  230. },
  231. "operations":{
  232. "BarOp":{
  233. "name":"BarOp",
  234. "http":{
  235. "method":"POST",
  236. "requestUri":"/"
  237. },
  238. "input":{"shape": "BarOpRequest"},
  239. "output":{"shape":"BarOpResponse"}
  240. },
  241. "EventStreamOp":{
  242. "name":"EventStreamOp",
  243. "http":{
  244. "method":"POST",
  245. "requestUri":"/"
  246. },
  247. "input":{"shape": "EventStreamOpRequest"},
  248. "output":{"shape":"EventStreamOpResponse"}
  249. },
  250. "FooOp":{
  251. "name":"FooOp",
  252. "http":{
  253. "method":"POST",
  254. "requestUri":"/"
  255. },
  256. "input":{"shape": "FooOpRequest"},
  257. "output":{"shape":"FooOpResponse"}
  258. }
  259. },
  260. "shapes":{
  261. "BarOpRequest":{
  262. "type":"structure",
  263. "members":{}
  264. },
  265. "BarOpResponse":{
  266. "type":"structure",
  267. "members":{}
  268. },
  269. "EventStreamOpRequest":{
  270. "type":"structure",
  271. "members":{
  272. }
  273. },
  274. "EventStreamOpResponse":{
  275. "type":"structure",
  276. "members":{
  277. "EventStream":{"shape":"EventStream"}
  278. }
  279. },
  280. "FooOpRequest":{
  281. "type":"structure",
  282. "members":{}
  283. },
  284. "FooOpResponse":{
  285. "type":"structure",
  286. "members":{}
  287. },
  288. "EventStream":{
  289. "type":"structure",
  290. "members":{
  291. "Empty":{"shape":"EmptyEvent"}
  292. },
  293. "eventstream":true
  294. },
  295. "EmptyEvent": {
  296. "type":"structure",
  297. "members":{},
  298. "event": true
  299. }
  300. }
  301. }
  302. `
  303. cases := map[string]struct {
  304. Model string
  305. ExpectOps []string
  306. ExpectShapes []string
  307. }{
  308. "control": {
  309. Model: strings.Replace(baseModel, "{h2Option}", "", -1),
  310. ExpectOps: []string{"BarOp", "EventStreamOp", "FooOp"},
  311. ExpectShapes: []string{
  312. "BarOpInput", "BarOpOutput", "EmptyEvent",
  313. "EventStreamOpEventStream", "EventStreamOpInput",
  314. "EventStreamOpOutput", "FooOpInput", "FooOpOutput",
  315. },
  316. },
  317. "HTTP/2 with EventStreams": {
  318. Model: strings.Replace(baseModel, "{h2Option}", "eventstream", 1),
  319. ExpectOps: []string{"BarOp", "FooOp"},
  320. ExpectShapes: []string{
  321. "BarOpInput", "BarOpOutput", "FooOpInput", "FooOpOutput",
  322. },
  323. },
  324. "HTTP/2 with optional": {
  325. Model: strings.Replace(baseModel, "{h2Option}", "optional", 1),
  326. ExpectOps: []string{"BarOp", "EventStreamOp", "FooOp"},
  327. ExpectShapes: []string{
  328. "BarOpInput", "BarOpOutput", "EmptyEvent",
  329. "EventStreamOpEventStream", "EventStreamOpInput",
  330. "EventStreamOpOutput", "FooOpInput", "FooOpOutput",
  331. },
  332. },
  333. }
  334. for name, c := range cases {
  335. t.Run(name, func(t *testing.T) {
  336. var a API
  337. a.AttachString(c.Model)
  338. a.APIGoCode()
  339. if e, a := c.ExpectOps, a.OperationNames(); !reflect.DeepEqual(e, a) {
  340. t.Errorf("expect %v ops, got %v", e, a)
  341. }
  342. if e, a := c.ExpectShapes, a.ShapeNames(); !reflect.DeepEqual(e, a) {
  343. t.Errorf("expect %v shapes, got %v", e, a)
  344. }
  345. })
  346. }
  347. }
  348. func TestCreateInputOutputShapes(t *testing.T) {
  349. meta := Metadata{
  350. APIVersion: "0000-00-00",
  351. EndpointPrefix: "rpcservice",
  352. JSONVersion: "1.1",
  353. Protocol: "json",
  354. ServiceAbbreviation: "RPCService",
  355. ServiceFullName: "RPC Service",
  356. ServiceID: "RPCService",
  357. SignatureVersion: "v4",
  358. TargetPrefix: "RPCService_00000000",
  359. UID: "RPCService-0000-00-00",
  360. }
  361. type OpExpect struct {
  362. Input string
  363. Output string
  364. }
  365. cases := map[string]struct {
  366. API *API
  367. ExpectOps map[string]OpExpect
  368. ExpectShapes []string
  369. }{
  370. "allRename": {
  371. API: &API{Metadata: meta,
  372. Operations: map[string]*Operation{
  373. "FirstOp": {Name: "FirstOp",
  374. InputRef: ShapeRef{ShapeName: "FirstOpRequest"},
  375. OutputRef: ShapeRef{ShapeName: "FirstOpResponse"},
  376. },
  377. "SecondOp": {Name: "SecondOp",
  378. InputRef: ShapeRef{ShapeName: "SecondOpRequest"},
  379. OutputRef: ShapeRef{ShapeName: "SecondOpResponse"},
  380. },
  381. },
  382. Shapes: map[string]*Shape{
  383. "FirstOpRequest": {ShapeName: "FirstOpRequest", Type: "structure"},
  384. "FirstOpResponse": {ShapeName: "FirstOpResponse", Type: "structure"},
  385. "SecondOpRequest": {ShapeName: "SecondOpRequest", Type: "structure"},
  386. "SecondOpResponse": {ShapeName: "SecondOpResponse", Type: "structure"},
  387. },
  388. },
  389. ExpectOps: map[string]OpExpect{
  390. "FirstOp": {
  391. Input: "FirstOpInput",
  392. Output: "FirstOpOutput",
  393. },
  394. "SecondOp": {
  395. Input: "SecondOpInput",
  396. Output: "SecondOpOutput",
  397. },
  398. },
  399. ExpectShapes: []string{
  400. "FirstOpInput", "FirstOpOutput",
  401. "SecondOpInput", "SecondOpOutput",
  402. },
  403. },
  404. "noRename": {
  405. API: &API{Metadata: meta,
  406. Operations: map[string]*Operation{
  407. "FirstOp": {Name: "FirstOp",
  408. InputRef: ShapeRef{ShapeName: "FirstOpInput"},
  409. OutputRef: ShapeRef{ShapeName: "FirstOpOutput"},
  410. },
  411. "SecondOp": {Name: "SecondOp",
  412. InputRef: ShapeRef{ShapeName: "SecondOpInput"},
  413. OutputRef: ShapeRef{ShapeName: "SecondOpOutput"},
  414. },
  415. },
  416. Shapes: map[string]*Shape{
  417. "FirstOpInput": {ShapeName: "FirstOpInput", Type: "structure"},
  418. "FirstOpOutput": {ShapeName: "FirstOpOutput", Type: "structure"},
  419. "SecondOpInput": {ShapeName: "SecondOpInput", Type: "structure"},
  420. "SecondOpOutput": {ShapeName: "SecondOpOutput", Type: "structure"},
  421. },
  422. },
  423. ExpectOps: map[string]OpExpect{
  424. "FirstOp": {
  425. Input: "FirstOpInput",
  426. Output: "FirstOpOutput",
  427. },
  428. "SecondOp": {
  429. Input: "SecondOpInput",
  430. Output: "SecondOpOutput",
  431. },
  432. },
  433. ExpectShapes: []string{
  434. "FirstOpInput", "FirstOpOutput",
  435. "SecondOpInput", "SecondOpOutput",
  436. },
  437. },
  438. "renameWithNested": {
  439. API: &API{Metadata: meta,
  440. Operations: map[string]*Operation{
  441. "FirstOp": {Name: "FirstOp",
  442. InputRef: ShapeRef{ShapeName: "FirstOpWriteMe"},
  443. OutputRef: ShapeRef{ShapeName: "FirstOpReadMe"},
  444. },
  445. "SecondOp": {Name: "SecondOp",
  446. InputRef: ShapeRef{ShapeName: "SecondOpWriteMe"},
  447. OutputRef: ShapeRef{ShapeName: "SecondOpReadMe"},
  448. },
  449. },
  450. Shapes: map[string]*Shape{
  451. "FirstOpWriteMe": {ShapeName: "FirstOpWriteMe", Type: "structure",
  452. MemberRefs: map[string]*ShapeRef{
  453. "Foo": {ShapeName: "String"},
  454. },
  455. },
  456. "FirstOpReadMe": {ShapeName: "FirstOpReadMe", Type: "structure",
  457. MemberRefs: map[string]*ShapeRef{
  458. "Bar": {ShapeName: "Struct"},
  459. "Once": {ShapeName: "Once"},
  460. },
  461. },
  462. "SecondOpWriteMe": {ShapeName: "SecondOpWriteMe", Type: "structure"},
  463. "SecondOpReadMe": {ShapeName: "SecondOpReadMe", Type: "structure"},
  464. "Once": {ShapeName: "Once", Type: "string"},
  465. "String": {ShapeName: "String", Type: "string"},
  466. "Struct": {ShapeName: "Struct", Type: "structure",
  467. MemberRefs: map[string]*ShapeRef{
  468. "Foo": {ShapeName: "String"},
  469. "Bar": {ShapeName: "Struct"},
  470. },
  471. },
  472. },
  473. },
  474. ExpectOps: map[string]OpExpect{
  475. "FirstOp": {
  476. Input: "FirstOpInput",
  477. Output: "FirstOpOutput",
  478. },
  479. "SecondOp": {
  480. Input: "SecondOpInput",
  481. Output: "SecondOpOutput",
  482. },
  483. },
  484. ExpectShapes: []string{
  485. "FirstOpInput", "FirstOpOutput",
  486. "Once",
  487. "SecondOpInput", "SecondOpOutput",
  488. "String", "Struct",
  489. },
  490. },
  491. "aliasedInput": {
  492. API: &API{Metadata: meta,
  493. Operations: map[string]*Operation{
  494. "FirstOp": {Name: "FirstOp",
  495. InputRef: ShapeRef{ShapeName: "FirstOpRequest"},
  496. OutputRef: ShapeRef{ShapeName: "FirstOpResponse"},
  497. },
  498. },
  499. Shapes: map[string]*Shape{
  500. "FirstOpRequest": {ShapeName: "FirstOpRequest", Type: "structure",
  501. AliasedShapeName: true,
  502. },
  503. "FirstOpResponse": {ShapeName: "FirstOpResponse", Type: "structure"},
  504. },
  505. },
  506. ExpectOps: map[string]OpExpect{
  507. "FirstOp": {
  508. Input: "FirstOpRequest",
  509. Output: "FirstOpOutput",
  510. },
  511. },
  512. ExpectShapes: []string{
  513. "FirstOpOutput", "FirstOpRequest",
  514. },
  515. },
  516. "aliasedOutput": {
  517. API: &API{Metadata: meta,
  518. Operations: map[string]*Operation{
  519. "FirstOp": {Name: "FirstOp",
  520. InputRef: ShapeRef{ShapeName: "FirstOpRequest"},
  521. OutputRef: ShapeRef{ShapeName: "FirstOpResponse"},
  522. },
  523. },
  524. Shapes: map[string]*Shape{
  525. "FirstOpRequest": {ShapeName: "FirstOpRequest", Type: "structure"},
  526. "FirstOpResponse": {ShapeName: "FirstOpResponse", Type: "structure",
  527. AliasedShapeName: true,
  528. },
  529. },
  530. },
  531. ExpectOps: map[string]OpExpect{
  532. "FirstOp": {
  533. Input: "FirstOpInput",
  534. Output: "FirstOpResponse",
  535. },
  536. },
  537. ExpectShapes: []string{
  538. "FirstOpInput", "FirstOpResponse",
  539. },
  540. },
  541. "resusedShape": {
  542. API: &API{Metadata: meta,
  543. Operations: map[string]*Operation{
  544. "FirstOp": {Name: "FirstOp",
  545. InputRef: ShapeRef{ShapeName: "FirstOpRequest"},
  546. OutputRef: ShapeRef{ShapeName: "ReusedShape"},
  547. },
  548. },
  549. Shapes: map[string]*Shape{
  550. "FirstOpRequest": {ShapeName: "FirstOpRequest", Type: "structure",
  551. MemberRefs: map[string]*ShapeRef{
  552. "Foo": {ShapeName: "ReusedShape"},
  553. "ooF": {ShapeName: "ReusedShapeList"},
  554. },
  555. },
  556. "ReusedShape": {ShapeName: "ReusedShape", Type: "structure"},
  557. "ReusedShapeList": {ShapeName: "ReusedShapeList", Type: "list",
  558. MemberRef: ShapeRef{ShapeName: "ReusedShape"},
  559. },
  560. },
  561. },
  562. ExpectOps: map[string]OpExpect{
  563. "FirstOp": {
  564. Input: "FirstOpInput",
  565. Output: "FirstOpOutput",
  566. },
  567. },
  568. ExpectShapes: []string{
  569. "FirstOpInput", "FirstOpOutput",
  570. "ReusedShape", "ReusedShapeList",
  571. },
  572. },
  573. "aliasedResusedShape": {
  574. API: &API{Metadata: meta,
  575. Operations: map[string]*Operation{
  576. "FirstOp": {Name: "FirstOp",
  577. InputRef: ShapeRef{ShapeName: "FirstOpRequest"},
  578. OutputRef: ShapeRef{ShapeName: "ReusedShape"},
  579. },
  580. },
  581. Shapes: map[string]*Shape{
  582. "FirstOpRequest": {ShapeName: "FirstOpRequest", Type: "structure",
  583. MemberRefs: map[string]*ShapeRef{
  584. "Foo": {ShapeName: "ReusedShape"},
  585. "ooF": {ShapeName: "ReusedShapeList"},
  586. },
  587. },
  588. "ReusedShape": {ShapeName: "ReusedShape", Type: "structure",
  589. AliasedShapeName: true,
  590. },
  591. "ReusedShapeList": {ShapeName: "ReusedShapeList", Type: "list",
  592. MemberRef: ShapeRef{ShapeName: "ReusedShape"},
  593. },
  594. },
  595. },
  596. ExpectOps: map[string]OpExpect{
  597. "FirstOp": {
  598. Input: "FirstOpInput",
  599. Output: "ReusedShape",
  600. },
  601. },
  602. ExpectShapes: []string{
  603. "FirstOpInput",
  604. "ReusedShape", "ReusedShapeList",
  605. },
  606. },
  607. "unsetInput": {
  608. API: &API{Metadata: meta,
  609. Operations: map[string]*Operation{
  610. "FirstOp": {Name: "FirstOp",
  611. OutputRef: ShapeRef{ShapeName: "FirstOpResponse"},
  612. },
  613. },
  614. Shapes: map[string]*Shape{
  615. "FirstOpResponse": {ShapeName: "FirstOpResponse", Type: "structure"},
  616. },
  617. },
  618. ExpectOps: map[string]OpExpect{
  619. "FirstOp": {
  620. Input: "FirstOpInput",
  621. Output: "FirstOpOutput",
  622. },
  623. },
  624. ExpectShapes: []string{
  625. "FirstOpInput", "FirstOpOutput",
  626. },
  627. },
  628. "unsetOutput": {
  629. API: &API{Metadata: meta,
  630. Operations: map[string]*Operation{
  631. "FirstOp": {Name: "FirstOp",
  632. InputRef: ShapeRef{ShapeName: "FirstOpRequest"},
  633. },
  634. },
  635. Shapes: map[string]*Shape{
  636. "FirstOpRequest": {ShapeName: "FirstOpRequest", Type: "structure"},
  637. },
  638. },
  639. ExpectOps: map[string]OpExpect{
  640. "FirstOp": {
  641. Input: "FirstOpInput",
  642. Output: "FirstOpOutput",
  643. },
  644. },
  645. ExpectShapes: []string{
  646. "FirstOpInput", "FirstOpOutput",
  647. },
  648. },
  649. }
  650. for name, c := range cases {
  651. t.Run(name, func(t *testing.T) {
  652. a := c.API
  653. a.Setup()
  654. for opName, op := range a.Operations {
  655. if e, a := op.InputRef.ShapeName, op.InputRef.Shape.ShapeName; e != a {
  656. t.Errorf("expect input ref and shape names to match, %s, %s", e, a)
  657. }
  658. if e, a := c.ExpectOps[opName].Input, op.InputRef.ShapeName; e != a {
  659. t.Errorf("expect %v input shape, got %v", e, a)
  660. }
  661. if e, a := op.OutputRef.ShapeName, op.OutputRef.Shape.ShapeName; e != a {
  662. t.Errorf("expect output ref and shape names to match, %s, %s", e, a)
  663. }
  664. if e, a := c.ExpectOps[opName].Output, op.OutputRef.ShapeName; e != a {
  665. t.Errorf("expect %v output shape, got %v", e, a)
  666. }
  667. }
  668. if e, a := c.ExpectShapes, a.ShapeNames(); !reflect.DeepEqual(e, a) {
  669. t.Errorf("expect %v shapes, got %v", e, a)
  670. }
  671. })
  672. }
  673. }