-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain_test.go
62 lines (53 loc) · 1.47 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
59
60
61
62
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"os"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
type User struct {
Name string `json:"name"`
Username string `json:"username"`
Email string `json:"email"`
Password string `json:"password"`
}
type Response struct {
Token string `json:"token"`
}
var (
user = &User{Name: "DummyUser", Username: "username", Password: "password", Email: "email@email.com"}
server *httptest.Server
)
func TestMain(m *testing.M) {
server = httptest.NewServer(Server(nil, nil, nil))
fmt.Println("Server URL", server.URL)
defer server.Close()
os.Exit(m.Run())
}
func TestIndex(t *testing.T) {
Convey("Should be able to access index and redirect to APIv1 index", t, func() {
res, _ := http.Get(server.URL)
defer res.Body.Close()
So(res.StatusCode, ShouldEqual, 200)
})
}
func TestLogin(t *testing.T) {
Convey("Should be able to login", t, func() {
// jsondata, _ := json.Marshal(user)
// data := strings.NewReader(string(jsondata))
// req, _ := http.NewRequest("POST", server.URL+"/api/v1/auth/signup", data)
// client := &http.Client{}
// res, err := client.Do(req)
// fmt.Println(res, err)
// So(res.StatusCode, ShouldEqual, 200)
// res, _ := http.PostForm(server.URL+"/api/v1/auth/signup", url.Values{
// "username": {user.Username},
// "password": {user.Password},
// "name": {user.Name},
// "email": {user.Email},
// })
// So(res.StatusCode, ShouldEqual, 200)
})
}