Skip to content

Commit 2d64488

Browse files
authored
add tests for some pages; increase wait time to ensure the repo get cloned (#281)
1 parent e267ff8 commit 2d64488

File tree

1 file changed

+128
-5
lines changed

1 file changed

+128
-5
lines changed

tests/first_run.v

Lines changed: 128 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,34 @@ fn main() {
3535
test_user_page(test_username)
3636
test_login_with_token(test_username, token)
3737
test_static_served()
38+
test_oauth_page()
3839

3940
test_create_repo(token, 'test1', '')
4041
assert get_repo_commit_count(token, test_username, 'test1', default_branch) == 0
4142
assert get_repo_issue_count(token, test_username, 'test1') == 0
4243
assert get_repo_branch_count(token, test_username, 'test1') == 0
4344

44-
test_create_repo(token, 'test2', test_github_repo_url)
45+
repo_name := 'test2'
46+
test_create_repo(token, repo_name, test_github_repo_url)
4547
// wait while repo is cloning
46-
time.sleep(3 * time.second)
48+
time.sleep(5 * time.second)
4749
// get repo
48-
assert get_repo_commit_count(token, test_username, 'test2', test_github_repo_primary_branch) > 0
49-
assert get_repo_issue_count(token, test_username, 'test2') == 0
50-
assert get_repo_branch_count(token, test_username, 'test2') > 0
50+
assert get_repo_commit_count(token, test_username, repo_name, test_github_repo_primary_branch) > 0
51+
assert get_repo_issue_count(token, test_username, repo_name) == 0
52+
assert get_repo_branch_count(token, test_username, repo_name) > 0
53+
test_repo_page(test_username, repo_name)
54+
test_branch_page(test_username, repo_name, test_github_repo_primary_branch)
55+
test_repos_page(test_username)
56+
test_repo_settings_page(test_username, repo_name)
57+
test_contributors_page(test_username, repo_name)
58+
// test_issues_page(test_username)
59+
test_stars_page(test_username)
60+
test_settings_page(test_username)
61+
test_commits_page(test_username, repo_name, test_github_repo_primary_branch)
62+
test_branches_page(test_username, repo_name)
63+
test_repo_tree(test_username, repo_name, test_github_repo_primary_branch, 'c')
64+
// test_refs_page(test_username, repo_name)
65+
// test_api_branches_count(test_username, repo_name)
5166
ilog("all tests passed!")
5267

5368
after()!
@@ -188,6 +203,114 @@ fn test_user_page(username string) {
188203
assert user_page_result.body.contains('<h3>${username}</h3>')
189204
}
190205

206+
fn test_repo_page(username string, repo_name string) {
207+
ilog('Testing the new repo /${username}/${repo_name} page is up')
208+
repo_page_result := http.get(prepare_url("${username}/${repo_name}")) or { exit_with_message(err.str()) }
209+
210+
assert repo_page_result.status_code == 200
211+
}
212+
213+
fn test_branch_page(username string, repo_name string, branch_name string) {
214+
ilog('Testing the new branch /${username}/${repo_name}/tree/${branch_name} page is up')
215+
branch_page_result := http.get(prepare_url("${username}/${repo_name}/tree/${branch_name}")) or { exit_with_message(err.str()) }
216+
217+
assert branch_page_result.status_code == 200
218+
}
219+
220+
fn test_repos_page(username string) {
221+
ilog('Testing the new repos /${username}/repos page is up')
222+
repos_page_result := http.get(prepare_url("${username}/repos")) or { exit_with_message(err.str()) }
223+
224+
assert repos_page_result.status_code == 200
225+
}
226+
227+
fn test_contributors_page(username string, repo_name string) {
228+
ilog('Testing the new contributors /${username}/${repo_name}/contributors page is up')
229+
contributors_page_result := http.get(prepare_url("${username}/${repo_name}/contributors")) or { exit_with_message(err.str()) }
230+
231+
assert contributors_page_result.status_code == 200
232+
}
233+
234+
fn test_commits_page(username string, repo_name string, branch_name string) {
235+
ilog('Testing the new commits /${username}/${repo_name}/${branch_name}/commits/1 page is up')
236+
// Doesn't work with commits/[no 1]
237+
commits_page_result := http.get(prepare_url("${username}/${repo_name}/${branch_name}/commits/1")) or { exit_with_message(err.str()) }
238+
239+
assert commits_page_result.status_code == 200
240+
}
241+
242+
fn test_branches_page(username string, repo_name string) {
243+
ilog('Testing the new branches /${username}/${repo_name}/branches page is up')
244+
branches_page_result := http.get(prepare_url("${username}/${repo_name}/branches")) or { exit_with_message(err.str()) }
245+
246+
assert branches_page_result.status_code == 200
247+
}
248+
249+
fn test_api_branches_count(username string, repo_name string) {
250+
ilog('Testing if api/v1/${username}/${repo_name}/branches/count works')
251+
api_branches_count_result := http.get(prepare_url("api/v1/${username}/${repo_name}/branches/count")) or { exit_with_message(err.str()) }
252+
// api_branches_count_result := http.fetch(
253+
// method: .get
254+
// url: prepare_url("api/v1/${username}/${repo_name}/branches/count")
255+
// ) or { exit_with_message(err.str()) }
256+
257+
assert api_branches_count_result.status_code == 200
258+
259+
response_json := json.decode(api.ApiBranchCount, api_branches_count_result.body) or {
260+
exit_with_message(err.str())
261+
}
262+
assert response_json.result > 0
263+
}
264+
265+
fn test_refs_page(username string, repo_name string) {
266+
ilog('Testing the new refs /${username}/${repo_name}/info/refs page is up')
267+
refs_page_result := http.get(prepare_url("${username}/${repo_name}/info/refs")) or { exit_with_message(err.str()) }
268+
269+
assert refs_page_result.status_code == 200
270+
}
271+
272+
fn test_oauth_page() {
273+
ilog('Testing the new oauth /oauth page is up')
274+
oauth_page_result := http.get(prepare_url("oauth")) or { exit_with_message(err.str()) }
275+
276+
assert oauth_page_result.status_code == 200
277+
}
278+
279+
fn test_repo_tree(username string, repo_name string, branch_name string, path string) {
280+
ilog('Testing the new tree /${username}/${repo_name}/tree/${branch_name}/${path} page is up')
281+
repo_tree_result := http.get(prepare_url("${username}/${repo_name}/tree/${branch_name}/${path}")) or { exit_with_message(err.str()) }
282+
283+
assert repo_tree_result.status_code == 200
284+
}
285+
// fn test_issues_page(username string) {
286+
// test_endpoint_page("${username}/issues", 'issues')
287+
// }
288+
289+
fn test_stars_page(username string) {
290+
ilog("Testing the new stars /${username}/stars page is up")
291+
stars_page_result := http.get(prepare_url("${username}/stars")) or { exit_with_message(err.str()) }
292+
293+
assert stars_page_result.status_code == 200
294+
}
295+
296+
fn test_settings_page(username string) {
297+
ilog('Testing the new settings /${username}/settings page is up')
298+
settings_page_result := http.get(prepare_url("${username}/settings")) or { exit_with_message(err.str()) }
299+
300+
assert settings_page_result.status_code == 200
301+
}
302+
303+
fn test_repo_settings_page(username string, repo_name string) {
304+
test_endpoint_page("${username}/${repo_name}/settings", 'settings')
305+
}
306+
307+
fn test_endpoint_page(endpoint string, pagename string) {
308+
ilog('Testing the new ${pagename} /${endpoint} page is up')
309+
endpoint_result := http.get(prepare_url("${endpoint}")) or { exit_with_message(err.str()) }
310+
311+
assert endpoint_result.status_code == 200
312+
}
313+
191314
fn test_login_with_token(username string, token string) {
192315
ilog('Try to login in with `${username}` user token')
193316

0 commit comments

Comments
 (0)