4
4
5
5
source $( dirname $0 ) /helpers.sh
6
6
7
+ check_jq_functionality () {
8
+ # Ensure JQ correctly treats empty input as invalid
9
+ set +e
10
+ jq -e ' type == "string"' < /dev/null
11
+ if [ $? -eq 0 ]; then
12
+ echo " WARNING - Outdated JQ - please update! Some tests may have incorrectly pass"
13
+ fi
14
+ set -e
15
+ }
16
+
7
17
it_can_check_from_head () {
8
18
local repo=$( init_repo)
9
19
local ref=$( make_commit $repo )
@@ -644,6 +654,97 @@ it_can_check_with_tag_filter() {
644
654
"
645
655
}
646
656
657
+ it_can_check_with_tag_and_path_match_filter () {
658
+ local repo=$( init_repo)
659
+ local ref1=$( make_commit_to_file $repo file-a)
660
+ local ref2=$( make_annotated_tag $repo " 1.0-staging" " tag 1" true)
661
+ local ref3=$( make_commit_to_file $repo file-b)
662
+ local ref4=$( make_annotated_tag $repo " 1.0-production" " tag 2" true)
663
+ local ref5=$( make_annotated_tag $repo " 2.0-staging" " tag 3" true)
664
+ local ref6=$( make_commit_to_file $repo file-c)
665
+ local ref7=$( make_annotated_tag $repo " 2.0-staging" " tag 5" true)
666
+ local ref8=$( make_commit_to_file $repo file-b)
667
+ local ref9=$( make_annotated_tag $repo " 2.0-production" " tag 4" true)
668
+ local ref10=$( make_commit_to_file $repo file-c)
669
+
670
+ check_uri_with_tag_and_path_filter $repo " 2*" " match_tagged" file-c | jq -e "
671
+ . == [{ref: \" 2.0-staging\" , commit: \" $ref6 \" }]
672
+ "
673
+
674
+ # No matching files. ref3's tag was replaced by the tag on ref6 - which does not path match
675
+ check_uri_with_tag_and_path_filter $repo " *-staging" " match_tagged" file-b | jq -e "
676
+ . == []
677
+ "
678
+
679
+ # Although multiple tagged commits modify the files, ref8 is the latest (and version_depth is default 1)
680
+ check_uri_with_tag_and_path_filter $repo " *" " match_tagged" file-b file-c | jq -e "
681
+ . == [
682
+ {ref: \" 2.0-production\" , commit: \" $ref8 \" }
683
+ ]
684
+ "
685
+
686
+ # file-f was never created
687
+ check_uri_with_tag_and_path_filter $repo " *" " match_tagged" file-f | jq -e "
688
+ . == []
689
+ "
690
+
691
+ # no tags matching 4.0-*
692
+ check_uri_with_tag_and_path_filter $repo " 4.0-*" " match_tagged" file-c | jq -e "
693
+ . == []
694
+ "
695
+ }
696
+
697
+ it_can_check_with_tag_and_path_match_ancestors_filter () {
698
+ local repo=$( init_repo)
699
+ local ref1=$( make_commit_to_file $repo file-a)
700
+ local ref2=$( make_annotated_tag $repo " 1.0-staging" " tag 1" true)
701
+ local ref3=$( make_commit_to_file $repo file-b)
702
+ local ref4=$( make_annotated_tag $repo " 1.0-production" " tag 2" true)
703
+ local ref5=$( make_annotated_tag $repo " 2.0-staging" " tag 3" true)
704
+ local ref6=$( make_commit_to_file $repo file-c)
705
+ local ref7=$( make_annotated_tag $repo " 2.0-staging" " tag 5" true)
706
+ local ref8=$( make_commit_to_file $repo file-b)
707
+ local ref9=$( make_annotated_tag $repo " 2.0-production" " tag 4" true)
708
+ local ref10=$( make_commit_to_file $repo file-c)
709
+
710
+ # ref10 is the most recent to modify file-c, but the latest 2* tag is before it. Therefore ref6 matches.
711
+ check_uri_with_tag_and_path_filter $repo " 2*" " match_tag_ancestors" file-c | jq -e "
712
+ . == [{ref: \" $ref6 \" }]
713
+ "
714
+
715
+ # ref3 is the most recent commit to modify file-b, and following commits have -staging tags
716
+ check_uri_with_tag_and_path_filter $repo " *-staging" " match_tag_ancestors" file-b | jq -e "
717
+ . == [{ref: \" $ref3 \" }]
718
+ "
719
+
720
+ # although no 2.* tagged commits modified file-a, they follow on from commits that did
721
+ check_uri_with_tag_and_path_filter $repo " 2.*" " match_tag_ancestors" file-a | jq -e "
722
+ . == [{ref: \" $ref1 \" }]
723
+ "
724
+
725
+ # no commits creating file-c are followed by 1.* tags
726
+ check_uri_with_tag_and_path_filter $repo " 1.*" " match_tag_ancestors" file-c | jq -e "
727
+ . == []
728
+ "
729
+
730
+ # Although multiple tagged commits modify the files, ref8 is the latest (and version_depth is default 1)
731
+ check_uri_with_tag_and_path_filter $repo " *" " match_tag_ancestors" file-b file-c | jq -e "
732
+ . == [
733
+ {ref: \" $ref8 \" }
734
+ ]
735
+ "
736
+
737
+ # file-f was never created
738
+ check_uri_with_tag_and_path_filter $repo " *" " match_tag_ancestors" file-f | jq -e "
739
+ . == []
740
+ "
741
+
742
+ # no tags matching 4.0-*
743
+ check_uri_with_tag_and_path_filter $repo " 4.0-*" " match_tag_ancestors" file-c | jq -e "
744
+ . == []
745
+ "
746
+ }
747
+
647
748
it_can_check_with_tag_regex () {
648
749
local repo=$( init_repo)
649
750
local ref1=$( make_commit $repo )
@@ -679,7 +780,7 @@ it_can_check_with_tag_filter_with_cursor() {
679
780
local ref13=$( make_commit $repo )
680
781
681
782
x=$( check_uri_with_tag_filter_from $repo " *-staging" " 2.0-staging" )
682
- check_uri_with_tag_filter_from $repo " *-staging" " 2.0-staging" | jq -e "
783
+ check_uri_with_tag_filter_from $repo " *-staging" " 2.0-staging" 2 | jq -e "
683
784
. == [{ref: \" 2.0-staging\" , commit: \" $ref5 \" }, {ref: \" 3.0-staging\" , commit: \" $ref9 \" }]
684
785
"
685
786
}
@@ -701,7 +802,7 @@ it_can_check_with_tag_regex_with_cursor() {
701
802
local ref13=$( make_commit $repo )
702
803
703
804
x=$( check_uri_with_tag_regex_from $repo " .*-staging" " 2.0-staging" )
704
- check_uri_with_tag_regex_from $repo " .*-staging" " 2.0-staging" | jq -e "
805
+ check_uri_with_tag_regex_from $repo " .*-staging" " 2.0-staging" 2 | jq -e "
705
806
. == [{ref: \" 2.0-staging\" , commit: \" $ref5 \" }, {ref: \" 3.0-staging\" , commit: \" $ref9 \" }]
706
807
"
707
808
}
@@ -765,7 +866,7 @@ it_can_check_with_tag_filter_over_all_branches_with_cursor() {
765
866
local ref13=$( make_annotated_tag $repo " 3.0-production" " tag 6" )
766
867
local ref14=$( make_commit_to_branch $repo branch-a)
767
868
768
- check_uri_with_tag_filter_from $repo " *-staging" " 2.0-staging" | jq -e "
869
+ check_uri_with_tag_filter_from $repo " *-staging" " 2.0-staging" 2 | jq -e "
769
870
. == [{ref: \" 2.0-staging\" , commit: \" $ref6 \" }, {ref: \" 3.0-staging\" , commit: \" $ref10 \" }]
770
871
"
771
872
}
@@ -787,7 +888,7 @@ it_can_check_with_tag_regex_over_all_branches_with_cursor() {
787
888
local ref13=$( make_annotated_tag $repo " 3.0-production" " tag 6" )
788
889
local ref14=$( make_commit_to_branch $repo branch-a)
789
890
790
- check_uri_with_tag_regex_from $repo " .*-staging" " 2.0-staging" | jq -e "
891
+ check_uri_with_tag_regex_from $repo " .*-staging" " 2.0-staging" 2 | jq -e "
791
892
. == [{ref: \" 2.0-staging\" , commit: \" $ref6 \" }, {ref: \" 3.0-staging\" , commit: \" $ref10 \" }]
792
893
"
793
894
}
@@ -1014,6 +1115,7 @@ it_checks_uri_with_tag_filter_and_version_depth() {
1014
1115
]"
1015
1116
}
1016
1117
1118
+ run check_jq_functionality
1017
1119
run it_can_check_from_head
1018
1120
run it_can_check_from_a_ref
1019
1121
run it_can_check_from_a_first_commit_in_repo
@@ -1054,6 +1156,8 @@ run it_can_check_with_tag_filter_with_bogus_ref
1054
1156
run it_can_check_with_tag_regex_with_bogus_ref
1055
1157
run it_can_check_with_tag_filter_with_replaced_tags
1056
1158
run it_can_check_with_tag_regex_with_replaced_tags
1159
+ run it_can_check_with_tag_and_path_match_filter
1160
+ run it_can_check_with_tag_and_path_match_ancestors_filter
1057
1161
run it_can_check_from_head_only_fetching_single_branch
1058
1162
run it_can_check_and_set_git_config
1059
1163
run it_can_check_from_a_ref_and_only_show_merge_commit
0 commit comments