aboutsummaryrefslogtreecommitdiffstats
path: root/t/001-creates-a-new-alias-for-a-contact-with-an-existing-name.t
blob: 26e811956e09a18e82b58632dd007fe8b7a0cb1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env perl

use strict;
use warnings;

use Test::More;
use File::Copy qw(copy);

use feature qw(say);

my $tmp_file = "./testdata/tmp";

# Setup: make a temporary alias file
copy("./testdata/aliases", $tmp_file);


# Append test alias to alises file
open(my $fh, '>>', $tmp_file) or die;
say $fh 'alias paris-numa NUMA Paris <communique@numa.co>';
close $fh;


my $output = `cat ./testdata/email | ./target/debug/alias-auto-add $tmp_file`;
ok !$?;

# Check that the program outputs the full email coming from STDIN
{
	open(my $fh, '<', './testdata/email') or die;
	local $/ = undef;
	my $email = <$fh>;

	is $output, $email;

	close $fh;
}

# Check that the aliases file includes an alias for the address from the input email
{
	open(my $fh, '<', $tmp_file) or die;

	my $last_line;
	while (my $line = readline $fh) {
		$last_line = $line;
	}

	is $last_line, 'alias paris-numa-2 NUMA Paris <communication@numa.co>' . "\n";

	close $fh;
}


# Teardown
unlink $tmp_file;


done_testing;