-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
52 lines (36 loc) · 1.03 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
package main
import (
"github.com/stretchr/testify/assert"
"net/http"
"github.com/foolin/goview/supports/ginview"
"github.com/gin-gonic/gin"
"net/http/httptest"
"testing"
)
func TestHomePage(t *testing.T) {
t.Run("Homepage rendering test - 200 ok", func(t *testing.T){
w := httptest.NewRecorder()
r := gin.Default()
r.HTMLRender = ginview.Default()
r.GET("/", HomePage)
ctx, _ := gin.CreateTestContext(w)
req, _ := http.NewRequestWithContext(ctx, "GET", "/", nil)
r.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code)
})
}
func TestRunCmd(t *testing.T) {
w := httptest.NewRecorder()
r := gin.Default()
r.HTMLRender = ginview.Default()
r.GET("/runcmd", RunCmd)
ctx, _ := gin.CreateTestContext(w)
req, _ := http.NewRequestWithContext(ctx, "GET", "/runcmd", nil)
r.ServeHTTP(w, req)
assert.Equal(t, 500, w.Code)
w1 := httptest.NewRecorder()
ctx1, _ := gin.CreateTestContext(w1)
req2, _ := http.NewRequestWithContext(ctx1, "GET", "/runcmd?text=uname", nil )
r.ServeHTTP(w1, req2)
assert.Equal(t, 200, w1.Code)
}