Skip to content

Commit 0ecb1a8

Browse files
committed
add tests for tags check step
Signed-off-by: Taylor Silva <dev@taydev.net>
1 parent c55f2b4 commit 0ecb1a8

2 files changed

Lines changed: 186 additions & 6 deletions

File tree

test/check_tags.sh

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
source $(dirname $0)/helpers.sh
6+
7+
it_gets_all_tags() {
8+
local repo=$(init_repo)
9+
make_annotated_tag $repo foo "tag foo" true >/dev/null
10+
make_annotated_tag $repo bar "tag bar" true >/dev/null
11+
make_annotated_tag $repo wasd "tag wasd" true >/dev/null
12+
make_annotated_tag $repo other "tag other" true >/dev/null
13+
14+
check_uri_with_tags $repo | jq -e 'map(.tag) == ["foo","bar","wasd","other"]'
15+
}
16+
17+
it_uses_tag_filter() {
18+
local repo=$(init_repo)
19+
make_annotated_tag $repo foo-1 "tag foo-1" true >/dev/null
20+
make_annotated_tag $repo foo-2 "tag foo-2" true >/dev/null
21+
make_annotated_tag $repo wasd "tag wasd" true >/dev/null
22+
make_annotated_tag $repo 3-foo "tag 3-foo" true >/dev/null
23+
24+
check_uri_with_tags_filter $repo "foo-*" | jq -e 'map(.tag) == ["foo-1","foo-2"]'
25+
}
26+
27+
it_uses_tag_filters() {
28+
local repo=$(init_repo)
29+
make_annotated_tag $repo foo-1 "tag foo-1" true >/dev/null
30+
make_annotated_tag $repo foo-2 "tag foo-2" true >/dev/null
31+
make_annotated_tag $repo wasd "tag wasd" true >/dev/null
32+
make_annotated_tag $repo 3-foo "tag 3-foo" true >/dev/null
33+
34+
check_uri_with_tags_filters $repo "foo-*" | jq -e 'map(.tag) == ["foo-1","foo-2"]'
35+
}
36+
37+
it_combines_tag_filter_and_tag_filters() {
38+
local repo=$(init_repo)
39+
make_annotated_tag $repo foo-1 "tag foo-1" true >/dev/null
40+
make_annotated_tag $repo foo-2 "tag foo-2" true >/dev/null
41+
make_annotated_tag $repo wasd "tag wasd" true >/dev/null
42+
make_annotated_tag $repo 3-foo "tag 3-foo" true >/dev/null
43+
44+
check_uri_with_tags_filter_and_filters $repo "*-foo" "foo-*" \
45+
| jq -e 'map(.tag) == ["foo-1","foo-2","3-foo"]'
46+
}
47+
48+
it_uses_tag_regex() {
49+
local repo=$(init_repo)
50+
make_annotated_tag $repo foo-1 "tag foo-1" true >/dev/null
51+
make_annotated_tag $repo foo-2 "tag foo-2" true >/dev/null
52+
make_annotated_tag $repo wasd "tag wasd" true >/dev/null
53+
make_annotated_tag $repo 3-foo "tag 3-foo" true >/dev/null
54+
55+
check_uri_with_tags_regex $repo "foo-.*" | jq -e 'map(.tag) == ["foo-1","foo-2"]'
56+
}
57+
58+
it_sorts_by_semver() {
59+
local repo=$(init_repo)
60+
make_annotated_tag $repo v1.1.0 "tag v1.1.0" >/dev/null
61+
make_annotated_tag $repo v1.2.0 "tag v1.2.0" >/dev/null
62+
make_annotated_tag $repo v1.1.1 "tag v1.1.1" >/dev/null
63+
make_annotated_tag $repo v1.1.2 "tag v1.1.2" >/dev/null
64+
make_annotated_tag $repo v1.2.1 "tag v1.2.1" >/dev/null
65+
66+
check_uri_with_tags_sort $repo "semver" \
67+
| jq -e 'map(.tag) == ["v1.1.0","v1.1.1","v1.1.2","v1.2.0","v1.2.1"]'
68+
}
69+
70+
it_returns_new_tags() {
71+
local repo=$(init_repo)
72+
make_annotated_tag $repo v1.1.0 "tag v1.1.0" >/dev/null
73+
make_annotated_tag $repo v1.2.0 "tag v1.2.0" >/dev/null
74+
make_annotated_tag $repo v1.1.1 "tag v1.1.1" >/dev/null
75+
make_annotated_tag $repo v1.1.2 "tag v1.1.2" >/dev/null
76+
make_annotated_tag $repo v1.2.1 "tag v1.2.1" >/dev/null
77+
78+
check_uri_with_tags_sort_from $repo "semver" "v1.2.0" \
79+
| jq -e 'map(.tag) == ["v1.2.0","v1.2.1"]'
80+
}
81+
82+
run it_gets_all_tags
83+
run it_uses_tag_filter
84+
run it_uses_tag_filters
85+
run it_combines_tag_filter_and_tag_filters
86+
run it_uses_tag_regex
87+
run it_sorts_by_semver
88+
run it_returns_new_tags

