Skip to content

Commit 7c35e78

Browse files
committed
test: add support for changing target parser
1 parent 072b938 commit 7c35e78

File tree

4 files changed

+40
-12
lines changed

4 files changed

+40
-12
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,9 @@ jobs:
3838
with:
3939
ruby-version: ${{ matrix.ruby }}
4040
bundler-cache: true # 'bundle install' and cache gems
41-
- run: bundle exec rake
41+
- name: Test with REXML
42+
run: bundle exec rake
43+
- name: Test with libxml
44+
env:
45+
XMLRPC_PARSER: libxml
46+
run: bundle exec rake

test/helper.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require "test-unit"
2+
3+
module TestHelper
4+
def parser
5+
case ENV["XMLRPC_PARSER"]
6+
when "libxml"
7+
XMLRPC::XMLParser::LibXMLStreamParser.new
8+
else
9+
XMLRPC::XMLParser::REXMLStreamParser.new
10+
end
11+
end
12+
end

test/test_client.rb

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: false
2-
require 'test/unit'
2+
3+
require_relative 'helper'
4+
35
require 'xmlrpc/client'
46
require 'net/http'
57
begin
@@ -9,6 +11,8 @@
911

1012
module XMLRPC
1113
class ClientTest < Test::Unit::TestCase
14+
include TestHelper
15+
1216
module Fake
1317
class HTTP < Net::HTTP
1418
class << self
@@ -217,7 +221,7 @@ def test_request
217221
'/foo' => [ Fake::Response.new(fh, [['Content-Type', 'text/xml']]) ]
218222
}
219223

220-
client = fake_client(responses).new2 'http://example.org/foo'
224+
client = fake_client(responses, 'http://example.org/foo')
221225

222226
resp = client.call('wp.getUsersBlogs', 'tlo', 'omg')
223227

@@ -239,7 +243,7 @@ def test_async_request
239243
'/foo' => [ Fake::Response.new(fh, [['Content-Type', 'text/xml']]) ]
240244
}
241245

242-
client = fake_client(responses).new2 'http://example.org/foo'
246+
client = fake_client(responses, 'http://example.org/foo')
243247

244248
resp = client.call_async('wp.getUsersBlogs', 'tlo', 'omg')
245249

@@ -261,7 +265,7 @@ def test_application_xml_content_type
261265
'/foo' => [ Fake::Response.new(fh, [['Content-Type', 'application/xml']]) ]
262266
}
263267

264-
client = fake_client(responses).new2 'http://example.org/foo'
268+
client = fake_client(responses, 'http://example.org/foo')
265269

266270
resp = client.call('wp.getUsersBlogs', 'tlo', 'omg')
267271

@@ -284,7 +288,7 @@ def test_bad_content_type
284288
'/foo' => [ Fake::Response.new(fh) ]
285289
}
286290

287-
client = fake_client(responses).new2 'http://example.org/foo'
291+
client = fake_client(responses, 'http://example.org/foo')
288292

289293
resp = client.call('wp.getUsersBlogs', 'tlo', 'omg')
290294

@@ -304,7 +308,7 @@ def test_no_data
304308
'/foo' => [ Fake::Response.new(nil, [['Content-Type', 'text/xml']]) ]
305309
}
306310

307-
client = fake_client(responses).new2 'http://example.org/foo'
311+
client = fake_client(responses, 'http://example.org/foo')
308312

309313
assert_raise(RuntimeError.new("No data")) do
310314
client.call('wp.getUsersBlogs', 'tlo', 'omg')
@@ -318,7 +322,7 @@ def test_i8_tag
318322
'/foo' => [ Fake::Response.new(fh) ]
319323
}
320324

321-
client = fake_client(responses).new2 'http://example.org/foo'
325+
client = fake_client(responses, 'http://example.org/foo')
322326

323327
resp = client.call('wp.getUsersBlogs', 'tlo', 'omg')
324328

@@ -348,10 +352,13 @@ def read filename
348352
File.read File.expand_path(File.join(__FILE__, '..', 'data', filename))
349353
end
350354

351-
def fake_client responses
352-
Class.new(Fake::Client) {
355+
def fake_client(responses, uri)
356+
client_class = Class.new(Fake::Client) {
353357
define_method(:net_http) { |*_| Fake::HTTP.new(responses) }
354358
}
359+
client = client_class.new2(uri)
360+
client.set_parser(parser)
361+
client
355362
end
356363
end
357364
end

test/test_server.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
# coding: utf-8
21
# frozen_string_literal: true
32

4-
require 'test/unit'
3+
require_relative 'helper'
4+
55
require 'stringio'
66
require 'xmlrpc/client'
77
require 'xmlrpc/server'
88

99
module TestXMLRPC
1010
class TestXMLRPCServer < Test::Unit::TestCase
11+
include TestHelper
12+
1113
def test_port
1214
s = nil
1315
begin
1416
stdout, $stdout = $stdout, StringIO.new
1517
stderr, $stderr = $stderr, StringIO.new
1618
s = XMLRPC::Server.new(0, '127.0.0.1', 1)
19+
s.set_parser(parser)
1720
ensure
1821
$stdout = stdout
1922
$stderr = stderr
@@ -25,6 +28,7 @@ def test_port
2528

2629
begin
2730
c = XMLRPC::Client.new('127.0.0.1', '/', s.port)
31+
c.set_parser(parser)
2832
assert_equal(7, c.call('test.add', 3, 4))
2933
ensure
3034
s.shutdown

0 commit comments

Comments
 (0)