testrail-tests.t 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. use strict;
  2. use warnings;
  3. use Test::More "tests" => 32;
  4. use Test::Fatal;
  5. use FindBin;
  6. use Capture::Tiny qw{capture_merged};
  7. use lib $FindBin::Bin.'/../bin';
  8. require 'testrail-tests';
  9. use lib $FindBin::Bin.'/lib';
  10. use Test::LWP::UserAgent::TestRailMock;
  11. #check plan mode
  12. my @args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -p GosPlan -r}, "Executing the great plan", qw{-m t --config testConfig --no-recurse});
  13. my ($out,$code) = TestRail::Bin::Tests::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
  14. is($code, 0, "Exit code OK running plan mode, no recurse");
  15. chomp $out;
  16. like($out,qr/skipall\.test$/,"Gets test correctly in plan mode, no recurse");
  17. #check no-match
  18. @args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -p GosPlan -r}, "Executing the great plan", qw{--no-match t --config testConfig });
  19. ($out,$code) = TestRail::Bin::Tests::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
  20. is($code, 0, "Exit code OK running plan mode, no match");
  21. chomp $out;
  22. unlike($out,qr/skipall\.test/,"Omits test correctly in plan mode, recurse, no-match");
  23. unlike($out,qr/NOT SO SEARED AFTER ARR/,"Omits non-file test correctly in plan mode, recurse, no-match");
  24. like($out,qr/faker\.test/,"Omits non-file test correctly in plan mode, recurse, no-match");
  25. #check no-match, no recurse
  26. @args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -p GosPlan -r}, "Executing the great plan", qw{--no-match t --config testConfig --no-recurse});
  27. ($out,$code) = TestRail::Bin::Tests::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
  28. is($code, 0, "Exit code OK running plan mode, no match, no recurse");
  29. chomp $out;
  30. unlike($out,qr/skipall\.test/,"Omits test correctly in plan mode, no recurse, no-match");
  31. unlike($out,qr/NOT SO SEARED AFTER ARR/,"Omits non-file test correctly in plan mode, no recurse, no-match");
  32. like($out,qr/faker\.test/,"Omits non-file test correctly in plan mode, no recurse, no-match");
  33. @args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -p GosPlan -r}, "Executing the great plan", qw{--config testConfig -m t });
  34. ($out,$code) = TestRail::Bin::Tests::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
  35. is($code, 0, "Exit code OK running plan mode, recurse");
  36. chomp $out;
  37. like($out,qr/skipall\.test$/,"Gets test correctly in plan mode, recurse");
  38. #check non plan mode
  39. @args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -r TestingSuite -m t --no-recurse});
  40. ($out,$code) = TestRail::Bin::Tests::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
  41. is($code, 0, "Exit code OK running no plan mode, no recurse");
  42. chomp $out;
  43. like($out,qr/skipall\.test$/,"Gets test correctly in no plan mode, no recurse");
  44. @args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -r TestingSuite -m t });
  45. ($out,$code) = TestRail::Bin::Tests::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
  46. is($code, 0, "Exit code OK running no plan mode, recurse");
  47. chomp $out;
  48. like($out,qr/skipall\.test$/,"Gets test correctly in no plan mode, recurse");
  49. #Negative case, filtering by config
  50. @args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -p GosPlan -r}, "Executing the great plan", qw{-m t --config testPlatform1});
  51. isnt(exception {TestRail::Bin::Tests::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)}, undef, "Exit code not OK when passing invalid configs for plan");
  52. #check assignedto filters
  53. @args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -p GosPlan -r}, "Executing the great plan", qw{ --config testConfig --assignedto teodesian});
  54. ($out,$code) = TestRail::Bin::Tests::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
  55. is($code, 0, "Exit code OK when filtering by assignment");
  56. like($out,qr/skipall\.test$/,"Gets test correctly when filtering by assignment");
  57. @args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -p GosPlan -r}, "Executing the great plan", qw{ --config testConfig --assignedto billy});
  58. ($out,$code) = TestRail::Bin::Tests::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
  59. is($code, 255, "Exit code OK when filtering by assignment");
  60. chomp $out;
  61. is($out,"","Gets no tests correctly when filtering by wrong assignment");
  62. #check status filters
  63. @args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -p GosPlan -r}, "Executing the great plan", qw{-m t --config testConfig --status passed});
  64. ($out,$code) = TestRail::Bin::Tests::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
  65. is($code, 0, "Exit code OK when filtering by status");
  66. like($out,qr/skipall\.test$/,"Gets test correctly when filtering by status");
  67. @args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -p GosPlan -r}, "Executing the great plan", qw{ --config testConfig --status failed});
  68. ($out,$code) = TestRail::Bin::Tests::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
  69. is($code, 255, "Exit code OK when filtering by status");
  70. chomp $out;
  71. is($out,"","Gets no tests correctly when filtering by wrong status");
  72. #Verify no-match returns non path
  73. @args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -r TestingSuite });
  74. ($out,$code) = TestRail::Bin::Tests::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
  75. is($code, 0, "Exit code OK running no plan mode, no-match");
  76. chomp $out;
  77. like($out,qr/\nskipall\.test$/,"Gets test correctly in no plan mode, no-match");
  78. #Verify no-match returns non path
  79. @args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -r TestingSuite --orphans t });
  80. ($out,$code) = TestRail::Bin::Tests::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
  81. is($code, 0, "Exit code OK running no plan mode, no recurse");
  82. chomp $out;
  83. like($out,qr/NOT SO SEARED AFTER ARR/,"Gets test correctly in orphan mode");
  84. #Verify no-match returns non path
  85. @args = qw{--help};
  86. $0 = $FindBin::Bin.'/../bin/testrail-tests';
  87. ($out,(undef,$code)) = capture_merged {TestRail::Bin::Tests::run('args' => \@args)};
  88. is($code, 0, "Exit code OK asking for help");
  89. like($out,qr/encoding of arguments/i,"Help output OK");
  90. #Make sure that the binary itself processes args correctly
  91. $out = `$^X $0 --help`;
  92. like($out,qr/encoding of arguments/i,"Appears we can run binary successfully");