diff options
author | Aleksejs Sestakovs <aleksejs.sestakovs@zabbix.com> | 2019-11-07 11:43:39 +0300 |
---|---|---|
committer | Aleksejs Sestakovs <aleksejs.sestakovs@zabbix.com> | 2019-11-07 11:45:43 +0300 |
commit | cd2f1247b526cb6611034b353ff5b7e034872397 (patch) | |
tree | 8a76198269263a280ac7b9e78c821354d8a4b3ca /tests/zabbix_server/preprocessor | |
parent | c4864869ad50459c38dc1511cdd094fe476c7951 (diff) |
.......... [DEV-1354] updated test cases
* commit 'b3f26be08d7efa5b94f5dd8d26f639acbe8d3e12':
.......... [DEV-1354] updated test cases
(cherry picked from commit 0e0f5fae0a546dd433fbc672fe3b0e9c9dbb7f20)
Diffstat (limited to 'tests/zabbix_server/preprocessor')
-rw-r--r-- | tests/zabbix_server/preprocessor/item_preproc_csv_to_json.yaml | 497 |
1 files changed, 294 insertions, 203 deletions
diff --git a/tests/zabbix_server/preprocessor/item_preproc_csv_to_json.yaml b/tests/zabbix_server/preprocessor/item_preproc_csv_to_json.yaml index f0512de77bc..899c0e89c06 100644 --- a/tests/zabbix_server/preprocessor/item_preproc_csv_to_json.yaml +++ b/tests/zabbix_server/preprocessor/item_preproc_csv_to_json.yaml @@ -1,5 +1,5 @@ --- -test case: 'empty parameters' +test case: 'missing second parameter' in: csv: '' params: '' @@ -7,23 +7,47 @@ out: result: '' return: 'FAIL' --- -test case: 'empty input #1' +test case: 'missing third parameter' in: csv: '' - params: ",\n\n1" + params: "\n" +out: + result: '' + return: 'FAIL' +--- +test case: 'invalid first parameter' +in: + csv: '' + params: ",.\n\n0" +out: + result: '' + return: 'FAIL' +--- +test case: 'invalid second parameter' +in: + csv: '' + params: "\n,.\n0" +out: + result: '' + return: 'FAIL' +--- +test case: 'empty input (1)' +in: + csv: '' + params: "\n\n1" out: result: '[]' return: 'SUCCEED' --- -test case: 'empty input #2' +test case: 'empty input (2)' in: csv: '' - params: ",\n\n0" + params: "\n\n0" out: result: '[]' return: 'SUCCEED' --- -test case: 'single char input #1' +test case: 'single char (1)' in: csv: 'A' params: ",\n\n1" @@ -31,7 +55,7 @@ out: result: '[]' return: 'SUCCEED' --- -test case: 'single char input #2' +test case: 'single char (2)' in: csv: 'A' params: ",\n\n0" @@ -39,7 +63,23 @@ out: result: '[{"1":"A"}]' return: 'SUCCEED' --- -test case: 'empty line input #1' +test case: 'single UTF8 4-bytes character (1)' +in: + csv: '๐' + params: ",\n\n1" +out: + result: '[]' + return: 'SUCCEED' +--- +test case: 'single UTF8 4-bytes character (2)' +in: + csv: '๐' + params: ",\n\n0" +out: + result: '[{"1":"๐"}]' + return: 'SUCCEED' +--- +test case: 'empty line (1)' in: csv: "\n" params: ",\n\n1" @@ -47,7 +87,7 @@ out: result: '[{"":""}]' return: 'SUCCEED' --- -test case: 'empty line input #2' +test case: 'empty line (2)' in: csv: "\n" params: ",\n\n0" @@ -55,340 +95,391 @@ out: result: '[{},{}]' return: 'SUCCEED' --- -test case: 'multiple empty lines input #1' +test case: 'multiple empty lines (1)' in: - csv: "\n\n" + csv: "\n\n\n" params: ",\n\n1" out: - result: '[{"":""},{"":""}]' + result: '[{"":""},{"":""},{"":""}]' return: 'SUCCEED' --- -test case: 'multiple empty lines input #2' +test case: 'multiple empty lines (2)' in: - csv: "\n\n" + csv: "\n\n\n" params: ",\n\n0" out: - result: '[{},{},{}]' + result: '[{},{},{},{}]' return: 'SUCCEED' --- -test case: 'csv input with header line' +test case: 'single column (1)' in: csv: | - nr,name,addr - 1,abc,xyz - 2,cba,zyx + nr + 1 + 2 params: "\n\n1" out: - result: '[{"nr":"1","name":"abc","addr":"xyz"},{"nr":"2","name":"cba","addr":"zyx"},{"nr":"","name":"","addr":""}]' + result: '[{"nr":"1"},{"nr":"2"},{"nr":""}]' return: 'SUCCEED' --- -test case: 'csv input without header line' +test case: 'single column (2)' in: csv: | - nr,name,addr - 1,abc,xyz - 2,cba,zyx + nr + 1 + 2 params: "\n\n0" out: - result: '[{"1":"nr","2":"name","3":"addr"},{"1":"1","2":"abc","3":"xyz"},{"1":"2","2":"cba","3":"zyx"},{}]' - return: 'SUCCEED' ---- -test case: 'CSV wihtout trailing new line' -in: - csv: "nr,\"name\",addr\n\"1\",abc,xyz\n\"2\",\"cba\",\"zyx\"\n" - params: "\n\"\n1" -out: - result: '[{"nr":"1","name":"abc","addr":"xyz"},{"nr":"2","name":"cba","addr":"zyx"},{"nr":"","name":"","addr":""}]' + result: '[{"1":"nr"},{"1":"1"},{"1":"2"},{}]' return: 'SUCCEED' --- -test case: 'CSV with header line only' +test case: 'single line (1)' in: - csv: 'nr,name,addr' + csv: "a,b,c" params: "\n\n1" out: result: '[]' return: 'SUCCEED' --- -test case: 'one line CSV' +test case: 'single line (2)' in: - csv: 'nr,name,addr' + csv: "a,b,c" params: "\n\n0" out: - result: '[{"1":"nr","2":"name","3":"addr"}]' + result: '[{"1":"a","2":"b","3":"c"}]' return: 'SUCCEED' --- -test case: 'multi-byte UTF-8 delimiter' +test case: 'no trailing line break (1)' in: - csv: | - nrัnameัaddr - 1ัabcัxyz - 2ัcbaัzyx - params: "ั\n\n1" + csv: "nr,\"name\",addr\n\"1\",abc,xyz\n\"2\",\"cba\",zyx" + params: "\n\"\n1" out: - result: '[{"nr":"1","name":"abc","addr":"xyz"},{"nr":"2","name":"cba","addr":"zyx"},{"nr":"","name":"","addr":""}]' + result: '[{"nr":"1","name":"abc","addr":"xyz"},{"nr":"2","name":"cba","addr":"zyx"}]' return: 'SUCCEED' --- -test case: 'multi-byte UTF-8 quotation character' +test case: 'no trailing line break (2)' in: - csv: | - nr,ัnameั,addr - 1,abc,ัxyzั - ั2ั,ัcbaั,ัzyxั - params: "\nั\n1" + csv: "nr,\"name\",addr\n\"1\",abc,xyz\n\"2\",\"cba\"," + params: "\n\"\n1" out: - result: '[{"nr":"1","name":"abc","addr":"xyz"},{"nr":"2","name":"cba","addr":"zyx"},{"nr":"","name":"","addr":""}]' + result: '[{"nr":"1","name":"abc","addr":"xyz"},{"nr":"2","name":"cba","addr":""}]' return: 'SUCCEED' --- -test case: 'multi-byte UTF-8 delimiter and quotation characters' +test case: 'no trailing line break (3)' in: - csv: | - nrััnameััaddr - 1ัabcััxyzั - ั2ััััcbaััััzyัxั - params: "ั\nั\n1" + csv: "nr,\"name\",addr\n\"1\",abc,xyz\n\"2\",\"cba\",\"zyx\"" + params: "\n\"\n1" out: - result: '[{"nr":"1","name":"abc","addr":"xyz"},{"nr":"2","name":"ัcbaั","addr":"zyัx"},{"nr":"","name":"","addr":""}]' + result: '[{"nr":"1","name":"abc","addr":"xyz"},{"nr":"2","name":"cba","addr":"zyx"}]' return: 'SUCCEED' --- -test case: 'single column CSV input #1' +test case: 'empty fields (1)' in: - csv: | - nr - 1 - 2 + csv: ",," params: "\n\n1" out: - result: '[{"nr":"1"},{"nr":"2"},{"nr":""}]' - return: 'SUCCEED' + result: '' + return: 'FAIL' --- -test case: 'single column CSV input #2' +test case: 'empty fields (2)' in: - csv: | - nr - 1 - 2 + csv: ",," params: "\n\n0" out: - result: '[{"1":"nr"},{"1":"1"},{"1":"2"},{}]' + result: '[{"1":"","2":"","3":""}]' return: 'SUCCEED' --- -test case: 'less fields in one row #1' +test case: 'empty fields (3)' in: - csv: | - nr,name,addr - 1,abc,xyz - 2,cba - 3,def,fed - params: "\n\n0" + csv: "a,b,c\n,," + params: "\n\n1" out: - result: '[{"1":"nr","2":"name","3":"addr"},{"1":"1","2":"abc","3":"xyz"},{"1":"2","2":"cba"},{"1":"3","2":"def","3":"fed"},{}]' + result: '[{"a":"","b":"","c":""}]' return: 'SUCCEED' --- -test case: 'less fields in one row #2' +test case: 'delimiter in quoted field' in: - csv: | - nr,name,addr - 1,abc,xyz - 2,cba - 3,def,fed - params: "\n\n1" + csv: '`fld,1`,`fld,2`' + params: "\n`\n0" out: - result: '[{"nr":"1","name":"abc","addr":"xyz"},{"nr":"2","name":"cba","addr":""},{"nr":"3","name":"def","addr":"fed"},{"nr":"","name":"","addr":""}]' + result: '[{"1":"fld,1","2":"fld,2"}]' return: 'SUCCEED' --- -test case: 'more fields in one row #1' +test case: 'quotation character in unquoted field' in: - csv: | - nr,name,addr - 1,abc,xyz - 2,cba,zyx,extra - 3,def,fed - params: "\n\n0" + csv: 'fld`1,fld`2' + params: "\n`\n0" out: - result: '[{"1":"nr","2":"name","3":"addr"},{"1":"1","2":"abc","3":"xyz"},{"1":"2","2":"cba","3":"zyx","4":"extra"},{"1":"3","2":"def","3":"fed"},{}]' + result: '[{"1":"fld`1","2":"fld`2"}]' return: 'SUCCEED' --- -test case: 'more fields in one row #2' +test case: 'quotation character in unquoted field (2)' in: - csv: | - nr,name,addr - 1,abc,xyz - 2,cba,zyx,extra - 3,def,fed - params: "\n\n1" + csv: ' `fld`1` , `fld`2` ' + params: "\n`\n0" out: - result: '' - return: 'FAIL' + result: '[{"1":" `fld`1` ","2":" `fld`2` "}]' + return: 'SUCCEED' --- -test case: 'quoted fields' +test case: 'escaped quotation character' in: - csv: | - nr,|name, surname|,addr - |1|,ab|c|,|x||y,z| - 2,|||cba|||,|||zyx||| - params: "\n|\n1" + csv: '`fld``1`,`fld``2`' + params: "\n`\n0" out: - result: '[{"nr":"1","name, surname":"ab|c|","addr":"x|y,z"},{"nr":"2","name, surname":"|cba|","addr":"|zyx|"},{"nr":"","name, surname":"","addr":""}]' + result: '[{"1":"fld`1","2":"fld`2"}]' return: 'SUCCEED' --- -test case: 'empty fields #1' +test case: 'delimiter set in sep line' in: - csv: | - ,, - ,, + csv: |- + sEp=. + col1,.;col2,.; + fld1,.;fld2,.; params: "\n\n1" out: - result: '' - return: 'FAIL' + result: '[{"col1,":"fld1,",";col2,":";fld2,",";":";"}]' + return: 'SUCCEED' --- -test case: 'empty fields #2' +test case: 'cr/nl line breaks' in: - csv: | - ,, - ,, + csv: "Sep=.\r\nname.addr\r\nabc.xyz\r\n\r\nfld1.fld2\r\n\r\n\r\nfld3.fld4\r\n" + params: "\n\n1" +out: + result: '[{"name":"abc","addr":"xyz"},{"name":"","addr":""},{"name":"fld1","addr":"fld2"},{"name":"","addr":""},{"name":"","addr":""},{"name":"fld3","addr":"fld4"},{"name":"","addr":""}]' + return: 'SUCCEED' +--- +test case: 'various length rows' +in: + csv: |- + fld1,fld2,fld3 + fld1,fld2,fld3,fld4 + fld1,fld2 + fld1,fld2,fld3,fld4,fld5 params: "\n\n0" out: - result: '[{"1":"","2":"","3":""},{"1":"","2":"","3":""},{}]' + result: '[{"1":"fld1","2":"fld2","3":"fld3"},{"1":"fld1","2":"fld2","3":"fld3","4":"fld4"},{"1":"fld1","2":"fld2"},{"1":"fld1","2":"fld2","3":"fld3","4":"fld4","5":"fld5"}]' return: 'SUCCEED' --- -test case: 'empty fields #3' +test case: 'equal delimiter and quotation characters' in: - csv: | - ||,||,|| - ||,||,|| - params: "\n|\n0" + csv: |- + ,fld1,,fld2 + params: ",\n,\n0" out: - result: '[{"1":"","2":"","3":""},{"1":"","2":"","3":""},{}]' + result: '[{"1":"","2":"fld1","3":"","4":"fld2"}]' return: 'SUCCEED' --- -test case: 'duplicated column names' +test case: 'UTF8 2-byte delimiter' in: - csv: | - nr,name,name - 1,abc,xyz - 2,cba,zyx - params: "\n\n1" + csv: |- + col1ัcol2 + fld1ัfld2 + params: "ั\n\n1" out: - result: '' - return: 'FAIL' + result: '[{"col1":"fld1","col2":"fld2"}]' + return: 'SUCCEED' --- -test case: 'unclosed quoted field #1' +test case: 'UTF8 3-byte delimiter set in sep line' in: - csv: | - nr,name,addr - 1,|abc,xyz - 2,cba,zyx - params: "\n|\n1" + csv: |- + sep=๊ข + col1๊ขcol2 + fld1๊ขfld2 + params: "\n\n1" out: - result: '' - return: 'FAIL' + result: '[{"col1":"fld1","col2":"fld2"}]' + return: 'SUCCEED' --- -test case: 'unclosed quoted field #2' +test case: 'UTF8 4-byte delimiter' in: - csv: | - nr,name,addr - 1,|abc| ,xyz - 2,cba,zyx - params: "\n|\n1" + csv: |- + col1๐col2 + fld1๐fld2 + params: "๐\n\n1" out: - result: '' - return: 'FAIL' + result: '[{"col1":"fld1","col2":"fld2"}]' + return: 'SUCCEED' --- -test case: 'CSV with sep line #1' +test case: 'UTF8 2-byte quotation character' in: - csv: | - Sep=. - nr.name.addr - 1.abc.xyz - 2.cba.zyx - params: "\n\n1" + csv: |- + ัcol1ั,ัcol,2ั + ัfld1ั,ัfld,2ั + params: "\nั\n1" out: - result: '[{"nr":"1","name":"abc","addr":"xyz"},{"nr":"2","name":"cba","addr":"zyx"},{"nr":"","name":"","addr":""}]' + result: '[{"col1":"fld1","col,2":"fld,2"}]' return: 'SUCCEED' --- -test case: 'CSV with sep line #2' +test case: 'UTF8 3-byte quotation character' in: - csv: | - Sep=. - nr.name.addr - 1.abc.xyz - 2.cba.zyx - params: "\n\n0" + csv: |- + ๊ขcol1๊ข,๊ขcol,2๊ข + ๊ขfld1๊ข,๊ขfld,2๊ข + params: "\n๊ข\n1" out: - result: '[{"1":"nr","2":"name","3":"addr"},{"1":"1","2":"abc","3":"xyz"},{"1":"2","2":"cba","3":"zyx"},{}]' + result: '[{"col1":"fld1","col,2":"fld,2"}]' return: 'SUCCEED' --- -test case: 'CSV with unsupported sep line #1' +test case: 'UTF8 multi-byte delimiter and quotation characters' in: - csv: | - Sep=.. - nr.name.addr - 1.abc.xyz - 2.cba.zyx - params: "\n\n1" + csv: |- + ๐col1๐๊ข๐col2๐๊ข๐๐ + fld1๊ข๐fld2๐๊ข + params: "๊ข\n๐\n1" out: - result: '[{"Sep=..":"nr.name.addr"},{"Sep=..":"1.abc.xyz"},{"Sep=..":"2.cba.zyx"},{"Sep=..":""}]' + result: '[{"col1":"fld1","col2":"fld2","":""}]' return: 'SUCCEED' --- -test case: 'CSV with unsupported sep line #2' +test case: 'delimiter set to space' in: - csv: | - sep=ัะธะผะฒะพะปั - 1,2,3,4,5,6 - params: "\n\n0" + csv: |- + col1 col2 `col 3` + fld1 fld2 `fld 3` + params: " \n`\n1" out: - result: '[{"1":"sep=ัะธะผะฒะพะปั"},{"1":"1","2":"2","3":"3","4":"4","5":"5","6":"6"},{}]' + result: '[{"col1":"fld1","col2":"fld2","col 3":"fld 3","":""}]' return: 'SUCCEED' --- -test case: 'CSV with sep line #3' +test case: 'quotation character set to space' in: - csv: | - Sep=! - nr.name.addr - 1.abc.xyz - 2.cba.zyx - params: ".\n\n1" + csv: |- + col1, col2 ,col 3 + fld1 ,fld2, fld 3 + params: "\n \n1" out: - result: '[{"nr":"1","name":"abc","addr":"xyz"},{"nr":"2","name":"cba","addr":"zyx"},{"nr":"","name":"","addr":""}]' + result: '[{"col1":"fld1","col2":"fld2","col 3":"fld 3"}]' return: 'SUCCEED' --- -test case: 'CSV with sep line only #1' +test case: 'sep line only (1)' in: - csv: 'Sep=.' + csv: 'sep=.' params: "\n\n1" out: result: '[]' return: 'SUCCEED' --- -test case: 'CSV with sep line only #2' +test case: 'sep line only (2)' in: - csv: 'Sep=.' + csv: 'sep=.' params: "\n\n0" out: result: '[]' return: 'SUCCEED' --- -test case: 'CSV with unsupported sep line only #1' +test case: 'sep line only (3)' in: - csv: 'Sep=..' + csv: "sep=.\n" params: "\n\n1" out: result: '[]' return: 'SUCCEED' --- -test case: 'CSV with unsupported sep line only #2' +test case: 'sep line only (4)' +in: + csv: 'sep=.' + params: "\n\n0" +out: + result: '[]' + return: 'SUCCEED' +--- +test case: 'unsupported sep line (1)' in: - csv: 'Sep=..' + csv: |- + sep=.; + fld1,fld2 params: "\n\n0" out: - result: '[{"1":"Sep=.."}]' + result: '[{"1":"sep=.;"},{"1":"fld1","2":"fld2"}]' return: 'SUCCEED' --- -test case: 'cr/nl line endings' +test case: 'unsupported sep line (2)' in: - csv: "Sep=.\r\nname.addr\r\nabc.xyz\r\n" + csv: |- + sep= + fld1,fld2 + params: "\n\n0" +out: + result: '[{"1":"sep="},{"1":"fld1","2":"fld2"}]' + return: 'SUCCEED' +--- +test case: 'duplicated column names (1)' +in: + csv: |- + col1,col1 + fld1,fld2 + params: "\n\n1" +out: + result: '' + return: 'FAIL' +--- +test case: 'duplicated column names (2)' +in: + csv: |- + , + fld1,fld2 + params: "\n\n1" +out: + result: '' + return: 'FAIL' +--- +test case: 'more fields in data row than in header' +in: + csv: |- + col1,col1 + fld1,fld2,fld3 params: "\n\n1" out: - result: '[{"name":"abc","addr":"xyz"},{"name":"","addr":""}]' + result: '' + return: 'FAIL' +--- +test case: 'unclosed quoted field' +in: + csv: 'col1,"col1' + params: "\n\"\n0" +out: + result: '' + return: 'FAIL' +--- +test case: 'missing delimiter or line break after quoted field' +in: + csv: 'col1,"col1" ' + params: "\n\"\n0" +out: + result: '' + return: 'FAIL' +--- +test case: 'unsupported line break' +in: + csv: "col1,col1\n\rfld1,fld2" + params: "\n\n0" +out: + result: '' + return: 'FAIL' +--- +test case: 'CSV sample input (1)' +in: + csv: | + sEp=. + ;c`2;`;```;๐๊ขัa;col.5;`col6`;col7 + fld.1;`fld.2`;f`3;`;```;;``;aั๊ข๐ + + ``;fld2`ั;fld3๊ข`;`๐`;;`` + + + ;c`2;`;```;๐๊ขัa;col.5;`col6`;col7 + params: ";\n`\n1" +out: + result: '[{"":"fld.1","c`2":"fld.2",";`":"f`3","๐๊ขัa":";`","col.5":"","col6":"","col7":"aั๊ข๐"},{"":"","c`2":"",";`":"","๐๊ขัa":"","col.5":"","col6":"","col7":""},{"":"","c`2":"fld2`ั",";`":"fld3๊ข`","๐๊ขัa":"๐","col.5":"","col6":"","col7":""},{"":"","c`2":"",";`":"","๐๊ขัa":"","col.5":"","col6":"","col7":""},{"":"","c`2":"",";`":"","๐๊ขัa":"","col.5":"","col6":"","col7":""},{"":"","c`2":"c`2",";`":";`","๐๊ขัa":"๐๊ขัa","col.5":"col.5","col6":"col6","col7":"col7"},{"":"","c`2":"",";`":"","๐๊ขัa":"","col.5":"","col6":"","col7":""}]' + return: 'SUCCEED' +--- +test case: 'CSV sample input (2)' +in: + csv: |- + sEp=. + col1,.;col2,.; + fld1,.;fld2,.; + params: ";\n\n1" +out: + result: '[{"col1,.":"fld1,.","col2,.":"fld2,.","":""}]' return: 'SUCCEED' ... |