Skip to content

Commit

Permalink
Migrate mergeTables testsuite to RSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
ancorgs committed Feb 6, 2020
1 parent c7a3dc4 commit 4a9a362
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 70 deletions.
107 changes: 107 additions & 0 deletions test/mail_aliases_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/usr/bin/env rspec
# Copyright (c) [2020] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require_relative "test_helper"

Yast.import "MailAliases"

describe Yast::MailAliases do
describe ".mergeTables" do
let(:old1) do
[
{
"comment" => " Basic system aliases that MUST be present.\n",
"value" => "root",
"key" => "postmaster"
},
{ "comment" => "", "value" => "postmaster", "key" => "mailer-daemon" },
{ "comment" => " amavis\n", "value" => "root", "key" => "virusalert" },
{
"comment" => " General redirections for pseudo accounts in /etc/passwd.\n",
"value" => "root",
"key" => "administrator"
},
{ "comment" => "", "value" => "root", "key" => "daemon" },
{ "comment" => "", "value" => "root", "key" => "nobody" },
{
"comment" => " \"bin\" used to be in /etc/passwd\n",
"value" => "root",
"key" => "bin"
},
{
"comment" => " Further well-known aliases for dns/news/ftp/mail/fax/web/gnats.\n",
"value" => "news",
"key" => "newsadm"
},
{ "comment" => "", "value" => "news", "key" => "newsadmin" },
{ "comment" => "", "value" => "news", "key" => "usenet" }
]
end

let(:new1) do
[
{ "key" => "root", "value" => "auser", "comment" => " I am r00t!" },
{ "key" => "B.User", "value" => "buser", "comment" => " blah" },
{ "key" => "usenet", "value" => "root", "comment" => " direct" },
{ "key" => "A.User", "value" => "auser", "comment" => "" },
{ "key" => "newsadmin", "value" => "root", "comment" => " direct" }
]
end

let(:merged) do
old1[0..7] + [
{ "comment" => " direct", "key" => "newsadmin", "value" => "root" },
{ "comment" => " direct", "key" => "usenet", "value" => "root" },
{ "comment" => " I am r00t!", "key" => "root", "value" => "auser" },
{ "comment" => " blah", "key" => "B.User", "value" => "buser" },
{ "comment" => "", "key" => "A.User", "value" => "auser" }
]
end

it "returns a merged table" do
expect(described_class.mergeTables(new1, old1)).to eq merged
end

context "when the first table is empty" do
let(:new1) { [] }

it "returns the second table" do
expect(described_class.mergeTables(new1, old1)).to eq old1
end
end

context "when the second table is empty" do
let(:old1) { [] }

it "returns the first table" do
expect(described_class.mergeTables(new1, old1)).to eq new1
end
end

context "when both tables are empty" do
let(:old1) { [] }
let(:new1) { [] }

it "returns an empty table" do
expect(described_class.mergeTables(new1, old1)).to eq []
end
end
end
end
48 changes: 48 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright (c) [2020] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

# Set the paths
SRC_PATH = File.expand_path("../src", __dir__)
ENV["Y2DIR"] = SRC_PATH

# make sure we run the tests in English locale
# (some tests check the output which is marked for translation)
ENV["LC_ALL"] = "en_US.UTF-8"

require "yast"
require "yast/rspec"

if ENV["COVERAGE"]
require "simplecov"
SimpleCov.start do
add_filter "/test/"
end

# track all ruby files under src
SimpleCov.track_files("#{SRC_PATH}/**/*.rb")

# use coveralls for on-line code coverage reporting at Travis CI
if ENV["TRAVIS"]
require "coveralls"
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
]
end
end
Empty file removed testsuite/tests/mergeTables.err
Empty file.
4 changes: 0 additions & 4 deletions testsuite/tests/mergeTables.out

This file was deleted.

66 changes: 0 additions & 66 deletions testsuite/tests/mergeTables.rb

This file was deleted.

0 comments on commit 4a9a362

Please sign in to comment.