@@ -17,38 +17,48 @@ import (
1717 "github.com/stretchr/testify/assert"
1818)
1919
20- func TestLinksNoLogin (t * testing.T ) {
20+ func assertLinkPageComplete (t * testing.T , session * TestSession , link string ) {
21+ req := NewRequest (t , "GET" , link )
22+ resp := session .MakeRequest (t , req , http .StatusOK )
23+ assert .True (t , test .IsNormalPageCompleted (resp .Body .String ()), "Page did not complete: " + link )
24+ }
25+
26+ func TestLinks (t * testing.T ) {
2127 defer tests .PrepareTestEnv (t )()
2228
29+ t .Run ("NoLogin" , testLinksNoLogin )
30+ t .Run ("RedirectsNoLogin" , testLinksRedirectsNoLogin )
31+ t .Run ("NoLoginNotExist" , testLinksNoLoginNotExist )
32+ t .Run ("AsUser" , testLinksAsUser )
33+ t .Run ("RepoCommon" , testLinksRepoCommon )
34+ }
35+
36+ func testLinksNoLogin (t * testing.T ) {
2337 links := []string {
38+ "/" ,
2439 "/explore/repos" ,
2540 "/explore/repos?q=test" ,
2641 "/explore/users" ,
2742 "/explore/users?q=test" ,
2843 "/explore/organizations" ,
2944 "/explore/organizations?q=test" ,
30- "/" ,
3145 "/user/sign_up" ,
3246 "/user/login" ,
3347 "/user/forgot_password" ,
34- "/api/swagger" ,
3548 "/user2/repo1" ,
3649 "/user2/repo1/" ,
3750 "/user2/repo1/projects" ,
3851 "/user2/repo1/projects/1" ,
3952 "/user2/repo1/releases/tag/delete-tag" , // It's the only one existing record on release.yml which has is_tag: true
40- "/.well-known/security.txt " ,
53+ "/api/swagger " ,
4154 }
42-
4355 for _ , link := range links {
44- req := NewRequest (t , "GET" , link )
45- MakeRequest (t , req , http .StatusOK )
56+ assertLinkPageComplete (t , nil , link )
4657 }
58+ MakeRequest (t , NewRequest (t , "GET" , "/.well-known/security.txt" ), http .StatusOK )
4759}
4860
49- func TestRedirectsNoLogin (t * testing.T ) {
50- defer tests .PrepareTestEnv (t )()
51-
61+ func testLinksRedirectsNoLogin (t * testing.T ) {
5262 redirects := []struct { from , to string }{
5363 {"/user2/repo1/commits/master" , "/user2/repo1/commits/branch/master" },
5464 {"/user2/repo1/src/master" , "/user2/repo1/src/branch/master" },
@@ -68,9 +78,7 @@ func TestRedirectsNoLogin(t *testing.T) {
6878 }
6979}
7080
71- func TestNoLoginNotExist (t * testing.T ) {
72- defer tests .PrepareTestEnv (t )()
73-
81+ func testLinksNoLoginNotExist (t * testing.T ) {
7482 links := []string {
7583 "/user5/repo4/projects" ,
7684 "/user5/repo4/projects/3" ,
@@ -82,7 +90,8 @@ func TestNoLoginNotExist(t *testing.T) {
8290 }
8391}
8492
85- func testLinksAsUser (userName string , t * testing.T ) {
93+ func testLinksAsUser (t * testing.T ) {
94+ session := loginUser (t , "user2" )
8695 links := []string {
8796 "/explore/repos" ,
8897 "/explore/repos?q=test" ,
@@ -130,18 +139,14 @@ func testLinksAsUser(userName string, t *testing.T) {
130139 "/user/settings/repos" ,
131140 }
132141
133- session := loginUser (t , userName )
134142 for _ , link := range links {
135- req := NewRequest (t , "GET" , link )
136- session .MakeRequest (t , req , http .StatusOK )
143+ assertLinkPageComplete (t , session , link )
137144 }
138145
139- reqAPI := NewRequestf (t , "GET" , "/api/v1/users/%s /repos" , userName )
146+ reqAPI := NewRequestf (t , "GET" , "/api/v1/users/user2 /repos" )
140147 respAPI := MakeRequest (t , reqAPI , http .StatusOK )
141-
142148 var apiRepos []* api.Repository
143149 DecodeJSON (t , respAPI , & apiRepos )
144-
145150 repoLinks := []string {
146151 "" ,
147152 "/issues" ,
@@ -164,24 +169,15 @@ func testLinksAsUser(userName string, t *testing.T) {
164169 "/wiki/?action=_new" ,
165170 "/activity" ,
166171 }
167-
168172 for _ , repo := range apiRepos {
169173 for _ , link := range repoLinks {
170- req := NewRequest ( t , "GET" , fmt .Sprintf ("/%s /%s%s" , userName , repo .Name , link ) )
171- session . MakeRequest (t , req , http . StatusOK )
174+ link = fmt .Sprintf ("/user2 /%s%s" , repo .Name , link )
175+ assertLinkPageComplete (t , session , link )
172176 }
173177 }
174178}
175179
176- func TestLinksLogin (t * testing.T ) {
177- defer tests .PrepareTestEnv (t )()
178-
179- testLinksAsUser ("user2" , t )
180- }
181-
182- func TestRepoLinks (t * testing.T ) {
183- defer tests .PrepareTestEnv (t )()
184-
180+ func testLinksRepoCommon (t * testing.T ) {
185181 // repo1 has enabled almost features, so we can test most links
186182 repoLink := "/user2/repo1"
187183 links := []string {
@@ -192,21 +188,18 @@ func TestRepoLinks(t *testing.T) {
192188
193189 // anonymous user
194190 for _ , link := range links {
195- req := NewRequest (t , "GET" , repoLink + link )
196- MakeRequest (t , req , http .StatusOK )
191+ assertLinkPageComplete (t , nil , repoLink + link )
197192 }
198193
199194 // admin/owner user
200195 session := loginUser (t , "user1" )
201196 for _ , link := range links {
202- req := NewRequest (t , "GET" , repoLink + link )
203- session .MakeRequest (t , req , http .StatusOK )
197+ assertLinkPageComplete (t , session , repoLink + link )
204198 }
205199
206200 // non-admin non-owner user
207201 session = loginUser (t , "user2" )
208202 for _ , link := range links {
209- req := NewRequest (t , "GET" , repoLink + link )
210- session .MakeRequest (t , req , http .StatusOK )
203+ assertLinkPageComplete (t , session , repoLink + link )
211204 }
212205}
0 commit comments