From d6fbc25111a9a76b40f19b2481428a9170c706b0 Mon Sep 17 00:00:00 2001 From: Ben Morrison Date: Mon, 13 May 2019 17:20:40 -0400 Subject: serving css virtually instead of directly --- handlers_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'handlers_test.go') 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") + } + }) +} -- cgit 1.4.1-2-gfad0