mac-address-set: add testify unit-test
adding a unit test script which uses testify framework to test the mac-address-set script for vuc1 and vcu2. BugzID: 77171 Signed-off-by: Patrick Zysset <patrick.zysset@netmodule.com>
This commit is contained in:
parent
2173bda09c
commit
2734a8b02f
|
|
@ -0,0 +1,48 @@
|
|||
# bash-assert
|
||||
|
||||
testify is a lightweight unit testing framework for bash
|
||||
|
||||
# Usage
|
||||
|
||||
clone this repository `git clone https://github.com/zombieleet/testify.git` here.
|
||||
|
||||
run the mac-address-set-test.sh file and check the console output.
|
||||
|
||||
# Commands
|
||||
|
||||
all subcommands to the assert functions requres 4 arguments, the first argument is the actual value to test for, while the second argument
|
||||
is the expected value, the thrid argument is a description of the test , while the fourth argument is a short description of what the test output should be
|
||||
|
||||
**expect** Compares two values
|
||||
|
||||
`assert expect "$(Name 'Jane' 'Doe')" "John Doe" "Test for Name Function" "should fail"`
|
||||
|
||||
To test the output of a function you have to use command substitution
|
||||
|
||||
You can also test single values
|
||||
|
||||
`assert expect "victory" "favour" "Test for Name comparison" "This should fail"`
|
||||
|
||||
testing for mathematical expressions
|
||||
|
||||
`assert expect "$((2+2))" "4" "Test for Simple Math Operation" "It should succeed"`
|
||||
|
||||
|
||||
**regex** Does a regular expression match. The second argument to this subcommand should be a regular expression
|
||||
|
||||
`assert regex "What is the difference between 6 and half a dozen" "[[:digit:]]" "Match Number Regular Expression" "It should succeed"`
|
||||
|
||||
|
||||
**status** Test for any status code. The second argument should be the expected status code. The first argument to this subcommand should be a command name, and it should not be passed as a command substitution but it should be passed as just a string wrapped in double quotes.
|
||||
The arguments to the function should also be in the double quotes. Arguments with spaced should be wrapped in single quotes
|
||||
|
||||
`assert status "ls ." "0" "List in current dir" "it should return 0"`
|
||||
|
||||
**done** This should be last subcommand to call, it does not require any argument
|
||||
|
||||
|
||||
# LICENSE
|
||||
|
||||
GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
source ../files/mac-address-set.sh testify
|
||||
source ./testify/testify.bash
|
||||
|
||||
assert expect "$(log_error 'test')" "$0: error: test" "Test for Error logging" "should succeed"
|
||||
assert expect "$(log_info 'test')" "$0: info: test" "Test for Info logging" "should succeed"
|
||||
|
||||
# Testing VCU1 mac address converter
|
||||
assert expect "$(vcu1_eth_to_wlan '7C:97:63:50:00:00')" "7C:97:63:70:00:00" "Test VCU1 WLAN 1" "should match"
|
||||
assert expect "$(vcu1_eth_to_wlan '7c:97:63:50:00:00')" "7C:97:63:70:00:00" "Test VCU1 WLAN 2" "should match"
|
||||
|
||||
assert expect "$(vcu1_eth_to_bt '7C:97:63:50:00:0A')" "7C:97:63:80:00:0A" "Test VCU1 BT 1" "should match"
|
||||
assert expect "$(vcu1_eth_to_bt '7c:97:63:50:00:0a')" "7C:97:63:80:00:0A" "Test VCU1 BT 2" "should match"
|
||||
|
||||
# Testing VCU2 mac address converter
|
||||
assert expect "$(vcu2_eth_to_wlan_and_bt 'wlan' '00:11:2b:aa:cd:00')" "00:11:2B:AA:CD:03" "Test VCU2 WLAN 1" "should match"
|
||||
assert expect "$(vcu2_eth_to_wlan_and_bt 'wlan' '00:11:2B:AA:CD:00')" "00:11:2B:AA:CD:03" "Test VCU2 WLAN 2" "should match"
|
||||
assert expect "$(vcu2_eth_to_wlan_and_bt 'wlan' '00:11:2b:00:00:39')" "00:11:2B:00:00:3C" "Test VCU2 WLAN 3" "should match"
|
||||
assert expect "$(vcu2_eth_to_wlan_and_bt 'wlan' '00:11:2b:00:00:f0')" "00:11:2B:00:00:F3" "Test VCU2 WLAN 4" "should match"
|
||||
assert expect "$(vcu2_eth_to_wlan_and_bt 'wlan' '00:11:2b:00:00:f6')" "00:11:2B:00:00:F9" "Test VCU2 WLAN 5" "should match"
|
||||
assert expect "$(vcu2_eth_to_wlan_and_bt 'wlan' '00:11:2b:00:00:f7')" "00:11:2B:00:00:FA" "Test VCU2 WLAN 6" "should match"
|
||||
#assert expect "$(vcu2_eth_to_wlan_and_bt 'wlan' '00:11:2b:00:00:RS')" "" "Test VCU2 WLAN 7" "should match"
|
||||
#assert expect "$(vcu2_eth_to_wlan_and_bt 'wlan' '00:11:2b:00:00:FF')" "" "Test VCU2 WLAN 8" "should match"
|
||||
assert expect "$(vcu2_eth_to_wlan_and_bt 'wlan' '00:11:2b:00:00:06')" "00:11:2B:00:00:09" "Test VCU2 WLAN 9" "should match"
|
||||
|
||||
assert expect "$(vcu2_eth_to_wlan_and_bt 'bt' '00:11:2b:aa:cd:00')" "00:11:2B:AA:CD:04" "Test VCU2 BT 1" "should match"
|
||||
assert expect "$(vcu2_eth_to_wlan_and_bt 'bt' '00:11:2B:AA:CD:00')" "00:11:2B:AA:CD:04" "Test VCU2 BT 2" "should match"
|
||||
assert expect "$(vcu2_eth_to_wlan_and_bt 'bt' '00:11:2b:00:00:39')" "00:11:2B:00:00:3D" "Test VCU2 BT 3" "should match"
|
||||
assert expect "$(vcu2_eth_to_wlan_and_bt 'bt' '00:11:2b:00:00:f0')" "00:11:2B:00:00:F4" "Test VCU2 BT 4" "should match"
|
||||
assert expect "$(vcu2_eth_to_wlan_and_bt 'bt' '00:11:2b:00:00:f6')" "00:11:2B:00:00:FA" "Test VCU2 BT 5" "should match"
|
||||
assert expect "$(vcu2_eth_to_wlan_and_bt 'bt' '00:11:2b:00:00:f7')" "00:11:2B:00:00:FB" "Test VCU2 BT 6" "should match"
|
||||
#assert expect "$(vcu2_eth_to_wlan_and_bt 'wlan' '00:11:2b:00:00:RS')" "" "Test VCU2 BT 7" "should match"
|
||||
#assert expect "$(vcu2_eth_to_wlan_and_bt 'wlan' '00:11:2b:00:00:FF')" "" "Test VCU2 BT 8" "should match"
|
||||
assert expect "$(vcu2_eth_to_wlan_and_bt 'bt' '00:11:2b:00:00:06')" "00:11:2B:00:00:0A" "Test VCU2 BT 9" "should match"
|
||||
|
||||
# Examples:
|
||||
#assert expect "$(Name 'Jane' 'Doe')" "John Doe" "Test for Name Function" "should fail"
|
||||
#assert expect "$(Name 'Jane' 'Doe')" "Jane Doe" "Test for Name Function" "should succeed"
|
||||
#assert status "Name" "5" "Test for status code" "should return 5"
|
||||
#assert status "Name 'Jane' 'Doe'" "0" "Test for Status Code" "should return 0"
|
||||
#assert status "Name 'Jane' " "3" "Test for Status Code" "should return 3"
|
||||
#assert status "Name 'Jane' 'Doe'" "12" "Test for Status Code" "it should fail"
|
||||
#assert regex "$(Name 'Jane' 'Doe')" "Jane" "Test for Regexp" "it should match"
|
||||
#assert regex "123victory" "\W" "Test for Regexp Non Word Character" "it should fail if match failes"
|
||||
#assert expect "$((2+2))" "4" "Test for Simple Math Operation" "It should succeed"
|
||||
#assert regex "What is the difference between 6 and half a dozen" "[[:digit:]]" "Match Number Regular Expression" "It should succeed"
|
||||
#assert status "ls ." "0" "List in current dir" "it should return 0"
|
||||
|
||||
assert done
|
||||
|
||||
Loading…
Reference in New Issue