1tdc - Adding test cases for tdc 2 3Author: Lucas Bates - lucasb@mojatatu.com 4 5ADDING TEST CASES 6----------------- 7 8User-defined tests should be added by defining a separate JSON file. This 9will help prevent conflicts when updating the repository. Refer to 10template.json for the required JSON format for test cases. 11 12Include the 'id' field, but do not assign a value. Running tdc with the -i 13option will generate a unique ID for that test case. 14 15tdc will recursively search the 'tc' subdirectory for .json files. Any 16test case files you create in these directories will automatically be included. 17If you wish to store your custom test cases elsewhere, be sure to run tdc 18with the -f argument and the path to your file. 19 20Be aware of required escape characters in the JSON data - particularly when 21defining the match pattern. Refer to the tctests.json file for examples when 22in doubt. 23 24 25TEST CASE STRUCTURE 26------------------- 27 28Each test case has required data: 29 30id: A unique alphanumeric value to identify a particular test case 31name: Descriptive name that explains the command under test 32category: A list of single-word descriptions covering what the command 33 under test is testing. Example: filter, actions, u32, gact, etc. 34setup: The list of commands required to ensure the command under test 35 succeeds. For example: if testing a filter, the command to create 36 the qdisc would appear here. 37 This list can be empty. 38 Each command can be a string to be executed, or a list consisting 39 of a string which is a command to be executed, followed by 1 or 40 more acceptable exit codes for this command. 41 If only a string is given for the command, then an exit code of 0 42 will be expected. 43cmdUnderTest: The tc command being tested itself. 44expExitCode: The code returned by the command under test upon its termination. 45 tdc will compare this value against the actual returned value. 46verifyCmd: The tc command to be run to verify successful execution. 47 For example: if the command under test creates a gact action, 48 verifyCmd should be "$TC actions show action gact" 49matchPattern: A regular expression to be applied against the output of the 50 verifyCmd to prove the command under test succeeded. This pattern 51 should be as specific as possible so that a false positive is not 52 matched. 53matchCount: How many times the regex in matchPattern should match. A value 54 of 0 is acceptable. 55teardown: The list of commands to clean up after the test is completed. 56 The environment should be returned to the same state as when 57 this test was started: qdiscs deleted, actions flushed, etc. 58 This list can be empty. 59 Each command can be a string to be executed, or a list consisting 60 of a string which is a command to be executed, followed by 1 or 61 more acceptable exit codes for this command. 62 If only a string is given for the command, then an exit code of 0 63 will be expected. 64 65 66SETUP/TEARDOWN ERRORS 67--------------------- 68 69If an error is detected during the setup/teardown process, execution of the 70tests will immediately stop with an error message and the namespace in which 71the tests are run will be destroyed. This is to prevent inaccurate results 72in the test cases. 73 74Repeated failures of the setup/teardown may indicate a problem with the test 75case, or possibly even a bug in one of the commands that are not being tested. 76 77It's possible to include acceptable exit codes with the setup/teardown command 78so that it doesn't halt the script for an error that doesn't matter. Turn the 79individual command into a list, with the command being first, followed by all 80acceptable exit codes for the command. 81 82