summaryrefslogtreecommitdiff
path: root/internal/href/href_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/href/href_test.go')
-rw-r--r--internal/href/href_test.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/internal/href/href_test.go b/internal/href/href_test.go
new file mode 100644
index 0000000..ed2bc40
--- /dev/null
+++ b/internal/href/href_test.go
@@ -0,0 +1,63 @@
+package href
+
+import (
+ "io"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "testing"
+)
+
+func TestTitle(t *testing.T) {
+ testCases := []struct {
+ fixture, title, contentType string
+ }{
+ {
+ `testdata/linux.org.ru`,
+ `LINUX.ORG.RU - Русская информация об ОС Linux`,
+ `text/html;charset=utf-8`,
+ },
+ {
+ `testdata/opennet.ru`,
+ `Проект OpenNet - всё, что связано с открытым ПО, открытыми технологиями, Linux, BSD и Unix`,
+ `text/html; charset=koi8-r`,
+ },
+ {
+ `testdata/openbsd.org`,
+ `OpenBSD`,
+ `text/html`,
+ },
+ {
+ `testdata/undeadly.org`,
+ `OpenBSD Journal: A resource for the OpenBSD community`,
+ `text/html`,
+ },
+ {
+ `testdata/deepnested.html`,
+ `!`,
+ `text/html`,
+ },
+ }
+ for _, tc := range testCases {
+ t.Run(tc.fixture, func(t *testing.T) {
+ ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ fd, err := os.Open(tc.fixture)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+ defer fd.Close()
+ w.Header().Set("Content-Type", tc.contentType)
+ io.Copy(w, fd)
+ }))
+ defer ts.Close()
+ title, err := Title(ts.URL)
+ if err != nil {
+ t.Error(tc.fixture, err)
+ }
+ if title != tc.title {
+ t.Errorf("got %v, want %v", title, tc.title)
+ }
+ })
+ }
+}