A unit test for validating repository tags.

lf/include.mk
-------------
  o Handle a bootstrap case for git submodule checkout.
  o Invoke git command using macro $(GIT) else not found by path.
  o git submodule update --init --recursive will checkout repo:onf-make

test/bats/check_repo_tags.bats
------------------------------
  o A BATS unit test to validate contents of gerrit and github repository tags.
  o Replace inlined hardcoded list of repository names.
  o Instead read them from data file conf/repos/voltha.
  o Added conditional booleans enable_fatal= and enable_skip=1
    for easy removal of test filtering while using interactively.

test/bats/conf/repos/deprecated
-------------------------------
  o Move a few repositories into a new deprecated list so their usage is clear.

[HOWTO: test]
  % git clone ssh://gerrit.opencord.org/ci-management
  % make -C ci-management/tests/bat test-bats

check_repo_tags.bats
3 tests, 0 failures

Change-Id: I5fc8e37b36f02f77d5b54594a7092a9456562939
Signed-off-by: Joey Armstrong <jarmstrong@linuxfoundation.org>
diff --git a/test/bats/README.md b/test/bats/README.md
new file mode 100644
index 0000000..56b47e1
--- /dev/null
+++ b/test/bats/README.md
@@ -0,0 +1,30 @@
+BATS unit testing
+=================
+
+check_repo_tags.bats
+--------------------
+
+- SRC: [jjb/pipeline/voltha/software-upgrades.groovy](https://gerrit.opencord.org/plugins/gitiles/ci-management/+/refs/heads/master/jjb/pipeline/voltha/software-upgrades.groovy#80)
+- TST: [test/bats/check_repo_tags.bats](https://gerrit.opencord.org/plugins/gitiles/ci-management/+/refs/heads/master/test/bats/check_repo_tags.bats)
+- LIB: [test/bats/utils/check_repo_tags.sh](https://gerrit.opencord.org/plugins/gitiles/ci-management/+/refs/heads/master/test/bats/utils/check_repo_tags.sh#31)
+
+Unit test check_repo_tags.bats will exercise (git ls-remote) logic inlined within the software-upgrades.groovy script.  The test will gather a list of tagnames from the gerrit and github repositories then compare the lists for differences.
+
+
+Interactive Testing
+-------------------
+
+check_repo_tags.bats contains two variables that can be uncommented to enable debugging.
+
+- Uncomment to allow tagname differences to induce testing failures.
+
+    - declare -g -i enable_fatal=1
+
+- Test exclusions (skip) are supported but behavior is heavy handed.
+  Skip will cause a test suite to prematurely exit on first failure
+  VS iterate over all test conditions then ignore overall status.
+
+    - declare -g -i enable_skip=1
+    - For initial triage this test has been setup to call continue
+      rather than skip.  Ignore individual test conditions that are
+      a known failure point.
diff --git a/test/bats/check_repo_tags.bats b/test/bats/check_repo_tags.bats
index d36ead1..64dd88a 100755
--- a/test/bats/check_repo_tags.bats
+++ b/test/bats/check_repo_tags.bats
@@ -28,13 +28,15 @@
 setup() {
     source './utils/check_repo_tags.sh'
 
-    declare -g components=()
-    components+=('voltha-docs')
-    components+=('voltha-onos')
-    components+=('voltha-openolt-adapter')
-    components+=('voltha-openonu-adapter-go')
-    components+=('voltha-lib-go')
-    components+=('voltha-protos')
+    ## Slurp a list of repositories to query
+    readarray -t buffer < 'conf/repos/voltha'
+    declare -g -a components=("${buffer[0]}")
+
+    # Uncomment for raw test results
+    # declare -g -i enable_fatal=1
+
+    # Uncomment to skip remaining checks within a test.
+    # declare -g -i enable_skip=1
 }
 
 ## -----------------------------------------------------------------------
@@ -49,29 +51,47 @@
         ## Known problems
         ## --------------
         case "$component" in
+            device-management-interface)
+                if [[ -v enable_skip ]]; then
+                    skip 'declare -a gerrit=([0]="1.15.0")'
+                fi
+                [[ ! -v enable_fatal ]] && { continue; }
+                ;;
             voltha-docs)
-                # skip 'declare -a gerrit=([0]="2.12.35")'
-                continue
+                if [[ -v enable_skip ]]; then
+                    skip 'declare -a gerrit=([0]="2.12.35")'
+                fi
+                [[ ! -v enable_fatal ]] && { continue; }
                 ;;
             voltha-lib-go)
-                # skip 'declare -a gerrit=([0]="7.5.3")'
-                continue
+                if [[ -v enable_skip ]]; then
+                    skip 'declare -a gerrit=([0]="7.5.3")'
+                fi
+                [[ ! -v enable_fatal ]] && { continue; }
                 ;;
             voltha-onos)
-                # skip 'declare -a gerrit=([0]="2.11.0")'
-                continue
+                if [[ -v enable_skip ]]; then
+                    skip 'declare -a gerrit=([0]="2.11.0")'
+                fi
+                [[ ! -v enable_fatal ]] && { continue; }
                 ;;
