Add warnings and options to Run.ps1 59/7659/1
authorVictor Morales <victor.morales@intel.com>
Tue, 15 Aug 2017 21:24:05 +0000 (16:24 -0500)
committerVictor Morales <victor.morales@intel.com>
Tue, 15 Aug 2017 21:26:12 +0000 (16:26 -0500)
This change add the same options and messages that was included
in 8a0c9450a19892d4254e2b69d04f3b84007b700b

Change-Id: I612dc3c3f679797c271ee3f452454e833c2b2aba
Issue-Id: INT-97
Signed-off-by: Victor Morales <victor.morales@intel.com>
bootstrap/vagrant-onap/CONTRIBUTING.md
bootstrap/vagrant-onap/tools/Run.ps1
bootstrap/vagrant-onap/tools/run.sh

index 3e42510..f11327f 100644 (file)
@@ -12,15 +12,15 @@ Unit Testing
 
 The **_tests_** folder contains ~~scripts~~ _test suites_ that ensure the proper
 implementation of the _functions_ created on **_lib_** folder.  In order to
-execute the Unit Tests defined for this project, you must run the following
-command:
+display the Usage information you must execute the script with question mark as
+an argument like follows:
 
-    $ ./tools/run.sh -s [test_suite] -c [function] testing
+    $ ./tools/run.sh -?
 
 or using PowerShell
 
     PS C:\> Set-ExecutionPolicy Bypass -Scope CurrentUser
-    PS C:\> .\tools\Run.ps1 testing [test_suite] [function]
+    PS C:\> .\tools\Run.ps1 testing -?
 
 Examples
 --------
index 5469abf..4d70140 100644 (file)
@@ -1,19 +1,93 @@
-switch ($args[0])
+<#
+.SYNOPSIS
+This script helps to configure its environment variables based on the component selected.
+
+.EXAMPLE
+.\tools\Run.ps1 testing -s functions -c install_maven -y
+
+.EXAMPLE
+.\tools\Run.ps1 all_in_one
+
+.EXAMPLE
+.\tools\Run.ps1 aai
+
+.PARAMETER s
+Test suite to use in testing mode.
+
+.PARAMETER c
+Test case to use in testing mode.
+
+.PARAMETER y
+Skips warning prompt.
+
+.LINK
+https://wiki.onap.org/display/DW/ONAP+on+Vagrant
+#>
+
+Param(
+    [ValidateSet("all_in_one","dns", "mr", "sdc", "aai", "mso", "robot", "vid", "sdnc", "portal", "dcae", "policy", "appc", "testing")]
+    [Parameter(Mandatory=$True,Position=0)]
+    [ValidateNotNullOrEmpty()]
+    [String]
+    $Command
+,
+    [Parameter(Mandatory=$False,HelpMessage="Test suite to use in testing mode.")]
+    [Alias("suite")]
+    [String]
+    $s = "*"
+,
+    [Parameter(Mandatory=$False,HelpMessage="Test case to sue in testing mode.")]
+    [Alias("case")]
+    [String]
+    $c = "*"
+,
+    [Parameter(Mandatory=$False,HelpMessage="Skips warning prompt.")]
+    [AllowNull()]
+    [Switch]
+    $y = $false
+)
+
+if ( -Not "testing".Equals($Command) )
+    {
+        if($PsBoundParameters.ContainsKey('s'))
+            {
+                Write-Host "Test suite should only be specified in testing mode."
+                Write-Host ".\tools\Run.ps1 -?"
+                exit 1
+            }
+        if($PsBoundParameters.ContainsKey('c'))
+            {
+                Write-Host "Test case should only be specified in testing mode."
+                Write-Host ".\tools\Run.ps1 -?"
+                exit 1
+            }
+    }
+
+switch ($Command)
     {
         "all_in_one" { $env:DEPLOY_MODE="all-in-one" }
         { @("dns", "mr", "sdc", "aai", "mso", "robot", "vid", "sdnc", "portal", "dcae", "policy", "appc") -contains $_ } { $env:DEPLOY_MODE="individual" }
         "testing"
             {
                 $env:DEPLOY_MODE="testing"
-                $test_suite="*"
-                if (!$args[1]) { $test_suite=$args[1] }
-                $env:TEST_SUITE=$test_suite
-                $test_case="*"
-                if (!$args[2]) { $test_case=$args[2] }
-                $env:TEST_CASE=$test_case
-
-                Remove-Item ./opt/ -Recurse -Force
-                Remove-Item $HOME/.m2/ -Recurse -Force
+                If(-Not $y)
+                    {
+                        Write-Host "Warning: This test script will delete the contents of ../opt/ and ~/.m2."
+                        $yn = Read-Host "Would you like to continue? [y]es/[n]o: "
+                        switch ($yn)
+                            {
+                                { @("n", "N") -contains $_ }
+                                    {
+                                        Write-Host "Exiting."
+                                        exit 0
+                                    }
+                            }
+                    }
+                $env:TEST_SUITE=$s
+                $env:TEST_CASE=$c
+
+                &cmd.exe /c rd /s /q .\opt\
+                &cmd.exe /c rd /s /q $HOME\.m2\
              }
          default
              {
@@ -22,5 +96,5 @@ switch ($args[0])
              }
     }
 
