Skip to content

Commit c7d0320

Browse files
committed
test: Add 'fake_link' test function
1 parent 5241c91 commit c7d0320

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

pkg/lib/util/ensure.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ ensure.non_zero() {
3333
# that is not an expectation
3434
# @arg $1 package
3535
ensure.package_exists() {
36-
local package="$1"
36+
local id="$1"
3737

38-
if [ ! -d "$BPM_PACKAGES_PATH/$package" ]; then
39-
die "Package '$package' does not exist"
38+
if [ ! -d "$BPM_PACKAGES_PATH/$id" ]; then
39+
die "Package '$id' does not exist"
4040
fi
4141
}

tests/do-list.bats

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ load 'util/init.sh'
1717
test_util.create_package 'username/p1'
1818
test_util.create_package 'username2/p2'
1919
test_util.create_package 'username2/p3'
20-
test_util.fake_clone "$site/username/p1"
21-
test_util.fake_clone "$site/username2/p2"
20+
test_util.fake_add "username/p1"
21+
test_util.fake_add "username2/p2"
2222

2323
run do-list --simple
2424

@@ -52,8 +52,8 @@ load 'util/init.sh'
5252
test_util.create_package 'username/p1'
5353
test_util.create_package 'username2/p2'
5454
test_util.create_package 'username2/p3'
55-
test_util.fake_clone "$site/username/p1"
56-
test_util.fake_clone "$site/username2/p2"
55+
test_util.fake_add "username/p1"
56+
test_util.fake_add "username2/p2"
5757

5858
run do-list
5959

tests/util/test_util.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,31 @@ test_util.fake_add() {
2323
local pkg="$1"
2424
ensure.non_zero 'pkg' "$pkg"
2525

26-
test_util.fake_clone "github.com/$pkg"
26+
git clone "$BPM_ORIGIN_DIR/github.com/$pkg" "$BPM_PACKAGES_PATH/github.com/$pkg"
2727
do-plumbing-add-deps "github.com/$pkg"
2828
do-plumbing-link-bins "github.com/$pkg"
2929
do-plumbing-link-completions "github.com/$pkg"
3030
do-plumbing-link-man "github.com/$pkg"
3131
}
3232

33+
# @description Mocks a 'bpm link'
34+
test_util.fake_link() {
35+
local pkg="$1"
36+
ensure.non_zero 'pkg' "$pkg"
37+
38+
mkdir -p "$BPM_PACKAGES_PATH/local"
39+
40+
ls -al "$BPM_ORIGIN_DIR/github.com/$pkg" >&3
41+
ls -al "$BPM_PACKAGES_PATH/local" >&3
42+
mkdir -p "$BPM_PACKAGES_PATH/local"
43+
ln -s "$BPM_ORIGIN_DIR/github.com/$pkg" "$BPM_PACKAGES_PATH/local"
44+
45+
do-plumbing-add-deps "$pkg"
46+
do-plumbing-link-bins "$pkg"
47+
do-plumbing-link-completions "$pkg"
48+
do-plumbing-link-man "$pkg"
49+
}
50+
3351
# @description Creates a 'bpm package', and cd's into it
3452
test_util.setup_pkg() {
3553
local pkg="$1"
@@ -39,6 +57,7 @@ test_util.setup_pkg() {
3957
cd "$BPM_ORIGIN_DIR/github.com/$pkg"
4058

4159
git init .
60+
git branch -M master
4261
touch 'README.md'
4362
git add .
4463
git commit -m "Initial commit"
@@ -57,7 +76,7 @@ test_util.create_package() {
5776
ensure.non_zero 'pkg' "$pkg"
5877

5978
test_util.setup_pkg "$pkg"; {
60-
git branch -M master
79+
:
6180
}; test_util.finish_pkg
6281
}
6382

0 commit comments

Comments
 (0)