about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--handlers_test.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/handlers_test.go b/handlers_test.go
new file mode 100644
index 0000000..72d3304
--- /dev/null
+++ b/handlers_test.go
@@ -0,0 +1,31 @@
+package main
+
+import (
+	"fmt"
+	"log"
+	"net/http"
+	"net/http/httptest"
+	"os"
+	"testing"
+)
+
+func logToNull() {
+	hush, err := os.Open("/dev/null")
+	if err != nil {
+		log.Printf("%v\n", err)
+	}
+	log.SetOutput(hush)
+}
+
+func Test_indexHandler(t *testing.T) {
+	logToNull()
+	t.Run("indexHandler", func(t *testing.T) {
+		w := httptest.NewRecorder()
+		req := httptest.NewRequest("GET", "localhost:9001/", nil)
+		indexHandler(w, req)
+		resp := w.Result()
+		if resp.StatusCode != http.StatusOK {
+			t.Errorf(fmt.Sprintf("%v", resp.StatusCode))
+		}
+	})
+}