Skip to content

Commit

Permalink
Avoid yast2-installation dependency in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Jun 22, 2021
1 parent e19fff6 commit d3019f3
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 41 deletions.
24 changes: 12 additions & 12 deletions src/lib/y2firewall/clients/auto.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# ------------------------------------------------------------------------------
# Copyright (c) 2017 SUSE LLC
# Copyright (c) [2017-2021] 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 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.
# 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.
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE about this file by physical or electronic mail, you may find
# current contact information at www.suse.com.
# ------------------------------------------------------------------------------
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "yast"
require "y2firewall/firewalld"
Expand Down
28 changes: 16 additions & 12 deletions test/lib/y2firewall/clients/auto_test.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#!/usr/bin/env rspec

# ------------------------------------------------------------------------------
# Copyright (c) 2017 SUSE LLC
# Copyright (c) [2017-2021] 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 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.
# 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.
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE about this file by physical or electronic mail, you may find
# current contact information at www.suse.com.
# ------------------------------------------------------------------------------
# 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"
require "y2firewall/dialogs/main"
Expand All @@ -36,8 +36,12 @@
allow(firewalld).to receive(:installed?).and_return(installed)
allow(subject).to receive(:autoyast).and_return(autoyast)
allow_any_instance_of(Y2Firewall::Firewalld::Api).to receive(:running?).and_return(false)

allow(subject).to receive(:settings).and_return(security_settings)
end

let(:security_settings) { double("::Installation::SecuritySettings", enable_firewall: false) }

describe "#summary" do
let(:installed) { false }

Expand Down
31 changes: 14 additions & 17 deletions test/lib/y2firewall/widgets/proposal_test.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
#!/usr/bin/env rspec

# ------------------------------------------------------------------------------
# Copyright (c) 2017 SUSE LLC
# Copyright (c) [2017-2021] 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 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.
# 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.
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE about this file by physical or electronic mail, you may find
# current contact information at www.suse.com.
# ------------------------------------------------------------------------------
# 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.rb"
require "cwm/rspec"
require "y2firewall/widgets/proposal"
require "installation/security_settings"

describe Y2Firewall::Widgets do
let(:proposal_settings) do
instance_double(
::Installation::SecuritySettings, enable_firewall: true, enable_sshd: true,
open_ssh: true, open_vnc: true
)
double("::Installation::SecuritySettings", enable_firewall: true, enable_sshd: true,
open_ssh: true, open_vnc: true)
end

describe Y2Firewall::Widgets::FirewallSSHProposal do
Expand Down
15 changes: 15 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@
require "yast"
require "yast/rspec"

LIBS_TO_SKIP = ["installation/security_settings"]

# Hack to avoid to require some files
#
# This is here to avoid a cyclic dependency with yast-installation at build time.
# The package yast-firewall does not include a BuildRequires for yast-installation, so the require
# for files defined by that package must be avoided.
module Kernel
alias_method :old_require, :require

def require(path)
old_require(path) unless LIBS_TO_SKIP.include?(path)
end
end

# stub module to prevent its Import
# Useful for modules from different yast packages, to avoid build dependencies
def stub_module(name, fake_class = nil)
Expand Down

0 comments on commit d3019f3

Please sign in to comment.