-            voltha-openolt-adapter)
-                # skip 'declare -a gerrit=([0]="4.4.10")'
-                continue
+            voltha-openolt-adapter) 
+                if [[ -v enable_skip ]]; then
+                    skip 'declare -a gerrit=([0]="4.4.10")'
+                fi
+                [[ ! -v enable_fatal ]] && { continue; }
                 ;;
             voltha-openonu-adapter-go)
-                # skip 'declare -a gerrit=([0]="2.12.0~beta")'
-                continue
+                if [[ -v enable_skip ]]; then
+                    skip 'declare -a gerrit=([0]="2.12.0~beta")'
+                fi
+                [[ ! -v enable_fatal ]] && { continue; }
                 ;;
             voltha-protos)
-                # skip 'declare -a gerrit=([0]="5.4.11")'
-                continue
+                if [[ -v enable_skip ]]; then
+                    skip 'declare -a gerrit=([0]="5.4.11")'
+                fi
+                [[ ! -v enable_fatal ]] && { continue; }
                 ;;
         esac
 
@@ -108,29 +128,35 @@
         ## Known problems
         ## --------------
         case "$component" in
-            voltha-docs)
-                # skip "$component not mirrored on github"
-                continue
+            device-management-interface)
+                if [[ -v enable_skip ]]; then
+                    skip 'declare -a gerrit=([0]="1.16.0")'
+                fi
+                [[ ! -v enable_fatal ]] && { continue; }
                 ;;
             voltha-onos)
-                # skip "declare -a gerrit=([0]="2.12.0~beta")"
-                continue
+                if [[ -v enable_skip ]]; then
+                    skip "declare -a gerrit=([0]="2.12.0~beta")"
+                fi
+                [[ ! -v enable_fatal ]] && { continue; }
                 ;;
             voltha-lib-go)
-                # skip "declare -a gerrit=([0]="7.6.0")"
-                continue
+                if [[ -v enable_skip ]]; then
+                    skip "declare -a gerrit=([0]="7.6.0")"
+                fi
+                [[ ! -v enable_fatal ]] && { continue; }
                 ;;
             voltha-openolt-adapter)
-                # skip "declare -a gerrit=([0]="4.4.11")"
-                continue
-                ;;
-            voltha-openonu-adapter-go)
-                # skip 'github repo lacks tag 2.12.0 (voltha-openonu-adapter-go)'
-                continue
+                if [[ -v enable_skip ]]; then
+                    skip "declare -a gerrit=([0]="4.4.11")"
+                fi
+                [[ ! -v enable_fatal ]] && { continue; }
                 ;;
             voltha-protos)
-                # skip "declare -a gerrit=([0]="5.5.0")"
-                continue
+                if [[ -v enable_skip ]]; then
+                    skip 'declare -a gerrit=([0]="5.5.0")'
+                fi
+                [[ ! -v enable_fatal ]] && { continue; }
                 ;;
         esac
 
diff --git a/test/bats/conf/repos/README.md b/test/bats/conf/repos/README.md
new file mode 100644
index 0000000..d28f5d9
--- /dev/null
+++ b/test/bats/conf/repos/README.md
@@ -0,0 +1,11 @@
+Repository components
+=====================
+
+These data files contain a list of repository names for scripting.
+
+TODO
+----
+  o Consider creating a common test data repository for content.
+  o Consider creating a library function able to gather repository names.
+    - On github traversal of orgs by name may work but is performance an issue ?
+
diff --git a/test/bats/conf/repos/deprecated b/test/bats/conf/repos/deprecated
new file mode 100644
index 0000000..0dc1a06
--- /dev/null
+++ b/test/bats/conf/repos/deprecated
@@ -0,0 +1,6 @@
+voltha-ponsimonu-adapter
+voltha-ponsimolt-adapter
+voltha-omci
+voltha-api-server
+voltha-adtran-adapter
+voltha-openonu-adapter
diff --git a/test/bats/conf/repos/onos b/test/bats/conf/repos/onos
new file mode 100644
index 0000000..f58ac60
--- /dev/null
+++ b/test/bats/conf/repos/onos
@@ -0,0 +1,14 @@
+aaa
+bng
+dhcpl2relay
+igmpproxy
+kafka
+kafka-onos
+maclearner
+mcast
+ofagent-go
+olt
+olttopology
+ppoeagent
+sadis
+segmentrouting
diff --git a/test/bats/conf/repos/voltha b/test/bats/conf/repos/voltha
new file mode 100644
index 0000000..55579be
--- /dev/null
+++ b/test/bats/conf/repos/voltha
@@ -0,0 +1,22 @@
+device-management-interface
+ofagent-go
+omci-lib-go
+openolt
+voltha-eponolt-adapter
+voltha-test-manifest
+voltha-docs
+voltha-docker-tools
+voltha-epononu-adapter
+voltha-go-controller
+voltha-protos
+voltha-go
+voltha-helm-charts
+voltha-system-tests
+voltha-onos
+voltha-openonu-adapter-go
+voltha-lib-go
+voltha-go-controller
+voltha-northbound-bbf-adapter
+bbsim
+bbsim-sadis-server
+voltctl