Browse Source

Add logic to find paths for user-specified tests

This also makes the any configs specified with the --config flag be used
instead of the default config. If uses still want to include the default
config, they need to specify it themselves.
Mike Dillon 10 years ago
parent
commit
8a81410013
1 changed files with 39 additions and 7 deletions
  1. 39 7
      test/run.sh

+ 39 - 7
test/run.sh

@@ -23,7 +23,7 @@ opts="$(getopt -o 'ht:c:?' --long 'dry-run,help,test:,config:' -- "$@" || { usag
 eval set -- "$opts"
 
 declare -A argTests=()
-declare -a additionalConfigs=()
+declare -a configs=()
 dryRun=
 while true; do
 	flag=$1
@@ -32,7 +32,7 @@ while true; do
 		--dry-run) dryRun=1 ;;
 		--help|-h|'-?') usage && exit 0 ;;
 		--test|-t) argTests["$1"]=1 && shift ;;
-		--config|-c) additionalConfigs+=("$(readlink -f "$1")") && shift ;;
+		--config|-c) configs+=("$(readlink -f "$1")") && shift ;;
 		--) break ;;
 		*)
 			{
@@ -55,12 +55,44 @@ declare -A testAlias=()
 declare -A imageTests=()
 declare -A globalExcludeTests=()
 
-# load the default config
-. "$dir/config.sh"
+# if there are no user-specified configs, use the default config
+if [ ${#configs} -eq 0 ]; then
+	configs+=("$dir/config.sh")
+fi
 
-# load additional user-specified configs
-for conf in "${additionalConfigs[@]}"; do
+# load the configs
+declare -A testPaths=()
+for conf in "${configs[@]}"; do
 	. "$conf"
+
+	# Determine the full path to any newly-declared tests
+	confDir="$(dirname "$conf")"
+
+	for testName in ${globalTests[@]}; do
+		[ "${testPaths[$testName]}" ] && continue
+
+		if [ -d "$confDir/tests/$testName" ]; then
+			# Test directory found relative to the conf file
+			testPaths[$testName]="$confDir/tests/$testName"
+		elif [ -d "$dir/tests/$testName" ]; then
+			# Test directory found in the main tests/ directory
+			testPaths[$testName]="$dir/tests/$testName"
+		fi
+	done
+
+	for image in ${!imageTests[@]}; do
+		for testName in ${imageTests[$image]}; do
+			[ "${testPaths[$testName]}" ] && continue
+
+			if [ -d "$confDir/tests/$testName" ]; then
+				# Test directory found relative to the conf file
+				testPaths[$testName]="$confDir/tests/$testName"
+			elif [ -d "$dir/tests/$testName" ]; then
+				# Test directory found in the main tests/ directory
+				testPaths[$testName]="$dir/tests/$testName"
+			fi
+		done
+	done
 done
 
 didFail=
@@ -110,7 +142,7 @@ for dockerImage in "$@"; do
 		
 		# run test against dockerImage here
 		# find the script for the test
-		scriptDir="$dir/tests/$t"
+		scriptDir="${testPaths[$t]}"
 		if [ -d "$scriptDir" ]; then
 			script="$scriptDir/run.sh"
 			if [ -x "$script" -a ! -d "$script" ]; then