The commands that are endorsed in Drizzletest are delineated in the following documentation. Examples are given for the commands. Browse tests/t for more examples.
Note
The commands are not case sensitive. All commands must end with semi-colon.
Syntax: |
---|
append_file file_name [terminator]
append_file command is used to append / add data to the end of an existing file. It is similar to write_file. In case, the specified file does not exist, it is created and the data is written on it. The end of data, that is to be appended, is marked by the terminator.
Note
The default terminator is EOF
The file_name can be substituted via variables.
Example: |
---|
let $MY_FILE = ~/foo/bar.txt;
append_file $MY_FILE;
writing text...
EOF
append_file $MY_FILE;
appending text with default terminator...
EOF
append_file $MY_FILE stop
appending text with `stop` terminator...
stop
Output: |
---|
~/foo/bar.txt:
writing text...
appending text with default terminator...
appending text with `stop` terminator...
Syntax: |
---|
cat_file file_name
cat_file is similar to the unix cat command. cat_file expects only one argument. The cat_file command reads the file given as its argument and writes its contents to the test_name.result file.
Note
If extra argument is passed to cat_file command, the following error is displayed. testname: At line N: Extra argument ‘/path/to/file/file_name’ passed to ‘cat_file’
Example: |
---|
/foo/log.txt:
The test produced the following results:
/tests/t/test_name.test:
let $LOG_RESULT = /foo;
cat_file $LOG_RESULT/log.txt
SELECT 1;
Output: |
---|
/tests/r/test_name.result:
The test produced the following results:
SELECT 1;
1
1
Note
The file_name can be specified via variables. In the example above, we have used LOG_RESULT as variable. We can also specify it as “let $LOG_RESULT = /foo/log.txt” and use it as “cat_file $LOG_RESULT”.
Syntax: |
---|
connect (name, host_name, user_name, password, db_name [,port_num [,socket [,options [,default_auth]]]])
Example: |
---|
Syntax: |
---|
let $var_name = value
let $var_name = query_get_value(query, col_name, row_num)
Example: |
---|
Syntax: |
---|
while(expr)
while() defines an action block which gets executed over a loop. The while command expects a value / variable (expr) which decides whether or not the next iteration has to be carried out. If the value is 0, it is considered as false and the loop terminates. The body of the while block, which contains the set of statements to be executed repeatedly, should be enclosed within curly braces { and }.
Note
Any non-zero value, positive / negative is treated as a true, and the loop gets executed. The expression expr does not support boolean expressions.
Example: |
---|
/tests/t/testname.test:
let $test=3;
let $iteration=1;
while($test)
{
echo test iteration $iteration;
SELECT 1;
dec $test;
inc $iteration;
}
Output: |
---|
/tests/r/testname.result:
test iteration 1
SELECT 1;
1
1
test iteration 2
SELECT 1;
1
1
test iteration 3
SELECT 1;
1
1
Note
Ensure that, the expr value becomes zero at some point of time. Else, the loop gets executed infinitely and the test gets stalled.
Syntax: |
---|
write_file file_name [terminator]
write_file command is write data to the file specified by file_name. When this command is issued, a file with the name as file_name is created and data is written to it. The end of the data, that is to be written, is marked by the terminator.
Note
If the file exists, it is not considered as error / the test will not fail. Instead, the contents of the file will be replaced by the data that is to be written.
The file_name can be substituted via variables.
Example: |
---|
let $MY_FILE = ~/foo/bar.txt
write_file $MY_FILE;
testing...
EOF
Output: |
---|
~/foo/bar.txt:
testing...
Example: |
---|
let $MY_FILE = ~/foo/bar.txt
write_file $MY_FILE stop;
testing with test-run...
stop
Output: |
---|
~/foo/bar.txt:
testing with test-run...
Note
In the above example, the contents present previously in bar.txt are overwritten