github.com/MontFerret/ferret@v0.18.0/pkg/drivers/http/document_test.go (about) 1 package http_test 2 3 import ( 4 "bytes" 5 "context" 6 "testing" 7 8 "github.com/MontFerret/ferret/pkg/drivers/http" 9 10 "github.com/PuerkitoBio/goquery" 11 . "github.com/smartystreets/goconvey/convey" 12 ) 13 14 func TestDocument(t *testing.T) { 15 doc := ` 16 <html lang="en"><head> 17 <meta charset="utf-8"> 18 <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> 19 <meta name="description" content=""> 20 <meta name="author" content=""> 21 </head> 22 <body> 23 <header> 24 <div class="collapse bg-dark" id="navbarHeader"> 25 <div class="container"> 26 <div class="row"> 27 <div class="col-sm-8 col-md-7 py-4"> 28 <h4 class="text-white">About</h4> 29 <p class="text-muted">Add some information about the album below, the author, or any other background context. Make it a few sentences long so folks can pick up some informative tidbits. Then, link them off to some social networking sites or contact information.</p> 30 </div> 31 <div class="col-sm-4 offset-md-1 py-4"> 32 <h4 class="text-white">Contact</h4> 33 <ul class="list-unstyled"> 34 <li><a href="#" class="text-white">Follow on Twitter</a></li> 35 <li><a href="#" class="text-white">Like on Facebook</a></li> 36 <li><a href="#" class="text-white">Email me</a></li> 37 </ul> 38 </div> 39 </div> 40 </div> 41 </div> 42 <div class="navbar navbar-dark bg-dark shadow-sm"> 43 <div class="container d-flex justify-content-between"> 44 <a href="#" class="navbar-brand d-flex align-items-center"> 45 <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="mr-2"><path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z"></path><circle cx="12" cy="13" r="4"></circle></svg> 46 <strong>Album</strong> 47 </a> 48 <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarHeader" aria-controls="navbarHeader" aria-expanded="false" aria-label="Toggle navigation"> 49 <span class="navbar-toggler-icon"></span> 50 </button> 51 </div> 52 </div> 53 </header> 54 55 <main role="main"> 56 57 <section class="jumbotron text-center"> 58 <div class="container"> 59 <h1 class="jumbotron-heading">Album example</h1> 60 <p class="lead text-muted">Something short and leading about the collection below—its contents, the creator, etc. Make it short and sweet, but not too short so folks don't simply skip over it entirely.</p> 61 <p> 62 <a href="#" class="btn btn-primary my-2">Main call to action</a> 63 <a href="#" class="btn btn-secondary my-2">Secondary action</a> 64 </p> 65 </div> 66 </section> 67 68 <div class="album py-5 bg-light"> 69 <div class="container"> 70 71 <div class="row"> 72 <div class="col-md-4"> 73 <div class="card mb-4 shadow-sm"> 74 <img class="card-img-top" data-src="holder.js/100px225?theme=thumb&bg=55595c&fg=eceeef&text=Thumbnail" alt="Thumbnail [100%x225]" style="height: 225px; width: 100%; display: block;" src="data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22348%22%20height%3D%22225%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20348%20225%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_165ea5071fe%20text%20%7B%20fill%3A%23eceeef%3Bfont-weight%3Abold%3Bfont-family%3AArial%2C%20Helvetica%2C%20Open%20Sans%2C%20sans-serif%2C%20monospace%3Bfont-size%3A17pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_165ea5071fe%22%3E%3Crect%20width%3D%22348%22%20height%3D%22225%22%20fill%3D%22%2355595c%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%22116.71875%22%20y%3D%22120.15%22%3EThumbnail%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E" data-holder-rendered="true"> 75 <div class="card-body"> 76 <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> 77 <div class="d-flex justify-content-between align-items-center"> 78 <div class="btn-group"> 79 <button type="button" class="btn btn-sm btn-outline-secondary">View</button> 80 <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button> 81 </div> 82 <small class="text-muted">9 mins</small> 83 </div> 84 </div> 85 </div> 86 </div> 87 <div class="col-md-4"> 88 <div class="card mb-4 shadow-sm"> 89 <img class="card-img-top" data-src="holder.js/100px225?theme=thumb&bg=55595c&fg=eceeef&text=Thumbnail" alt="Thumbnail [100%x225]" src="data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22348%22%20height%3D%22225%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20348%20225%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_165ea5071fe%20text%20%7B%20fill%3A%23eceeef%3Bfont-weight%3Abold%3Bfont-family%3AArial%2C%20Helvetica%2C%20Open%20Sans%2C%20sans-serif%2C%20monospace%3Bfont-size%3A17pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_165ea5071fe%22%3E%3Crect%20width%3D%22348%22%20height%3D%22225%22%20fill%3D%22%2355595c%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%22116.71875%22%20y%3D%22120.15%22%3EThumbnail%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E" data-holder-rendered="true" style="height: 225px; width: 100%; display: block;"> 90 <div class="card-body"> 91 <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> 92 <div class="d-flex justify-content-between align-items-center"> 93 <div class="btn-group"> 94 <button type="button" class="btn btn-sm btn-outline-secondary">View</button> 95 <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button> 96 </div> 97 <small class="text-muted">9 mins</small> 98 </div> 99 </div> 100 </div> 101 </div> 102 <div class="col-md-4"> 103 <div class="card mb-4 shadow-sm"> 104 <img class="card-img-top" data-src="holder.js/100px225?theme=thumb&bg=55595c&fg=eceeef&text=Thumbnail" alt="Thumbnail [100%x225]" src="data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22348%22%20height%3D%22225%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20348%20225%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_165ea507200%20text%20%7B%20fill%3A%23eceeef%3Bfont-weight%3Abold%3Bfont-family%3AArial%2C%20Helvetica%2C%20Open%20Sans%2C%20sans-serif%2C%20monospace%3Bfont-size%3A17pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_165ea507200%22%3E%3Crect%20width%3D%22348%22%20height%3D%22225%22%20fill%3D%22%2355595c%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%22116.71875%22%20y%3D%22120.15%22%3EThumbnail%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E" data-holder-rendered="true" style="height: 225px; width: 100%; display: block;"> 105 <div class="card-body"> 106 <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> 107 <div class="d-flex justify-content-between align-items-center"> 108 <div class="btn-group"> 109 <button type="button" class="btn btn-sm btn-outline-secondary">View</button> 110 <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button> 111 </div> 112 <small class="text-muted">9 mins</small> 113 </div> 114 </div> 115 </div> 116 </div> 117 118 <div class="col-md-4"> 119 <div class="card mb-4 shadow-sm"> 120 <img class="card-img-top" data-src="holder.js/100px225?theme=thumb&bg=55595c&fg=eceeef&text=Thumbnail" alt="Thumbnail [100%x225]" src="data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22348%22%20height%3D%22225%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20348%20225%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_165ea507200%20text%20%7B%20fill%3A%23eceeef%3Bfont-weight%3Abold%3Bfont-family%3AArial%2C%20Helvetica%2C%20Open%20Sans%2C%20sans-serif%2C%20monospace%3Bfont-size%3A17pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_165ea507200%22%3E%3Crect%20width%3D%22348%22%20height%3D%22225%22%20fill%3D%22%2355595c%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%22116.71875%22%20y%3D%22120.15%22%3EThumbnail%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E" data-holder-rendered="true" style="height: 225px; width: 100%; display: block;"> 121 <div class="card-body"> 122 <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> 123 <div class="d-flex justify-content-between align-items-center"> 124 <div class="btn-group"> 125 <button type="button" class="btn btn-sm btn-outline-secondary">View</button> 126 <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button> 127 </div> 128 <small class="text-muted">9 mins</small> 129 </div> 130 </div> 131 </div> 132 </div> 133 <div class="col-md-4"> 134 <div class="card mb-4 shadow-sm"> 135 <img class="card-img-top" data-src="holder.js/100px225?theme=thumb&bg=55595c&fg=eceeef&text=Thumbnail" alt="Thumbnail [100%x225]" src="data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22348%22%20height%3D%22225%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20348%20225%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_165ea507201%20text%20%7B%20fill%3A%23eceeef%3Bfont-weight%3Abold%3Bfont-family%3AArial%2C%20Helvetica%2C%20Open%20Sans%2C%20sans-serif%2C%20monospace%3Bfont-size%3A17pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_165ea507201%22%3E%3Crect%20width%3D%22348%22%20height%3D%22225%22%20fill%3D%22%2355595c%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%22116.71875%22%20y%3D%22120.15%22%3EThumbnail%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E" data-holder-rendered="true" style="height: 225px; width: 100%; display: block;"> 136 <div class="card-body"> 137 <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> 138 <div class="d-flex justify-content-between align-items-center"> 139 <div class="btn-group"> 140 <button type="button" class="btn btn-sm btn-outline-secondary">View</button> 141 <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button> 142 </div> 143 <small class="text-muted">9 mins</small> 144 </div> 145 </div> 146 </div> 147 </div> 148 <div class="col-md-4"> 149 <div class="card mb-4 shadow-sm"> 150 <img class="card-img-top" data-src="holder.js/100px225?theme=thumb&bg=55595c&fg=eceeef&text=Thumbnail" alt="Thumbnail [100%x225]" src="data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22348%22%20height%3D%22225%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20348%20225%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_165ea507202%20text%20%7B%20fill%3A%23eceeef%3Bfont-weight%3Abold%3Bfont-family%3AArial%2C%20Helvetica%2C%20Open%20Sans%2C%20sans-serif%2C%20monospace%3Bfont-size%3A17pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_165ea507202%22%3E%3Crect%20width%3D%22348%22%20height%3D%22225%22%20fill%3D%22%2355595c%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%22116.71875%22%20y%3D%22120.15%22%3EThumbnail%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E" data-holder-rendered="true" style="height: 225px; width: 100%; display: block;"> 151 <div class="card-body"> 152 <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> 153 <div class="d-flex justify-content-between align-items-center"> 154 <div class="btn-group"> 155 <button type="button" class="btn btn-sm btn-outline-secondary">View</button> 156 <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button> 157 </div> 158 <small class="text-muted">9 mins</small> 159 </div> 160 </div> 161 </div> 162 </div> 163 164 <div class="col-md-4"> 165 <div class="card mb-4 shadow-sm"> 166 <img class="card-img-top" data-src="holder.js/100px225?theme=thumb&bg=55595c&fg=eceeef&text=Thumbnail" alt="Thumbnail [100%x225]" src="data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22348%22%20height%3D%22225%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20348%20225%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_165ea507203%20text%20%7B%20fill%3A%23eceeef%3Bfont-weight%3Abold%3Bfont-family%3AArial%2C%20Helvetica%2C%20Open%20Sans%2C%20sans-serif%2C%20monospace%3Bfont-size%3A17pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_165ea507203%22%3E%3Crect%20width%3D%22348%22%20height%3D%22225%22%20fill%3D%22%2355595c%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%22116.71875%22%20y%3D%22120.15%22%3EThumbnail%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E" data-holder-rendered="true" style="height: 225px; width: 100%; display: block;"> 167 <div class="card-body"> 168 <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> 169 <div class="d-flex justify-content-between align-items-center"> 170 <div class="btn-group"> 171 <button type="button" class="btn btn-sm btn-outline-secondary">View</button> 172 <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button> 173 </div> 174 <small class="text-muted">9 mins</small> 175 </div> 176 </div> 177 </div> 178 </div> 179 <div class="col-md-4"> 180 <div class="card mb-4 shadow-sm"> 181 <img class="card-img-top" data-src="holder.js/100px225?theme=thumb&bg=55595c&fg=eceeef&text=Thumbnail" alt="Thumbnail [100%x225]" src="data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22348%22%20height%3D%22225%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20348%20225%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_165ea507203%20text%20%7B%20fill%3A%23eceeef%3Bfont-weight%3Abold%3Bfont-family%3AArial%2C%20Helvetica%2C%20Open%20Sans%2C%20sans-serif%2C%20monospace%3Bfont-size%3A17pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_165ea507203%22%3E%3Crect%20width%3D%22348%22%20height%3D%22225%22%20fill%3D%22%2355595c%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%22116.71875%22%20y%3D%22120.15%22%3EThumbnail%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E" data-holder-rendered="true" style="height: 225px; width: 100%; display: block;"> 182 <div class="card-body"> 183 <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> 184 <div class="d-flex justify-content-between align-items-center"> 185 <div class="btn-group"> 186 <button type="button" class="btn btn-sm btn-outline-secondary">View</button> 187 <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button> 188 </div> 189 <small class="text-muted">9 mins</small> 190 </div> 191 </div> 192 </div> 193 </div> 194 <div class="col-md-4"> 195 <div class="card mb-4 shadow-sm"> 196 <img class="card-img-top" data-src="holder.js/100px225?theme=thumb&bg=55595c&fg=eceeef&text=Thumbnail" alt="Thumbnail [100%x225]" src="data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22348%22%20height%3D%22225%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20348%20225%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_165ea507203%20text%20%7B%20fill%3A%23eceeef%3Bfont-weight%3Abold%3Bfont-family%3AArial%2C%20Helvetica%2C%20Open%20Sans%2C%20sans-serif%2C%20monospace%3Bfont-size%3A17pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_165ea507203%22%3E%3Crect%20width%3D%22348%22%20height%3D%22225%22%20fill%3D%22%2355595c%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%22116.71875%22%20y%3D%22120.15%22%3EThumbnail%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E" data-holder-rendered="true" style="height: 225px; width: 100%; display: block;"> 197 <div class="card-body"> 198 <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> 199 <div class="d-flex justify-content-between align-items-center"> 200 <div class="btn-group"> 201 <button type="button" class="btn btn-sm btn-outline-secondary">View</button> 202 <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button> 203 </div> 204 <small class="text-muted">9 mins</small> 205 </div> 206 </div> 207 </div> 208 </div> 209 </div> 210 </div> 211 </div> 212 </main> 213 <footer class="text-muted"> 214 <div class="container"> 215 <p class="float-right"> 216 <a href="#">Back to top</a> 217 </p> 218 <p>Album example is © Bootstrap, but please download and customize it for yourself!</p> 219 <p>New to Bootstrap? <a href="../../">Visit the homepage</a> or read our <a href="../../getting-started/">getting started guide</a>.</p> 220 </div> 221 </footer> 222 <svg xmlns="http://www.w3.org/2000/svg" width="348" height="225" viewBox="0 0 348 225" preserveAspectRatio="none" style="display: none; visibility: hidden; position: absolute; top: -100%; left: -100%;"><defs><style type="text/css"></style></defs><text x="0" y="17" style="font-weight:bold;font-size:17pt;font-family:Arial, Helvetica, Open Sans, sans-serif">Thumbnail</text></svg></body></html> 223 ` 224 Convey(".GetNodeType", t, func() { 225 Convey("Should serialize a boolean value", func() { 226 buff := bytes.NewBuffer([]byte(doc)) 227 228 buff.Write([]byte(doc)) 229 230 doc, err := goquery.NewDocumentFromReader(buff) 231 232 So(err, ShouldBeNil) 233 234 el, err := http.NewHTMLElement(doc.Selection) 235 236 So(err, ShouldBeNil) 237 238 nt, err := el.GetNodeType(context.Background()) 239 240 So(err, ShouldBeNil) 241 So(nt, ShouldEqual, 9) 242 }) 243 }) 244 }