#!/bin/bash #------------------------------------------------------------------------------ set -u # Usage: # cd /path/to/p4bbi/dev/test # ./unit_test_bbi_paths.sh 2>&1 | tee unit_test_bbi_paths.log LIB=../lib/bbi_paths.sh source $LIB || { echo -e "\nError: Failed to load $LIB. Aborting test.\n"; exit 1; } declare -i i=0 declare -i PassCount=0 declare -i FailCount=0 declare -i TestCount=0 declare -a InputSet1 # For testing get_stream_subdir() declare -a ResultSet1 declare -a InputSet2 # For testing get_stream() declare -a ResultSet2 declare Version=1.0.3 declare LibVersion=$(grep ^Version= $LIB|cut -d '=' -f 2) declare VERBOSITY=0 #------------------------------------------------------------------------------ # Static Test Data #------------------------------------------------------------------------------ # Function: get_stream_subdir ($path) # # Stream Depth 1 (default depth) examples: # Given: Expected Result: # //stream/main/... "" (empty) # //stream/main/ACE/... ACE # //stream/main/ACE/d1/d2/... ACE/d1/d2 # Stream Depth n>1 examples: # Depth Path Expected Result: # 2 //stream/main/... "" (empty; invalid input ignored). # 2 //components/radio/main/... "" (empty) # 2 //components/radio/main/ACE/... ACE # 2 //components/radio/main/ACE/d1/... ACE/d1 # 2 //components/radio/main/ACE/d1/d2/... ACE/d1/d2 # 3 //components/myco/radio/main/ACE/... ACE # 3 //components/myco/radio/main/ACE/d1/... ACE/d1 # 3 //components/myco/radio/main/ACE/d1/d2/... ACE/d1/d2 # Stream Depth 1 (default depth) test cases: i=0 InputSet1[$i]=//stream/main/... DepthSet1[$i]=1 ResultSet1[$i]= i=$((i+1)) InputSet1[$i]=//stream/main/ACE/... DepthSet1[$i]=1 ResultSet1[$i]=ACE i=$((i+1)) InputSet1[$i]=//stream/main/ACE/d1/d2/... DepthSet1[$i]=1 ResultSet1[$i]=ACE/d1/d2 i=$((i+1)) # Stream Depth n>1 test cases: InputSet1[$i]=//stream/main/... DepthSet1[$i]=2 ResultSet1[$i]= i=$((i+1)) InputSet1[$i]=//components/radio/main/... DepthSet1[$i]=2 ResultSet1[$i]= i=$((i+1)) InputSet1[$i]=//components/radio/main/ACE/... DepthSet1[$i]=2 ResultSet1[$i]=ACE i=$((i+1)) InputSet1[$i]=//components/radio/main/ACE/d1/... DepthSet1[$i]=2 ResultSet1[$i]=ACE/d1 i=$((i+1)) InputSet1[$i]=//components/radio/main/ACE/d1/d2/... DepthSet1[$i]=2 ResultSet1[$i]=ACE/d1/d2 i=$((i+1)) InputSet1[$i]=//components/myco/radio/main/ACE/... DepthSet1[$i]=3 ResultSet1[$i]=ACE i=$((i+1)) InputSet1[$i]=//components/myco/radio/main/ACE/d1/... DepthSet1[$i]=3 ResultSet1[$i]=ACE/d1 i=$((i+1)) InputSet1[$i]=//components/myco/radio/main/ACE/d1/d2/... DepthSet1[$i]=3 ResultSet1[$i]=ACE/d1/d2 i=$((i+1)) #------------------------------------------------------------------------------ # Function: get_stream ($path) # # Stream Depth 1 (default depth) examples: # Given: Expected Result: # //stream/main/... //stream/main # //stream/main/ACE/... //stream/main # //stream/main/ACE/d1/d2/... //stream/main # //stream/main //stream/main # # Stream Depth n>1 examples: # Depth Path Expected Result: # 2 //stream/main/... //stream/main # 2 //components/radio/main/... //components/radio/main # 2 //components/radio/main/ACE/... //components/radio/main # 2 //components/radio/main/ACE/d1/... //components/radio/main # 2 //components/radio/main/ACE/d1/d2/... //components/radio/main # 3 //components/myco/radio/main/... //components/myco/radio/main # 3 //components/myco/radio/main/ACE/... //components/myco/radio/main # 3 //components/myco/radio/main/ACE/d1/... //components/myco/radio/main # 3 //components/myco/radio/main/ACE/d1/d2/... //components/myco/radio/main # Stream Depth 1 (default depth) test cases: i=0 InputSet2[$i]=//stream/main/... DepthSet2[$i]=1 ResultSet2[$i]=//stream/main i=$((i+1)) InputSet2[$i]=//stream/main/ACE/... DepthSet2[$i]=1 ResultSet2[$i]=//stream/main i=$((i+1)) InputSet2[$i]=//stream/main/d1/d2/... DepthSet2[$i]=1 ResultSet2[$i]=//stream/main i=$((i+1)) InputSet2[$i]=//stream/main DepthSet2[$i]=1 ResultSet2[$i]=//stream/main i=$((i+1)) # Stream Depth n>1 test cases: InputSet2[$i]=//stream/main/... DepthSet2[$i]=2 ResultSet2[$i]=//stream/main i=$((i+1)) InputSet2[$i]=//components/radio/main/... DepthSet2[$i]=2 ResultSet2[$i]=//components/radio/main i=$((i+1)) InputSet2[$i]=//components/radio/main/ACE/... DepthSet2[$i]=2 ResultSet2[$i]=//components/radio/main i=$((i+1)) InputSet2[$i]=//components/radio/main/ACE/d1/... DepthSet2[$i]=2 ResultSet2[$i]=//components/radio/main i=$((i+1)) InputSet2[$i]=//components/radio/main/ACE/d2/... DepthSet2[$i]=2 ResultSet2[$i]=//components/radio/main i=$((i+1)) InputSet2[$i]=//components/myco/radio/main/... DepthSet2[$i]=3 ResultSet2[$i]=//components/myco/radio/main i=$((i+1)) InputSet2[$i]=//components/myco/radio/main/ACE/... DepthSet2[$i]=3 ResultSet2[$i]=//components/myco/radio/main i=$((i+1)) InputSet2[$i]=//components/myco/radio/main/ACE/d1/... DepthSet2[$i]=3 ResultSet2[$i]=//components/myco/radio/main i=$((i+1)) InputSet2[$i]=//components/myco/radio/main/ACE/d1/d2/... DepthSet2[$i]=3 ResultSet2[$i]=//components/myco/radio/main i=$((i+1)) echo -e "Started ${0##*/} v$Version at $(date).\nTesting $LIB v$LibVersion\n" echo -e "==============================================================================\n" echo -e "Test Set 1: Testing get_stream_subdir()\n" i=0; while [[ $i -lt ${#InputSet1[*]} ]]; do input=${InputSet1[$i]} depth=${DepthSet1[$i]} actual=$(get_stream_subdir "$input" "$depth") expected=${ResultSet1[$i]} echo -n -e "Test $((i+1)):\nInput:\t\t$input (depth $depth)\nOutput:\t\t$actual\nExpected:\t$expected\nResult:\t\t" if [[ "$actual" == "$expected" ]]; then echo -e "PASS\n" PassCount=$((PassCount+1)) else echo -e "FAIL\n" FailCount=$((FailCount+1)) fi i=$((i+1)) TestCount=$((TestCount+1)) done echo -e "==============================================================================\n" echo -e "Test Set 2: Testing get_stream()\n" i=0; while [[ $i -lt ${#InputSet2[*]} ]]; do input=${InputSet2[$i]} depth=${DepthSet2[$i]} actual=$(get_stream "$input" "$depth") expected=${ResultSet2[$i]} echo -n -e "Test $((i+1)):\nInput:\t\t$input (depth $depth)\nOutput:\t\t$actual\nExpected:\t$expected\nResult:\t\t" if [[ "$actual" == "$expected" ]]; then echo -e "PASS\n" PassCount=$((PassCount+1)) else echo -e "FAIL\n" FailCount=$((FailCount+1)) fi i=$((i+1)) TestCount=$((TestCount+1)) done echo -e "==============================================================================\n" echo -e "Summary:\n$TestCount tests executed, $PassCount passed, $FailCount failed.\n"
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 30968 | C. Thomas Tyler |
Migration from Classic to Streams with: p4 copy -b P4BBI_Classic_to_Streams |
||
//guest/perforce_software/p4bbi/main/test/unit_test_bbi_paths.sh | |||||
#1 | 19072 | C. Thomas Tyler | Released P4BBI/MultiArch/2016.3/19070 (2016/04/21). | ||
//guest/perforce_software/p4bbi/dev/test/unit_test_bbi_paths.sh | |||||
#3 | 19070 | C. Thomas Tyler |
Fixed UPDATE action for stream when StreamDepth>1. Made get_stream_subdir() and get_stream in bbi_paths.sh accept a depth parameters, and modified calls in bbi_acitons.sh to determine a value for the depth paramters and pass it in. Added unit test cases for StreamDepth>1. Added full integration test case to the test suite. |
||
#2 | 19069 | C. Thomas Tyler | Enhanced version capture for audit trail in unit test. | ||
#1 | 19068 | C. Thomas Tyler | Added unit test for testing bbi_paths.sh library. |