-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi_test.go
100 lines (72 loc) · 1.97 KB
/
api_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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package main
// TODO: separate package for testing
import (
"fmt"
//"io"
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"
)
var (
server *httptest.Server
//reader io.Reader
)
func init() {
// Create server for testing
server = httptest.NewServer(NewRouter())
}
// func TestMain(m *testing.M) {
// fmt.Println("Testing initiated")
// os.Exit(m.Run())
// }
func TestAuthSpotify(t *testing.T) {
fmt.Println("Starting TestAuthSpotify")
//t.log("Starting TestAuthSpotify")
authSpotifyUrl := fmt.Sprintf("%s/authspotify", server.URL)
reader := strings.NewReader("")
req, err := http.NewRequest("GET", authSpotifyUrl, reader)
res, err := http.DefaultClient.Do(req)
if err != nil {
t.Error(err)
}
if res.StatusCode != 200 {
t.Errorf("Success expected: %d", res.StatusCode)
}
}
func TestCreatePartyController(t *testing.T) {
fmt.Println("Starting TestCreatePartyController")
createPartyUrl := fmt.Sprintf("%s/dashboard/createparty", server.URL)
form := url.Values{}
form.Add("user", "my_user")
form.Add("location", "my_location")
form.Add("secret-code", "my_code")
form.Add("active-time", "my_time")
reader := strings.NewReader(form.Encode())
req, err := http.NewRequest("POST", createPartyUrl, reader)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
res, err := http.DefaultClient.Do(req)
if err != nil {
t.Error(err)
}
if res.StatusCode != 200 {
t.Errorf("Success expected: %d", res.StatusCode)
}
}
func TestSearchSong(t *testing.T) {
fmt.Println("Starting TestSearchSong")
searchSongUrl := fmt.Sprintf("%s/searchsong", server.URL)
form := url.Values{}
form.Add("searchsong", "halo")
reader := strings.NewReader(form.Encode())
req, err := http.NewRequest("GET", searchSongUrl, reader)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
res, err := http.DefaultClient.Do(req)
if err != nil {
t.Error(err)
}
if res.StatusCode != 200 {
t.Errorf("Success expected: %d", res.StatusCode)
}
}