-
Notifications
You must be signed in to change notification settings - Fork 3
/
backport.functions_tests
executable file
·82 lines (67 loc) · 3.26 KB
/
backport.functions_tests
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
#!/usr/bin/env bash
set -eu
SCRIPT_DIR=$(readlink -f "$0")
SCRIPT_DIR="$(dirname "${SCRIPT_DIR}")"
# Source the latest version of assert.sh unit testing library and include in current shell
curl --silent https://raw.githubusercontent.com/hazelcast/assert.sh/main/assert.sh --output assert.sh
# shellcheck source=/dev/null
# You _should_ be able to avoid a temporary file with something like
# . <(echo "${assert_script_content}")
# But this doesn't work on the MacOS GitHub runner (but does on MacOS locally)
. assert.sh
# shellcheck source=/dev/null
. "${SCRIPT_DIR}"/backport.functions
TESTS_RESULT=0
function test_get_pr_number {
local commit_msg=$1
local expected_pr_number=$2
local actual_pr_number=$(get_pr_number "$commit_msg")
local MSG="Expected PR Number extracted from \"$commit_msg\" should be equal to \"$expected_pr_number\""
assert_eq "$expected_pr_number" "$actual_pr_number" "$MSG" && log_success "$MSG" || TESTS_RESULT=$?
}
function test_get_pr_reviewers {
local repo_upstream=$1
local pr_number=$2
local expected_reviewers=$3
local actual_reviewers=$(get_pr_reviewers "$repo_upstream" "$pr_number")
local MSG="Expected reviewers extracted from \"$repo_upstream/pull/$pr_number\" should be equal to \"$expected_reviewers\""
assert_eq "$expected_reviewers" "$actual_reviewers" "$MSG" && log_success "$MSG" || TESTS_RESULT=$?
}
function test_get_pr_labels {
local repo_upstream=$1
local pr_number=$2
local expected_labels=$3
local actual_labels=$(get_pr_labels "$repo_upstream" "$pr_number")
local MSG="Expected labels extracted from \"$repo_upstream/pull/$pr_number\" should be equal to \"$actual_labels\""
assert_eq "$expected_labels" "$actual_labels" "$MSG" && log_success "$MSG" || TESTS_RESULT=$?
}
function test_check_if_milestone_in_repo {
local repo_upstream=$1
local milestone=$2
local expected_output=$3
local actual_output=$(check_if_milestone_in_repo "$repo_upstream" "$milestone")
local MSG="Queried \"$repo_upstream\" for milestone \"$milestone\", expecting \"$expected_output\""
assert_eq "$expected_output" "$actual_output" "$MSG" && log_success "$MSG" || TESTS_RESULT=$?
}
function test_get_branch_from_ref {
local ref=$1
local expected_branch=$2
local actual_branch=$(get_branch_from_ref "$ref")
local MSG="Expected branch extracted from \"$ref\" should be equal to \"$actual_branch\""
assert_eq "$expected_branch" "$actual_branch" "$MSG" && log_success "$MSG" || TESTS_RESULT=$?
}
log_header "Tests for get_pr_number"
test_get_pr_number 'Fix private test repository access [DI-236] (#221)' '221'
test_get_pr_number 'Fix private test repository access [DI-236] (#221) (#222)' '222'
log_header "Tests for get_pr_reviewers"
test_get_pr_reviewers 'hazelcast/backport' '1' 'ldziedziul'
log_header "Tests for get_pr_labels"
test_get_pr_labels 'hazelcast/backport' '1' 'enhancement'
log_header "Tests for check_if_milestone_in_repo"
# https://github.com/hazelcast/hazelcast/milestones
test_check_if_milestone_in_repo 'hazelcast/hazelcast' '2.1' 'true'
test_check_if_milestone_in_repo 'hazelcast/hazelcast' 'this-milestone-does-not-exist' 'false'
log_header "Tests for get_branch_from_ref"
test_get_branch_from_ref 'upstream/5.2.z' '5.2.z'
test_get_branch_from_ref 'upstream/v/5.2' 'v/5.2'
assert_eq 0 "$TESTS_RESULT" "All tests should pass"