github.com/aavshr/aws-sdk-go@v1.41.3/private/model/api/docstring_test.go (about) 1 //go:build go1.8 && codegen 2 // +build go1.8,codegen 3 4 package api 5 6 import ( 7 "testing" 8 ) 9 10 func TestDocstring(t *testing.T) { 11 cases := map[string]struct { 12 In string 13 Expect string 14 }{ 15 "non HTML": { 16 In: "Testing 1 2 3", 17 Expect: "// Testing 1 2 3", 18 }, 19 "link": { 20 In: `<a href="https://example.com">a link</a>`, 21 Expect: "// a link (https://example.com)", 22 }, 23 "link with space": { 24 In: `<a href=" https://example.com">a link</a>`, 25 Expect: "// a link (https://example.com)", 26 }, 27 "list HTML 01": { 28 In: "<ul><li>Testing 1 2 3</li> <li>FooBar</li></ul>", 29 Expect: "// * Testing 1 2 3\n// \n// * FooBar", 30 }, 31 "list HTML 02": { 32 In: "<ul> <li>Testing 1 2 3</li> <li>FooBar</li> </ul>", 33 Expect: "// * Testing 1 2 3\n// \n// * FooBar", 34 }, 35 "list HTML leading spaces": { 36 In: " <ul> <li>Testing 1 2 3</li> <li>FooBar</li> </ul>", 37 Expect: "// * Testing 1 2 3\n// \n// * FooBar", 38 }, 39 "list HTML paragraph": { 40 In: "<ul> <li> <p>Testing 1 2 3</p> </li><li> <p>FooBar</p></li></ul>", 41 Expect: "// * Testing 1 2 3\n// \n// * FooBar", 42 }, 43 "inline code HTML": { 44 In: "<ul> <li><code>Testing</code>: 1 2 3</li> <li>FooBar</li> </ul>", 45 Expect: "// * Testing: 1 2 3\n// \n// * FooBar", 46 }, 47 "complex list paragraph": { 48 In: "<ul> <li><p><code>FOO</code> Bar</p></li><li><p><code>Xyz</code> ABC</p></li></ul>", 49 Expect: "// * FOO Bar\n// \n// * Xyz ABC", 50 }, 51 "inline code in paragraph": { 52 In: "<p><code>Testing</code>: 1 2 3</p>", 53 Expect: "// Testing: 1 2 3", 54 }, 55 "root pre": { 56 In: "<pre><code>Testing</code></pre>", 57 Expect: "// Testing", 58 }, 59 "paragraph": { 60 In: "<p>Testing 1 2 3</p>", 61 Expect: "// Testing 1 2 3", 62 }, 63 "wrap lines": { 64 In: "<span data-target-type=\"operation\" data-service=\"secretsmanager\" data-target=\"CreateSecret\">CreateSecret</span> <span data-target-type=\"structure\" data-service=\"secretsmanager\" data-target=\"SecretListEntry\">SecretListEntry</span> <span data-target-type=\"structure\" data-service=\"secretsmanager\" data-target=\"CreateSecret$SecretName\">SecretName</span> <span data-target-type=\"structure\" data-service=\"secretsmanager\" data-target=\"SecretListEntry$KmsKeyId\">KmsKeyId</span>", 65 Expect: "// CreateSecret SecretListEntry SecretName KmsKeyId", 66 }, 67 "links with spaces": { 68 In: "<p> Deletes the replication configuration from the bucket. For information about replication configuration, see <a href=\" https://docs.aws.amazon.com/AmazonS3/latest/dev/crr.html\">Cross-Region Replication (CRR)</a> in the <i>Amazon S3 Developer Guide</i>. </p>", 69 Expect: "// Deletes the replication configuration from the bucket. For information about\n// replication configuration, see Cross-Region Replication (CRR) (https://docs.aws.amazon.com/AmazonS3/latest/dev/crr.html)\n// in the Amazon S3 Developer Guide.", 70 }, 71 } 72 73 for name, c := range cases { 74 t.Run(name, func(t *testing.T) { 75 t.Log("Input", c.In) 76 actual := docstring(c.In) 77 if e, a := c.Expect, actual; e != a { 78 t.Errorf("expect %q, got %q", e, a) 79 } 80 }) 81 } 82 } 83 84 func TestApiDocumentation_missingShapes(t *testing.T) { 85 docs := apiDocumentation{ 86 Service: "some service documentation", 87 Operations: map[string]string{ 88 "OperationOne": "some operation documentation", 89 "OperationTwo": "some more operation documentation", 90 }, 91 Shapes: map[string]shapeDocumentation{ 92 "ShapeOne": { 93 Base: "some shape documentation", 94 }, 95 "ShapeTwo": { 96 Base: "some more shape documentation", 97 Refs: map[string]string{ 98 "ShapeOne$shapeTwo": "shape ref document", 99 }, 100 }, 101 }, 102 } 103 104 api := API{ 105 Operations: map[string]*Operation{ 106 "OperationOne": {}, 107 }, 108 Shapes: map[string]*Shape{ 109 "ShapeOne": { 110 Type: "structure", 111 MemberRefs: map[string]*ShapeRef{}, 112 }, 113 }, 114 } 115 116 if err := docs.setup(&api); err != nil { 117 t.Fatalf("expect no error, got %v", err) 118 } 119 120 if _, ok := api.Operations["OperationTwo"]; ok { 121 t.Errorf("expect operation shape to not be added from document model") 122 } 123 124 if _, ok := api.Shapes["ShapeTwo"]; ok { 125 t.Errorf("expect shape to not be added from document model") 126 } 127 128 if _, ok := api.Shapes["ShapeOne"].MemberRefs["shapeTwo"]; ok { 129 t.Errorf("expect shape to not be added from document model") 130 } 131 }