test/helpers.sh

Lines changed: 98 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,14 +269,19 @@ make_annotated_tag() {
269269
local msg=$3
270270
local wait=${4:-false}
271271

272-
git -C $repo tag -f -a "$tag" -m "$msg"
273-
274-
git -C $repo describe --tags --abbrev=0
275-
276272
if [ "$wait" == true ]; then
277-
# Ensure creation date difference between tags - git does not sort with sub-second accuracy.
278-
sleep 1
273+
# Give each successive waited tag a distinct, increasing creation date so tags
274+
# sort deterministically. git's creatordate has only 1-second resolution, so
275+
# rather than sleeping 1s per tag we inject a monotonically increasing committer
276+
# date (the annotated tag's tagger/creator date).
277+
_annotated_tag_seq=$(( ${_annotated_tag_seq:-0} + 1 ))
278+
GIT_COMMITTER_DATE="$(date -u -d "@$(( 946684800 + _annotated_tag_seq ))" "+%Y-%m-%d %H:%M:%S +0000")" \
279+
git -C $repo tag -f -a "$tag" -m "$msg"
280+
else
281+
git -C $repo tag -f -a "$tag" -m "$msg"
279282
fi
283+
284+
git -C $repo describe --tags --abbrev=0
280285
}
281286

282287
check_uri() {
@@ -783,6 +788,93 @@ check_uri_with_branch_filters_and_regex() {
783788
}" | ${resource_dir}/check | tee /dev/stderr
784789
}
785790

791+
check_uri_with_tags() {
792+
jq -n "{
793+
source: {
794+
uri: $(echo $1 | jq -R .),
795+
version_type: \"tags\"
796+
}
797+
}" | ${resource_dir}/check | tee /dev/stderr
798+
}
799+
800+
check_uri_with_tags_filter() {
801+
local uri=$1
802+
local tag_filter=$2
803+
jq -n "{
804+
source: {
805+
uri: $(echo $uri | jq -R .),
806+
version_type: \"tags\",
807+
tag_filter: $(echo "$tag_filter" | jq -R .)
808+
}
809+
}" | ${resource_dir}/check | tee /dev/stderr
810+
}
811+
812+
check_uri_with_tags_filters() {
813+
local uri=$1
814+
shift
815+
jq -n "{
816+
source: {
817+
uri: $(echo $uri | jq -R .),
818+
version_type: \"tags\",
819+
tag_filters: $(echo "$@" | jq -R '. | split(" ")')
820+
}
821+
}" | ${resource_dir}/check | tee /dev/stderr
822+
}
823+
824+
check_uri_with_tags_filter_and_filters() {
825+
local uri=$1
826+
local tag_filter=$2
827+
shift 2
828+
jq -n "{
829+
source: {
830+
uri: $(echo $uri | jq -R .),
831+
version_type: \"tags\",
832+
tag_filter: $(echo "$tag_filter" | jq -R .),
833+
tag_filters: $(echo "$@" | jq -R '. | split(" ")')
834+
}
835+
}" | ${resource_dir}/check | tee /dev/stderr
836+
}
837+
838+
check_uri_with_tags_regex() {
839+
local uri=$1
840+
local tag_regex=$2
841+
jq -n "{
842+
source: {
843+
uri: $(echo $uri | jq -R .),
844+
version_type: \"tags\",
845+
tag_regex: $(echo "$tag_regex" | jq -R .)
846+
}
847+
}" | ${resource_dir}/check | tee /dev/stderr
848+
}
849+
850+
check_uri_with_tags_sort() {
851+
local uri=$1
852+
local tag_sort=$2
853+
jq -n "{
854+
source: {
855+
uri: $(echo $uri | jq -R .),
856+
version_type: \"tags\",
857+
tag_sort: $(echo "$tag_sort" | jq -R .)
858+
}
859+
}" | ${resource_dir}/check | tee /dev/stderr
860+
}
861+
862+
check_uri_with_tags_sort_from() {
863+
local uri=$1
864+
local tag_sort=$2
865+
local prev_tag=$3
866+
jq -n "{
867+
source: {
868+
uri: $(echo $uri | jq -R .),
869+
version_type: \"tags\",
870+
tag_sort: $(echo "$tag_sort" | jq -R .)
871+
},
872+
version: {
873+
tag: $(echo "$prev_tag" | jq -R .)
874+
}
875+
}" | ${resource_dir}/check | tee /dev/stderr
876+
}
877+
786878
get_uri() {
787879
jq -n "{
788880
source: {

0 commit comments

Comments
 (0)