-
Notifications
You must be signed in to change notification settings - Fork 0
/
medialog_test.go
74 lines (63 loc) · 1.99 KB
/
medialog_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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"bufio"
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"os"
"strings"
"testing"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
)
func TestApplication(t *testing.T) {
gin.SetMode(gin.TestMode)
t.Run("test the index page", func(t *testing.T) {
recorder := httptest.NewRecorder()
c, _ := gin.CreateTestContext(recorder)
req, err := http.NewRequestWithContext(c, "GET", "/", nil)
if err != nil {
t.Error(err)
}
r.ServeHTTP(recorder, req)
assert.Equal(t, 401, recorder.Code)
assert.Equal(t, "text/html; charset=utf-8", recorder.Header().Get("content-type"))
})
t.Run("test login to application", func(t *testing.T) {
recorder := httptest.NewRecorder()
c, _ := gin.CreateTestContext(recorder)
form := url.Values{}
form.Set("email", env.TestCreds.Username)
form.Add("password_1", env.TestCreds.Password)
req, err := http.NewRequestWithContext(c, "POST", "/users/authenticate", strings.NewReader(form.Encode()))
if err != nil {
t.Error(err)
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
r.ServeHTTP(recorder, req)
assert.Equal(t, http.StatusFound, recorder.Code)
outFile, _ := os.Create("headers.txt")
defer outFile.Close()
writer := bufio.NewWriter(outFile)
writer.WriteString(fmt.Sprintf("%v", recorder.Result().Header))
writer.Flush()
})
/*
t.Run("test get index authenticated", func(t *testing.T) {
recorder := httptest.NewRecorder()
c, _ := gin.CreateTestContext(recorder)
c.SetCookie("medialog-sessions",
"MTcyNTk5NzI2MHxOd3dBTkZkRVFUZEhRazFKU1VWVldqVlRSRlpZUkVWSVYxQkRRMUpHTjAxTFdsVk9OME5HTWpWTVdqSkhURnBPUkVsVVNGWmFWVkU9fGYXoOEZhC7V7FyNzW3NZd0xiPTGNjOqHJg2LMMM5iex",
2592000, "/", "", false, true,
)
req, err := http.NewRequestWithContext(c, "GET", "/", nil)
if err != nil {
t.Error(err)
}
r.ServeHTTP(recorder, req)
assert.Equal(t, 200, recorder.Code)
assert.Equal(t, "text/html; charset=utf-8", recorder.Header().Get("content-type"))
})
*/
}