/
main_test.go
58 lines (43 loc) · 1.18 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
c "github.com/easilok/lymantria-api/controllers"
"github.com/easilok/lymantria-api/routes"
"github.com/easilok/lymantria-api/test"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
)
func TestGetCatalogNothing(t *testing.T) {
db := test.ConnectTestDatabase()
w := httptest.NewRecorder()
r := gin.Default()
gin.SetMode(gin.TestMode)
controllers := c.NewBaseHandler(db)
routes.ApiRoutes(r, controllers)
t.Run("get json data", func(t *testing.T) {
assert.Equal(t, 200, w.Code)
})
}
func TestRouter(t *testing.T) {
db := test.ConnectTestDatabase()
// w := httptest.NewRecorder()
r := gin.Default()
gin.SetMode(gin.TestMode)
controllers := c.NewBaseHandler(db)
routes.ApiRoutes(r, controllers)
ts := httptest.NewServer(r)
defer ts.Close()
t.Run("get catalog without login", func(t *testing.T) {
// Make a request to our server with the {base url}/ping
resp, err := http.Get(fmt.Sprintf("%s/ping", ts.URL))
if err != nil {
t.Fatalf("Expected no error, got %v", err)
}
if resp.StatusCode != 404 {
t.Fatalf("Expected status code 404, got %v", resp.StatusCode)
}
})
}