diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-08-03 14:08:13 +0300 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-08-03 14:08:13 +0300 |
commit | 41f28a9ffabf4eb45c53836ea4de3b7a49229eaa (patch) | |
tree | 174d41cf6bb28ccc3c88727618886a431364a63c /lib | |
parent | 06b8f47cf3b8ce65012fe905f6d3953ff175fa85 (diff) |
Add factory for parsers. Add required specification in json schema matcher. Improved test code.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/ci/parsers.rb | 9 | ||||
-rw-r--r-- | lib/gitlab/ci/parsers/junit.rb (renamed from lib/gitlab/ci/parsers/junit_parser.rb) | 16 |
2 files changed, 15 insertions, 10 deletions
diff --git a/lib/gitlab/ci/parsers.rb b/lib/gitlab/ci/parsers.rb new file mode 100644 index 00000000000..a4eccc08dfc --- /dev/null +++ b/lib/gitlab/ci/parsers.rb @@ -0,0 +1,9 @@ +module Gitlab + module Ci + module Parsers + def self.fabricate!(file_type) + "Gitlab::Ci::Parsers::#{file_type.classify}".constantize.new + end + end + end +end diff --git a/lib/gitlab/ci/parsers/junit_parser.rb b/lib/gitlab/ci/parsers/junit.rb index 68217c6b5c4..3c4668ec13b 100644 --- a/lib/gitlab/ci/parsers/junit_parser.rb +++ b/lib/gitlab/ci/parsers/junit.rb @@ -1,28 +1,24 @@ module Gitlab module Ci module Parsers - class JunitParser + class Junit attr_reader :data JunitParserError = Class.new(StandardError) - def initialize(xml_data) + def parse!(xml_data, test_suite) @data = Hash.from_xml(xml_data) - rescue REXML::ParseException - raise JunitParserError, 'Failed to parse XML' - rescue - raise JunitParserError, 'Unknown error' - end - def parse!(test_suite) each_suite do |testcases| testcases.each do |testcase| test_case = create_test_case(testcase) test_suite.add_test_case(test_case) end end - rescue - raise JunitParserError, 'Invalid JUnit xml structure' + rescue REXML::ParseException => e + raise JunitParserError, "XML parsing failed: #{e.message}" + rescue => e + raise JunitParserError, "JUnit parsing failed: #{e.message}" end private |