98 lines
2.9 KiB
Go
98 lines
2.9 KiB
Go
|
package nomad
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
var pageData = `<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<title>Nomad: An MMS µblog</title>
|
||
|
<meta charset="utf-8" />
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
|
||
|
<meta property="og:title" content="Finally exploring the trail behind my apartment, of course in the rain." />
|
||
|
<meta property="og:type" content="website" />
|
||
|
<meta property="og:url" content="https://nomad.wntrmute.net/p/1986" />
|
||
|
<meta property="og:image" content="https://nomad.sfo2.cdn.digitaloceanspaces.com/MM6f13e74faa6d643d654507c5bd9d8f53.jpg" />
|
||
|
|
||
|
<link href="/index.rss" type="application/rss+xml" rel="alternate" title="Nomad feed" />
|
||
|
<link href="/static/favicon.ico" rel="shortcut icon">
|
||
|
<link href="/static/style.css" rel="stylesheet">
|
||
|
</head>
|
||
|
|
||
|
<body>
|
||
|
<div id="wrap">
|
||
|
<main>
|
||
|
<header>
|
||
|
<h1><a href="/">Nomad</a></h1>
|
||
|
</header>
|
||
|
<section>
|
||
|
|
||
|
<article class="entry entry-single" id="post-1986">
|
||
|
<div class="entry-details">
|
||
|
<span class="entry-author"><a href="/u/kyle">kyle</a></span>
|
||
|
|
||
|
</div>
|
||
|
|
||
|
<div class="entry-image">
|
||
|
<!-- TODO: how do we provide a useful alt? -->
|
||
|
<a href="https://nomad.sfo2.cdn.digitaloceanspaces.com/MM6f13e74faa6d643d654507c5bd9d8f53.jpg" target="_blank" rel="noopener">
|
||
|
<img src="https://nomad.sfo2.cdn.digitaloceanspaces.com/MM6f13e74faa6d643d654507c5bd9d8f53.jpg" alt="MMS attachment"/>
|
||
|
</a>
|
||
|
</div>
|
||
|
|
||
|
<p class="entry-body">Finally exploring the trail behind my apartment, of course in the rain.</p>
|
||
|
|
||
|
<div class="entry-details">
|
||
|
<time datetime="2021-10-24 13:22:47 PDT">
|
||
|
posted 2021-10-24 13:22:47 PDT
|
||
|
</time>
|
||
|
</div>
|
||
|
|
||
|
</article>
|
||
|
|
||
|
</section>
|
||
|
<footer>
|
||
|
<p>
|
||
|
<a href="/about">Nomad</a> is an experiment in MMS micropublishing,
|
||
|
and is bolted together with
|
||
|
<a href="https://www.palletsprojects.com/p/flask/">Flask</a>
|
||
|
and <a href="https://twilio.com/">Twilio</a>; it was inspired by
|
||
|
<a href="https://craigmod.com/essays/sms_publishing/">Craig Mod's experiment</a>.
|
||
|
It is being built by
|
||
|
<a class="h-card u-url" rel="me" href="https://ai6ua.net/">Kyle</a> and
|
||
|
<a class="h-card u-url" rel="me" href="https://wallyjones.com/">Wally</a>.
|
||
|
</p>
|
||
|
|
||
|
<p><small>Nomad v78</small></p>
|
||
|
|
||
|
</footer>
|
||
|
</main>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|
||
|
`
|
||
|
|
||
|
func TestFetch(t *testing.T) {
|
||
|
p := Post{
|
||
|
Body: nomadLink(NewURLSource("https://localhost")),
|
||
|
URL: NewStringSource(pageData),
|
||
|
}
|
||
|
|
||
|
err := p.Fetch()
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
expectedBody := "Finally exploring the trail behind my apartment, of course in the rain. [nomad.wntrmute.net](https://localhost)"
|
||
|
expectedImage := "https://nomad.sfo2.cdn.digitaloceanspaces.com/MM6f13e74faa6d643d654507c5bd9d8f53.jpg"
|
||
|
if p.Body != expectedBody {
|
||
|
t.Fatalf("have '%s', want '%s'", p.Body, expectedBody)
|
||
|
}
|
||
|
|
||
|
if p.Image.ID() != expectedImage {
|
||
|
t.Fatalf("have '%s', want '%s'", p.Image, expectedImage)
|
||
|
}
|
||
|
}
|