-vagrant destroy -f $args[0]
-vagrant up $args[0]
+vagrant destroy -f $Command
+vagrant up $Command
index aeb9d8c..6ba4a10 100755 (executable)
@@ -3,11 +3,11 @@
 usage ()
 {
 cat <<EOF
-Usage: run.sh [-y] [-h] Command
+Usage: run.sh [-y] [-?] Command
 Optional arguments:
     -y
         Skips warning prompt.
-    -h
+    -?
         Shows help about this program.
     -s <suite>
         Test suite to use in testing mode.
@@ -26,32 +26,32 @@ test_case="*"
 
 COMMAND=${@: -1}
 
-while getopts "yhs:c:" OPTION; do
-  case "$OPTION" in
+while getopts "y?s:c:" OPTION; do
+    case "$OPTION" in
     y)
-      run=true
-      ;;
+        run=true
+        ;;
     s)
-      if [ "$COMMAND" != "testing" ] ; then
-        echo "Test suite should only be specified in testing mode."
-        echo "./run.sh -h for usage."
-        exit 0
-      fi
-      test_suite=$OPTARG
-      ;;
+        if [ "$COMMAND" != "testing" ] ; then
+            echo "Test suite should only be specified in testing mode."
+            echo "./tools/run.sh -? for usage."
+            exit 1
+        fi
+        test_suite=$OPTARG
+        ;;
     c)
-      if [ "$COMMAND" != "testing" ] ; then
-        echo "Test case should only be specified in testing mode."
-        echo "./run.sh -h for usage."
+        if [ "$COMMAND" != "testing" ] ; then
+            echo "Test case should only be specified in testing mode."
+            echo "./tools/run.sh -? for usage."
+            exit 1
+        fi
+        test_case=$OPTARG
+        ;;
+    ?)
+        usage
         exit 0
-      fi
-      test_case=$OPTARG
-      ;;
-    h)
-      usage
-      exit 0
-      ;;
-  esac
+        ;;
+    esac
 done
 
 case $COMMAND in
@@ -64,19 +64,19 @@ case $COMMAND in
     "testing" )
         export DEPLOY_MODE='testing'
         if  [ "$run" == false ] ; then
-          while true ; do
-            echo "Warning: This test script will delete the contents of ../opt/ and ~/.m2."
-            read -p "Would you like to continue? [y]es/[n]o: " yn
-            case $yn in
-              [Yy]*)
-                break
-                ;;
-              [Nn]*)
-                echo "Exiting."
-                exit 0
-                ;;
-            esac
-          done
+            while true ; do
+                echo "Warning: This test script will delete the contents of ../opt/ and ~/.m2."
+                read -p "Would you like to continue? [y]es/[n]o: " yn
+                case $yn in
+                    [Yy]*)
+                        break
+                        ;;
+                    [Nn]*)
+                        echo "Exiting."
+                        exit 0
+                        ;;
+                esac
+            done
         fi
 
         export TEST_SUITE=$test_suite