模拟 REST:Client::REST
Mocking a REST:Client::REST
我正在尝试在 RT 系统上进行单元测试,因此我需要在本地模拟 RT 实例。基本上,我正在连接到 RT 系统并且正在处理工单队列。有人喜欢代码示例或任何想法吗?我想我需要模拟 LWP::UserAgent 但我不确定。
请出主意。提前致谢!
在我的例子下面找到:
my $mock = Test::MockModule->new('REST::Client');
my $raw_response = '';
$mock->mock(
POST => sub { # You can do the same for GET :)
my ($ua, $request) = @_;
if ($request =~ /confirm/) {
$raw_response = $confirm_response_ok; # This is response for Confirm Method in my Code
}
elsif ($request =~ /transfers/) {
$raw_response = $create_response_ok; # This is response for Create transfer in my Code
}
return '';
},
responseCode => sub {
my $self = shift;
return '200';
},
responseContent => sub {
my $self = shift;
return $raw_response;
}
);
来自迈阿密的爱。你知道在哪里可以找到我们:)
埃维里奥和哈罗德
我正在尝试在 RT 系统上进行单元测试,因此我需要在本地模拟 RT 实例。基本上,我正在连接到 RT 系统并且正在处理工单队列。有人喜欢代码示例或任何想法吗?我想我需要模拟 LWP::UserAgent 但我不确定。 请出主意。提前致谢!
在我的例子下面找到:
my $mock = Test::MockModule->new('REST::Client');
my $raw_response = '';
$mock->mock(
POST => sub { # You can do the same for GET :)
my ($ua, $request) = @_;
if ($request =~ /confirm/) {
$raw_response = $confirm_response_ok; # This is response for Confirm Method in my Code
}
elsif ($request =~ /transfers/) {
$raw_response = $create_response_ok; # This is response for Create transfer in my Code
}
return '';
},
responseCode => sub {
my $self = shift;
return '200';
},
responseContent => sub {
my $self = shift;
return $raw_response;
}
);
来自迈阿密的爱。你知道在哪里可以找到我们:)
埃维里奥和哈罗德