# SPDX-License-Identifier: GPL-2.0-or-later

package Amavis::SpamControl::RspamdClientTest;

use Test::Most;
use base 'Test::Class';

use File::Temp;

sub class { 'Amavis::SpamControl::RspamdClient' }

sub startup : Tests(startup => 1) {
  my $test = shift;
  use_ok $test->class;
}

sub constructor : Tests(3) {
  my $test  = shift;
  my $class = $test->class;
  can_ok $class, 'new';
  ok my $lookup = $class->new,
  '... and the constructor should succeed';
  isa_ok $lookup, $class, '... and the object it returns';
}

sub message_content : Tests {
    my $test = shift;
    my $message_content = $test->class->can('message_content');

    my $msg = \'Hello World';
    is $message_content->($msg), 'Hello World';
    is $message_content->($msg, 5), 'Hello';

    my $tmp = File::Temp->new;
    $msg = IO::File->new($tmp->filename, '+<');
    print $msg 'Hello World';
    $msg->flush;

    is $message_content->($msg), 'Hello World';
    is $message_content->($msg, 5), 'Hello';
}

1;
