Skip to content

Commit

Permalink
add tests for MailAliases module
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Feb 23, 2017
1 parent c2949be commit 881dbe4
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
1 change: 1 addition & 0 deletions library/general/src/modules/MailAliases.rb
Expand Up @@ -116,6 +116,7 @@ def MergeRootAlias(aliases)

# ----------------------------------------------------------------

# TODO: drop unused
# Merges mail tables, which are order-preserving maps.
# First are the entries of the old map, with values updated
# from the new one, then the rest of the new map.
Expand Down
61 changes: 61 additions & 0 deletions library/general/test/MailAliases_test.rb
@@ -0,0 +1,61 @@
#! /usr/bin/env rspec

require_relative "test_helper"

Yast.import "MailAliases"

describe Yast::MailAliases do
subject { described_class }

around do |example|
chroot_path = File.expand_path("../data/", __FILE__)
change_scr_root(chroot_path) do
subject.ReadAliases
example.call
end
end

describe ".ReadAliases" do
it "reads aliases table and sets it without root alias" do
expected_output =[{"comment"=>" Basic system aliases that MUST be present.\n",
"alias"=>"postmaster",
"destinations"=>"root"},
{"comment"=>"", "alias"=>"mailer-daemon", "destinations"=>"postmaster"},
{"comment"=>" amavis\n", "alias"=>"virusalert", "destinations"=>"root"},
{"comment"=>" General redirections for pseudo accounts in /etc/passwd.\n",
"alias"=>"administrator",
"destinations"=>"root"}]

subject.ReadAliases
expect(subject.aliases).to eq expected_output
end

it "reads root alias" do
subject.ReadAliases
expect(subject.root_alias).to eq "jreidinger"
end
end

describe ".MergeRootAlias" do
it "prepends new root_alias to copy of argument with its original comment" do
input = [
{"comment"=>"", "alias"=>"mailer-daemon", "destinations"=>"postmaster"}
]
subject.root_alias = "my_little_pony"

expected_output = [
{"comment"=>"", "alias"=>"root", "destinations" => "my_little_pony"},
{"comment"=>"", "alias"=>"mailer-daemon", "destinations"=>"postmaster"}
]


expect(subject.MergeRootAlias(input)).to eq expected_output
end
end

describe ".GetRootAlias" do
it "reads alieases and return root one" do
expect(subject.GetRootAlias).to eq "jreidinger"
end
end
end
1 change: 1 addition & 0 deletions library/general/test/Makefile.am
Expand Up @@ -7,6 +7,7 @@ TESTS = \
finish_client_test.rb \
hooks_test.rb \
linuxrc_test.rb \
MailAliases_test.rb \
os_release_test.rb \
popup_test.rb \
proposal_client_test.rb \
Expand Down
25 changes: 25 additions & 0 deletions library/general/test/data/etc/aliases
@@ -0,0 +1,25 @@
# This is the aliases file - it says who gets mail for whom.
#
# >>>>>>>>>> The program "newaliases" will need to be run
# >> NOTE >> after this file is updated for any changes
# >>>>>>>>>> to show through to sendmail.
#
# It is probably best to not work as user root and redirect all
# email to "root" to the address of a HUMAN who deals with this
# system's problems. Then you don't have to check for important
# email too often on the root account.
# The "\root" will make sure that email is also delivered to the
# root-account, but also forwared to the user "joe".
#root: joe, \root

root: jreidinger
# Basic system aliases that MUST be present.
postmaster: root
mailer-daemon: postmaster
# amavis
virusalert: root
# General redirections for pseudo accounts in /etc/passwd.
administrator: root
# mlmmj needs only one alias to function; this is with a mailinglist in
# /var/spool/mlmmj/myownlist (remember full path):

0 comments on commit 881dbe4

Please sign in to comment.