Skip to content

Commit

Permalink
add testcase for path filtering on branch
Browse files Browse the repository at this point in the history
Signed-off-by: Hoogervorst <[email protected]>
  • Loading branch information
Hoogervorst committed Sep 30, 2019
1 parent c7ce409 commit 0d0e9f8
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,22 @@ it_checks_given_paths() {
"
}

it_checks_given_paths_on_branch() {
local repo=$(init_repo)
local ref1=$(make_commit_to_file_on_branch_with_path $repo dummy file-b master)
echo $ref1
local ref2=$(make_commit_to_file_on_branch_with_path $repo dummy file-b master)
echo $ref2
local ref3=$(make_commit_to_file_on_branch_with_path $repo dummy file-b newbranch)
echo $ref3
local result=$(check_uri_from_paths_with_branch $repo newbranch "dummy/*")
echo result

check_uri_from_paths_with_branch $repo newbranch "dummy/*"| jq -e "
. == [{ref: $(echo $ref3 | jq -R .)}]
"
}

it_checks_given_glob_paths() { # issue gh-120
local repo=$(init_repo)
mkdir -p $repo/a/b
Expand Down Expand Up @@ -657,6 +673,7 @@ run it_can_check_from_a_first_commit_in_repo
run it_can_check_from_a_bogus_sha
run it_skips_ignored_paths
run it_checks_given_paths
run it_checks_given_paths_on_branch
run it_checks_given_glob_paths
run it_checks_given_ignored_paths
run it_can_check_when_not_ff
Expand Down
44 changes: 44 additions & 0 deletions test/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,34 @@ make_commit_to_file_on_branch() {
git -C $repo rev-parse HEAD
}

make_commit_to_file_on_branch_with_path() {
local repo=$1
local path=$2
local file=$3
local branch=$4
local msg=${5-}

# ensure branch exists
if ! git -C $repo rev-parse --verify $branch >/dev/null; then
git -C $repo branch $branch master
fi

# switch to branch
git -C $repo checkout -q $branch

# modify file and commit
mkdir -p $repo/$path
echo x >> $repo/$path/$file
git -C $repo add $path/$file
git -C $repo \
-c user.name='test' \
-c user.email='[email protected]' \
commit -q -m "commit $(wc -l $repo/$path/$file) $msg"

# output resulting sha
git -C $repo rev-parse HEAD
}

make_commit_to_file() {
make_commit_to_file_on_branch $1 $2 master "${3-}"
}
Expand Down Expand Up @@ -352,6 +380,22 @@ check_uri_from_paths() {
}" | ${resource_dir}/check | tee /dev/stderr
}

check_uri_from_paths_with_branch() {
local uri=$1
local branch=$2

shift 2

jq -n "{
source: {
uri: $(echo $uri | jq -R .),
paths: $(echo "$@" | jq -R '. | split(" ")'),
branch: $(echo $branch | jq -R .),
disable_ci_skip: true
},
}" | ${resource_dir}/check | tee /dev/stderr
}

check_uri_from_paths_ignoring() {
local uri=$1
local ref=$2
Expand Down

0 comments on commit 0d0e9f8

Please sign in to comment.