canopeas/falseknees/falseknees_test.go

484 lines
21 KiB
Go

package falseknees
import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"os"
"testing"
)
var (
server *httptest.Server
client *Client
)
func TestMain(m *testing.M) {
handler := func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/index.html" {
_, _ = w.Write(indexHTML)
return
}
if r.URL.Path == "/389.html" {
_, _ = w.Write(currentHTML)
return
}
if r.URL.Path == "/252.html" {
_, _ = w.Write(bunnyHTML)
return
}
w.WriteHeader(http.StatusNotFound)
}
server = httptest.NewServer(http.HandlerFunc(handler))
baseURL = server.URL + "/"
currentComic.Img = fmt.Sprintf("%simgs/389.png", baseURL)
bunnyComic.Img = fmt.Sprintf("%simgs/252.png", baseURL)
client = New()
os.Exit(m.Run())
}
func TestCurrent(t *testing.T) {
t.Parallel()
comic, err := client.Current(context.Background())
if err != nil {
t.Logf("could not get current comic: %v\n", err)
t.FailNow()
}
if *comic != currentComic {
t.Log("comic does not match test data")
t.FailNow()
}
}
func TestComic(t *testing.T) {
t.Parallel()
comic, err := client.Comic(context.Background(), 252)
if err != nil {
t.Logf("could not get comic 252: %v\n", err)
t.FailNow()
}
if *comic != bunnyComic {
t.Log("comic does not match test data")
t.FailNow()
}
}
var (
currentComic = Comic{
Num: 389,
Title: "that's the good stuff",
}
bunnyComic = Comic{
Num: 252,
Title: "Spring is the fucking greatest shit",
}
indexHTML = []byte(`<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="description"
content="False Knees is a webcomic written by Joshua Barkman. All silly nonsense is my own." />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="refresh" content="0; URL=389.html" />
<script type="text/javascript">
window.location.href = "389.html"
</script>
<!-- Favicon -->
<link rel="icon" type="image/png" href="imgs/favicon.png" sizes="96x96">
<!-- Facebook Meta tags -->
<meta property="og:title" content="False Knees" />
<meta property="og:type" content="blog" />
<meta property="og:url" content="http://www.falseknees.com/index.html" />
<meta property="og:image" content="http://www.falseknees.com/imgs/389.png" />
<meta property="og:site_name" content="False Knees" />
<meta property="fb:admins" content="1646220005" />
<link rel="image_src" href="imgs/389.png" />
<link type="text/css" rel="stylesheet" href="stylesheet.css" />
<title>Page Redirection</title>
<!-- Google Analytics -->
<script type="text/javascript">
var _gaq = _gaq || [];
var pluginUrl =
'//www.google-analytics.com/plugins/ga/inpage_linkid.js';
_gaq.push(['_require', 'inpage_linkid', pluginUrl]);
_gaq.push(['_setAccount', 'UA-37345913-1']);
_gaq.push(['_setDomainName', 'falseknees.com']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<div id="fb-root"></div>
<script>
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v2.0";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<!-- Title Image -->
<table align="center">
<tr>
<td>
<div id="title">
<a href="index.html"><img src="imgs/falseknees.png" width="800" /></a>
</div>
</td>
</tr>
</table>
<!-- New Button Placement -->
<div align="center">
<p>
<table>
<tr>
<td><a href="about.html"
title=""><img src="imgs/aboutoff.png" height="50" alt="About" onmouseover="this.src='imgs/abouton.png'" onmouseout="this.src='imgs/aboutoff.png'" /></a>
</td>
<td><a title=""><img src="imgs/stara.png" height="50" alt="" /></a></td>
<td><a href="https://false-knees.myshopify.com/"
title=""><img src="imgs/store.png" height="50" alt="Store" onmouseover="this.src='imgs/storeon.png'" onmouseout="this.src='imgs/store.png'" /></a>
</td>
<td><a title=""><img src="imgs/starb.png" height="50" alt="" /></a></td>
<td><a href="https://www.patreon.com/falseknees?ty=h"><img src="imgs/patron.png" height="50" onmouseover="this.src='imgs/patroff.png'" onmouseout="this.src='imgs/patron.png'"/></a>
</td>
<td><a title=""><img src="imgs/starc.png" height="50" alt="" /></a></td>
<td><a href="book.html"
title=""><img src="imgs/book.png" height="40" alt="About" onmouseover="this.src='imgs/bookon.png'" onmouseout="this.src='imgs/book.png'" /></a>
</td>
</tr>
</table>
</p>
</div>
<!-- Comic -->
<div>
<img src="imgs/389.png" width="600" title="that's the good stuff" />
</div>
<!-- Descriptive Text Box -->
<!-- Descriptive Text Box -->
<div align="center">
</div>
<!-- Navigation Buttons -->
<div align="center">
<p>
<table>
<tr>
<td><a href="1.html"
title=""><img src="imgs/first.png" height="60" alt="First" onmouseover="this.src='imgs/firston.png'" onmouseout="this.src='imgs/first.png'" /></a>
</td>
<td><a href="388.html"
title=""><img src="imgs/previous.png" height="60" alt="Previous" onmouseover="this.src='imgs/previouson.png'" onmouseout="this.src='imgs/previous.png'" /></a>
</td>
<td><a href="archive.html"
title=""><img src="imgs/archive.png" height="60" alt="Archive" onmouseover="this.src='imgs/archive2.png'" onmouseout="this.src='imgs/archive.png'" /></a>
</td>
<td><a href="index.html"
title=""><img src="imgs/next.png" height="60" alt="Next" onmouseover="this.src='imgs/nexton.png'" onmouseout="this.src='imgs/next.png'" /></a>
</td>
<td><a href="index.html"
title=""><img src="imgs/last.png" height="60" alt="Last" onmouseover="this.src='imgs/laston.png'" onmouseout="this.src='imgs/last.png'" /></a>
</td>
</tr>
</table>
</p>
</div>
<!-- Social Media -->
<table class="social" align="center">
<tr>
<td><a href="http://falseknees.tumblr.com/"><img src="imgs/TumblrButton.png" width="60" onmouseover="this.src='imgs/TumblrButtonOn.png'" onmouseout="this.src='imgs/TumblrButton.png'"/></a>
</td>
<td><a href="https://instagram.com/FalseKnees"><img src="imgs/instagram.png" width="60" onmouseover="this.src='imgs/instagramon.png'" onmouseout="this.src='imgs/instagram.png'"/></a>
</td>
<td><a href="https://www.facebook.com/FalseKnees?ref=hl"><img src="imgs/FacebookButton.png" width="60" onmouseover="this.src='imgs/FacebookButtonOn.png'" onmouseout="this.src='imgs/FacebookButton.png'"/></a>
</td>
<td><a href="http://www.webtoons.com/en/challenge/false-knees/list?title_no=79544"><img src="imgs/webtooff.png" width="60" onmouseover="this.src='imgs/webtoon.png'" onmouseout="this.src='imgs/webtooff.png'"/></a>
</td>
<td><a href="https://tapas.io/series/FalseKnees"><img src="imgs/tap.png" width="60" onmouseover="this.src='imgs/tapon.png'" onmouseout="this.src='imgs/tap.png'"/></a>
</td>
</tr>
</table>
<!-- Copyright -->
<div>
<p>False Knees &copy 2013-whenever Joshua Barkman</p>
</div>
</body>
</html>`)
currentHTML = []byte(`<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="description" content="False Knees is a webcomic written by Joshua Barkman. All silly nonsense is my own." />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!-- Favicon -->
<link rel="icon" type="image/png" href="imgs/favicon.png" sizes="96x96">
<!-- Facebook Meta tags -->
<meta property="og:title" content="False Knees" />
<meta property="og:type" content="blog" />
<meta property="og:url" content="http://www.falseknees.com/389.html" />
<meta property="og:image" content="http://www.falseknees.com/imgs/389.png" />
<meta property="og:site_name" content="False Knees" />
<meta property="fb:admins" content="1646220005" />
<link rel="image_src" href="imgs/389.png" />
<link type="text/css" rel="stylesheet" href="stylesheet.css" />
<title>False Knees</title>
<!-- Google Analytics -->
<script type="text/javascript">
var _gaq = _gaq || [];
var pluginUrl =
'//www.google-analytics.com/plugins/ga/inpage_linkid.js';
_gaq.push(['_require', 'inpage_linkid', pluginUrl]);
_gaq.push(['_setAccount', 'UA-37345913-1']);
_gaq.push(['_setDomainName', 'falseknees.com']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v2.0";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<!-- Title Image -->
<table align="center">
<tr>
<td><div id="title">
<a href="index.html"><img src="imgs/falseknees.png" width="800" /></a>
</div></td>
</tr>
</table>
<!-- New Button Placement -->
<div align="center">
<p>
<table>
<tr>
<td><a href="about.html" title=""><img src="imgs/aboutoff.png" height="50" alt="About" onmouseover="this.src='imgs/abouton.png'" onmouseout="this.src='imgs/aboutoff.png'" /></a></td>
<td><a title=""><img src="imgs/stara.png" height="50" alt="" /></a></td>
<td><a href="https://false-knees.myshopify.com/" title=""><img src="imgs/store.png" height="50" alt="Store" onmouseover="this.src='imgs/storeon.png'" onmouseout="this.src='imgs/store.png'" /></a></td>
<td><a title=""><img src="imgs/starb.png" height="50" alt="" /></a></td>
<td><a href="https://www.patreon.com/falseknees?ty=h"><img src="imgs/patron.png" height="50" onmouseover="this.src='imgs/patroff.png'" onmouseout="this.src='imgs/patron.png'"/></a></td>
<td><a title=""><img src="imgs/starc.png" height="50" alt="" /></a></td>
<td><a href="book.html" title=""><img src="imgs/book.png" height="40" alt="About" onmouseover="this.src='imgs/bookon.png'" onmouseout="this.src='imgs/book.png'" /></a></td>
</tr>
</table></p>
</div>
<!-- Comic -->
<div>
<img src="imgs/389.png" width="600" title="that's the good stuff" />
</div>
<!-- Descriptive Text Box -->
<!-- Descriptive Text Box -->
<div align="center">
</div>
<!-- Navigation Buttons -->
<div align="center">
<p>
<table>
<tr>
<td><a href="1.html" title=""><img src="imgs/first.png" height="60" alt="First" onmouseover="this.src='imgs/firston.png'" onmouseout="this.src='imgs/first.png'" /></a></td>
<td><a href="388.html" title=""><img src="imgs/previous.png" height="60" alt="Previous" onmouseover="this.src='imgs/previouson.png'" onmouseout="this.src='imgs/previous.png'" /></a></td>
<td><a href="archive.html" title=""><img src="imgs/archive.png" height="60" alt="Archive" onmouseover="this.src='imgs/archive2.png'" onmouseout="this.src='imgs/archive.png'" /></a></td>
<td><a href="389.html" title=""><img src="imgs/next.png" height="60" alt="Next" onmouseover="this.src='imgs/nexton.png'" onmouseout="this.src='imgs/next.png'" /></a></td>
<td><a href="index.html" title=""><img src="imgs/last.png" height="60" alt="Last" onmouseover="this.src='imgs/laston.png'" onmouseout="this.src='imgs/last.png'" /></a></td>
</tr>
</table></p>
</div>
<!-- Social Media -->
<table class="social" align="center">
<tr>
<td><a href="http://falseknees.tumblr.com/"><img src="imgs/TumblrButton.png" width="60" onmouseover="this.src='imgs/TumblrButtonOn.png'" onmouseout="this.src='imgs/TumblrButton.png'"/></a>
</td>
<td><a href="https://instagram.com/FalseKnees"><img src="imgs/instagram.png" width="60" onmouseover="this.src='imgs/instagramon.png'" onmouseout="this.src='imgs/instagram.png'"/></a>
</td>
<td><a href="https://www.facebook.com/FalseKnees?ref=hl"><img src="imgs/FacebookButton.png" width="60" onmouseover="this.src='imgs/FacebookButtonOn.png'" onmouseout="this.src='imgs/FacebookButton.png'"/></a>
</td>
<td><a href="http://www.webtoons.com/en/challenge/false-knees/list?title_no=79544"><img src="imgs/webtooff.png" width="60" onmouseover="this.src='imgs/webtoon.png'" onmouseout="this.src='imgs/webtooff.png'"/></a>
</td>
<td><a href="https://tapas.io/series/FalseKnees"><img src="imgs/tap.png" width="60" onmouseover="this.src='imgs/tapon.png'" onmouseout="this.src='imgs/tap.png'"/></a>
</td>
</tr>
</table>
<!-- Copyright -->
<div>
<p>False Knees &copy 2013-whenever Joshua Barkman</p>
</div>
</body>
</html>
`)
bunnyHTML = []byte(`<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="description" content="False Knees is a webcomic written by Joshua Barkman. All silly nonsense is my own." />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!-- Favicon -->
<link rel="icon" type="image/png" href="imgs/favicon.png" sizes="96x96">
<!-- Facebook Meta tags -->
<meta property="og:title" content="False Knees" />
<meta property="og:type" content="blog" />
<meta property="og:url" content="http://www.falseknees.com/252.html" />
<meta property="og:image" content="http://www.falseknees.com/imgs/252.png" />
<meta property="og:site_name" content="False Knees" />
<meta property="fb:admins" content="1646220005" />
<link rel="image_src" href="imgs/252.png" />
<link type="text/css" rel="stylesheet" href="stylesheet.css" />
<title>False Knees</title>
<!-- Google Analytics -->
<script type="text/javascript">
var _gaq = _gaq || [];
var pluginUrl =
'//www.google-analytics.com/plugins/ga/inpage_linkid.js';
_gaq.push(['_require', 'inpage_linkid', pluginUrl]);
_gaq.push(['_setAccount', 'UA-37345913-1']);
_gaq.push(['_setDomainName', 'falseknees.com']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v2.0";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<!-- Title Image -->
<table align="center">
<tr>
<td><div id="title">
<a href="index.html"><img src="imgs/falseknees.png" width="800" /></a>
</div></td>
</tr>
</table>
<!-- New Button Placement -->
<div align="center">
<p>
<table>
<tr>
<td><a href="about.html" title=""><img src="imgs/aboutoff.png" height="50" alt="About" onmouseover="this.src='imgs/abouton.png'" onmouseout="this.src='imgs/aboutoff.png'" /></a></td>
<td><a title=""><img src="imgs/stara.png" height="50" alt="" /></a></td>
<td><a href="https://false-knees.myshopify.com/collections/comic-prints" title=""><img src="imgs/store.png" height="50" alt="Store" onmouseover="this.src='imgs/storeon.png'" onmouseout="this.src='imgs/store.png'" /></a></td>
<td><a title=""><img src="imgs/starb.png" height="50" alt="" /></a></td>
<td><a href="https://www.patreon.com/falseknees?ty=h"><img src="imgs/patron.png" height="50" onmouseover="this.src='imgs/patroff.png'" onmouseout="this.src='imgs/patron.png'"/></a></td>
<td><a title=""><img src="imgs/starc.png" height="50" alt="" /></a></td>
<td><a href="book.html" title=""><img src="imgs/book.png" height="40" alt="About" onmouseover="this.src='imgs/bookon.png'" onmouseout="this.src='imgs/book.png'" /></a></td>
</tr>
</table></p>
</div>
<!-- Comic -->
<div>
<img src="imgs/252.png" width="600" title="Spring is the fucking greatest shit" />
</div>
<!-- Descriptive Text Box -->
<!-- Descriptive Text Box -->
<div align="center">
</div>
<!-- Navigation Buttons -->
<div align="center">
<p>
<table>
<tr>
<td><a href="1.html" title=""><img src="imgs/first.png" height="60" alt="First" onmouseover="this.src='imgs/firston.png'" onmouseout="this.src='imgs/first.png'" /></a></td>
<td><a href="251.html" title=""><img src="imgs/previous.png" height="60" alt="Previous" onmouseover="this.src='imgs/previouson.png'" onmouseout="this.src='imgs/previous.png'" /></a></td>
<td><a href="archive.html" title=""><img src="imgs/archive.png" height="60" alt="Archive" onmouseover="this.src='imgs/archive2.png'" onmouseout="this.src='imgs/archive.png'" /></a></td>
<td><a href="253.html" title=""><img src="imgs/next.png" height="60" alt="Next" onmouseover="this.src='imgs/nexton.png'" onmouseout="this.src='imgs/next.png'" /></a></td>
<td><a href="index.html" title=""><img src="imgs/last.png" height="60" alt="Last" onmouseover="this.src='imgs/laston.png'" onmouseout="this.src='imgs/last.png'" /></a></td>
</tr>
</table></p>
</div>
<!-- Social Media -->
<table class="social" align="center">
<tr>
<td><a href="http://falseknees.tumblr.com/"><img src="imgs/TumblrButton.png" width="60" onmouseover="this.src='imgs/TumblrButtonOn.png'" onmouseout="this.src='imgs/TumblrButton.png'"/></a>
</td>
<td><a href="https://instagram.com/FalseKnees"><img src="imgs/instagram.png" width="60" onmouseover="this.src='imgs/instagramon.png'" onmouseout="this.src='imgs/instagram.png'"/></a>
</td>
<td><a href="https://www.facebook.com/FalseKnees?ref=hl"><img src="imgs/FacebookButton.png" width="60" onmouseover="this.src='imgs/FacebookButtonOn.png'" onmouseout="this.src='imgs/FacebookButton.png'"/></a>
</td>
<td><a href="http://www.webtoons.com/en/challenge/false-knees/list?title_no=79544"><img src="imgs/webtooff.png" width="60" onmouseover="this.src='imgs/webtoon.png'" onmouseout="this.src='imgs/webtooff.png'"/></a>
</td>
<td><a href="https://tapas.io/series/FalseKnees"><img src="imgs/tap.png" width="60" onmouseover="this.src='imgs/tapon.png'" onmouseout="this.src='imgs/tap.png'"/></a>
</td>
</tr>
</table>
<!-- Copyright -->
<div>
<p>False Knees &copy 2013-whenever Joshua Barkman</p>
</div>
</body>
</html>
`)
)