-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_test.go
79 lines (67 loc) · 1.86 KB
/
app_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
package main
import (
"github.com/mlzyplntsyntk/go4web/core"
"net/http"
"net/http/httptest"
"testing"
)
func makeRequest(url string, configFile string) (int, string) {
config := core.GetConfigFromJSON(configFile)
addHandlers()
req, _ := http.NewRequest("GET", url, nil)
w := httptest.NewRecorder()
core.MainHandler(config).ServeHTTP(w, req)
result := w.Body.String()
return w.Code, result
}
func makeRequestForSingleLanguage(url string) (int, string) {
return makeRequest(url, "./config_test_single.json")
}
func makeRequestForMultiLanguage(url string) (int, string) {
return makeRequest(url, "./config.json")
}
func TestExistingPage(t *testing.T) {
code, result := makeRequestForSingleLanguage("/anasayfa")
if code != http.StatusOK {
t.Errorf("HttpStatus is not 200, %s", code)
}
if result != "Anasayfa" {
t.Errorf("Unexpected body: %v", result)
}
}
func TestNonExistentPage(t *testing.T) {
code, _ := makeRequestForSingleLanguage("/home")
if code != http.StatusNotFound {
t.Errorf("HttpStatus is not 404, %s", code)
}
}
func TestRedirection(t *testing.T) {
code, _ := makeRequestForMultiLanguage("/home")
if code != 301 {
t.Errorf("HttpStatus is not 301, %s", code)
}
}
func TestMultiDefaultLanguageHome(t *testing.T) {
code, result := makeRequestForMultiLanguage("/")
if code != http.StatusOK {
t.Errorf("HttpStatus is not OK, %s", code)
}
if result != "Home" {
t.Errorf("Default Language's home page not here ?")
}
}
func TestMultiLanguagePage(t *testing.T) {
code, result := makeRequestForMultiLanguage("/tr/anasayfa")
if code != http.StatusOK {
t.Errorf("HttpStatus is not OK, %s", code)
}
if result != "Anasayfa" {
t.Errorf("Anasayfa ?")
}
}
func TestMultiLanguageNonExistentPage(t *testing.T) {
code, _ := makeRequestForMultiLanguage("/tr/babasayfa")
if code != http.StatusNotFound {
t.Errorf("HttpStatus is not 404 %s", code)
}
}