summary refs log tree commit diff stats
path: root/handlers_test.go
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-05-13 17:20:40 -0400
committerBen Morrison <ben@gbmor.dev>2019-05-13 17:22:28 -0400
commitd6fbc25111a9a76b40f19b2481428a9170c706b0 (patch)
treed071366939de7a6994c56153f81b16e836883043 /handlers_test.go
parent9d31e04f8ec8c53c6f6e2323d7422b86b7a4ad90 (diff)
downloadgetwtxt-d6fbc25111a9a76b40f19b2481428a9170c706b0.tar.gz
serving css virtually instead of directly
Diffstat (limited to 'handlers_test.go')
-rw-r--r--handlers_test.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/handlers_test.go b/handlers_test.go
index 66c1566..4ae7ae6 100644
--- a/handlers_test.go
+++ b/handlers_test.go
@@ -1,7 +1,9 @@
 package main
 
 import (
+	"bytes"
 	"fmt"
+	"io/ioutil"
 	"log"
 	"net/http"
 	"net/http/httptest"
@@ -98,3 +100,27 @@ func Test_apiTagsHandler(t *testing.T) {
 		}
 	})
 }
+func Test_cssHandler(t *testing.T) {
+	initTestConf()
+
+	name := "CSS Handler Test"
+	css, err := ioutil.ReadFile("assets/style.css")
+	if err != nil {
+		t.Errorf("Couldn't read assets/style.css: %v\n", err)
+	}
+
+	w := httptest.NewRecorder()
+	req := httptest.NewRequest("GET", "localhost"+testport+"/css", nil)
+
+	t.Run(name, func(t *testing.T) {
+		cssHandler(w, req)
+		resp := w.Result()
+		body, _ := ioutil.ReadAll(resp.Body)
+		if resp.StatusCode != 200 {
+			t.Errorf("cssHandler(): %v\n", resp.StatusCode)
+		}
+		if !bytes.Equal(body, css) {
+			t.Errorf("cssHandler(): Byte mismatch\n")
+		}
+	})
+}