Add simple key value service
Change-Id: Ic04ddbd26b3111ff95d78f3046ace7fc69916219
diff --git a/service_test.go b/service_test.go
new file mode 100644
index 0000000..a18c52e
--- /dev/null
+++ b/service_test.go
@@ -0,0 +1,35 @@
+package main
+
+import (
+ "net/http"
+ "net/http/httptest"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestPingRoute(t *testing.T) {
+
+ dir := t.TempDir()
+
+ initDB(dir)
+ defer closeDB()
+ router := setupRouter()
+
+ w := httptest.NewRecorder()
+ req, _ := http.NewRequest(http.MethodGet, "/s10/s10/s10", nil)
+
+ router.ServeHTTP(w, req)
+
+ assert.Equal(t, http.StatusNotFound, w.Code)
+ assert.Equal(t, "No entry found", w.Body.String())
+
+ assert.Nil(t, add("s11", "s12", "s13", "http://example.org"))
+
+ w = httptest.NewRecorder()
+ req, _ = http.NewRequest(http.MethodGet, "/s11/s12/s13", nil)
+
+ router.ServeHTTP(w, req)
+ assert.Equal(t, http.StatusOK, w.Code)
+ assert.Equal(t, "http://example.org", w.Body.String())
+}