-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrab_test.sh
executable file
·85 lines (73 loc) · 3.21 KB
/
grab_test.sh
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
#!/bin/bash
set -e
source ./grab.sh
TMP_DIR=`mktemp -d -p /tmp/`
trap 'cleanup' EXIT
cleanup() {
rm -rf $TMPFILE
rm -rf $TMP_DIR
}
assert_equals() {
if [ "$1" == "$2" ]; then
return
else
echo "Expected [$1] but found [$2]!"
exit 1
fi
}
test_find_host() {
assert_equals "github.com" $(find_host "github.com/org/repo")
assert_equals "github.com" $(find_host "github.com/my-org/my-repo")
assert_equals "github.com" $(find_host "github.com/my-org/my-repo/path")
assert_equals "github.com" $(find_host "github.com/my-org/my-repo/path/myscript.sh")
assert_equals "github.com" $(find_host "github.com/my-org/my-repo@master")
assert_equals "github.com" $(find_host "github.com/my-org/[email protected]")
assert_equals "github.com" $(find_host "github.com/my-org/my-repo/[email protected]")
assert_equals "github.com" $(find_host "github.com/my-org/my-repo/path/[email protected]")
}
test_find_organization() {
assert_equals "org" $(find_organization "github.com/org/repo")
assert_equals "my-org" $(find_organization "github.com/my-org/my-repo")
assert_equals "my-org" $(find_organization "github.com/my-org/my-repo/path")
assert_equals "my-org" $(find_organization "github.com/my-org/my-repo/path/myscript.sh")
assert_equals "my-org" $(find_organization "github.com/my-org/my-repo@master")
assert_equals "my-org" $(find_organization "github.com/my-org/[email protected]")
assert_equals "my-org" $(find_organization "github.com/my-org/my-repo/path/@5.0.0")
assert_equals "my-org" $(find_organization "github.com/my-org/my-repo/path/[email protected]")
}
test_find_repository() {
assert_equals "repo" $(find_repository "github.com/org/repo")
assert_equals "my-repo" $(find_repository "github.com/my-org/my-repo")
assert_equals "my-repo" $(find_repository "github.com/my-org/my-repo@master")
assert_equals "my-repo" $(find_repository "github.com/my-org/[email protected]")
}
test_find_path() {
assert_equals "." $(find_path "github.com/org/repo")
assert_equals "./dir1" $(find_path "github.com/my-org/my-repo/dir1")
assert_equals "./dir1/dir2" $(find_path "github.com/my-org/my-repo/dir1/dir2")
assert_equals "./dir1/dir2/myscript.sh" $(find_path "github.com/my-org/my-repo/dir1/dir2/myscript.sh")
assert_equals "./dir1" $(find_path "github.com/my-org/my-repo/dir1@master")
assert_equals "./dir1/dir2" $(find_path "github.com/my-org/my-repo/dir1/dir2@master")
assert_equals "./dir1/dir2/myscript.sh" $(find_path "github.com/my-org/my-repo/dir1/dir2/myscript.sh@master")
assert_equals "./dir1" $(find_path "github.com/my-org/my-repoi/[email protected]")
}
test_find_version() {
assert_equals "master" $(find_version "github.com/org/repo")
assert_equals "master" $(find_version "github.com/my-org/my-repo")
assert_equals "master" $(find_version "github.com/my-org/my-repo@master")
assert_equals "5.0.0" $(find_version "github.com/my-org/[email protected]")
}
test_find_library_path() {
mkdir -p $TMP_DIR/.tests/find_library_path/cli
pushd $TMP_DIR/.tests/find_library_path/cli
touch library.sh
assert_equals "$TMP_DIR/.tests/find_library_path/cli/library.sh" $(find_library_path ".")
popd
}
test_find_host
test_find_version
test_find_organization
test_find_repository
test_find_path
test_find_library_path
echo "Grab tests completed successfully!"