aboutsummaryrefslogtreecommitdiff
path: root/api/cmd/main_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'api/cmd/main_test.go')
-rw-r--r--api/cmd/main_test.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/api/cmd/main_test.go b/api/cmd/main_test.go
index a6c8381..049cf6e 100644
--- a/api/cmd/main_test.go
+++ b/api/cmd/main_test.go
@@ -6,6 +6,7 @@ import (
6 "net/http" 6 "net/http"
7 "net/http/httptest" 7 "net/http/httptest"
8 "testing" 8 "testing"
9 "water/api/internal/router"
9 10
10 "github.com/spf13/viper" 11 "github.com/spf13/viper"
11 "github.com/stretchr/testify/assert" 12 "github.com/stretchr/testify/assert"
@@ -26,7 +27,7 @@ func getTestUserCredentials() (string, string) {
26} 27}
27 28
28func TestAuthRoute(t *testing.T) { 29func TestAuthRoute(t *testing.T) {
29 router := setupRouter() 30 r := router.SetupRouter()
30 31
31 username, password := getTestUserCredentials() 32 username, password := getTestUserCredentials()
32 33
@@ -39,7 +40,7 @@ func TestAuthRoute(t *testing.T) {
39 t.Fatalf("Failed to create request: %v", err) 40 t.Fatalf("Failed to create request: %v", err)
40 } 41 }
41 req.SetBasicAuth(username, password) 42 req.SetBasicAuth(username, password)
42 router.ServeHTTP(w, req) 43 r.ServeHTTP(w, req)
43 44
44 assert.Equal(t, http.StatusOK, w.Code, "response should return a 200 code") 45 assert.Equal(t, http.StatusOK, w.Code, "response should return a 200 code")
45 46
@@ -56,12 +57,12 @@ func TestAuthRoute(t *testing.T) {
56} 57}
57 58
58func TestAuthRouteFailure(t *testing.T) { 59func TestAuthRouteFailure(t *testing.T) {
59 router := setupRouter() 60 r := router.SetupRouter()
60 61
61 w := httptest.NewRecorder() 62 w := httptest.NewRecorder()
62 req, _ := http.NewRequest("POST", "/api/v1/auth", nil) 63 req, _ := http.NewRequest("POST", "/api/v1/auth", nil)
63 req.SetBasicAuth("asdf", "asdf") 64 req.SetBasicAuth("asdf", "asdf")
64 router.ServeHTTP(w, req) 65 r.ServeHTTP(w, req)
65 66
66 assert.Equal(t, http.StatusUnauthorized, w.Code, "should return a 401 code") 67 assert.Equal(t, http.StatusUnauthorized, w.Code, "should return a 401 code")
67} 68}