Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed Aug 10, 2018
1 parent cf60751 commit 37f83bb
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/modules/IscsiClient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ def main
# Data was modified?
@modified = false


@proposal_valid = false

# FIXME: write_only seems to be not in use
# Write only, used during autoinstallation.
# Don't run services and SuSEconfig, it's all done at one place.
@write_only = false
Expand Down Expand Up @@ -344,6 +344,7 @@ def AutoPackages
publish :function => :Modified, :type => "boolean ()"
publish :variable => :modified, :type => "boolean"
publish :variable => :proposal_valid, :type => "boolean"
# FIXME: write_only seems to be not in use
publish :variable => :write_only, :type => "boolean"
publish :variable => :AbortFunction, :type => "boolean ()"
publish :function => :Abort, :type => "boolean ()"
Expand Down
3 changes: 2 additions & 1 deletion test/iscsi_client_lib_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require_relative "test_helper"
#!/usr/bin/env rspec

require_relative "test_helper"
require_relative "../src/modules/IscsiClientLib"

describe Yast::IscsiClientLibClass do
Expand Down
133 changes: 127 additions & 6 deletions test/iscsi_client_test.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
#!/usr/bin/env rspec

require_relative "./test_helper"
require_relative "../src/modules/IscsiClient"

Yast.import "IscsiClient"

describe Yast::IscsiClient do
subject { described_class }
subject(:iscsi_client) { described_class }

let(:service) { instance_double("Yast2::SystemService", is_a?: true) }
before do
allow(Yast2::SystemService).to receive(:find).with(anything).and_return(service)
end

describe "#services" do
before do
allow(Yast2::SystemService).to receive(:find).with(anything).and_return(service)
end
let(:service) { instance_double(Yast2::SystemService, save: true, is_a?: true) }
let(:services) { instance_double(Yast2::CompoundService, save: true) }
let(:auto) { false }
let(:commandline) { false }

describe "#services" do
it "includes iscsi, iscsid, and iscsiuio" do
expect(Yast2::SystemService).to receive(:find).with("iscsi")
expect(Yast2::SystemService).to receive(:find).with("iscsid")
Expand All @@ -26,4 +30,121 @@
expect(subject.services).to be_a(Yast2::CompoundService)
end
end

describe "#Read" do
before do
allow(Yast::Progress).to receive(:New)
allow(Yast::Progress).to receive(:NextStage)
allow(Yast::Confirm).to receive(:MustBeRoot).and_return(true)
allow(Yast::NetworkService).to receive(:RunnungNetworkPopup).and_return(true)
allow(Yast::Builtins).to receive(:sleep)
allow(Yast::Builtins).to receive(:y2milestone)

allow(Yast::IscsiClientLib).to receive(:getiBFT).and_return(true)
allow(Yast::IscsiClientLib).to receive(:checkInitiatorName).and_return(true)
allow(Yast::IscsiClientLib).to receive(:autoLogOn)
allow(Yast::IscsiClientLib).to receive(:readSession).and_return(true)

allow(Yast::Mode).to receive(:auto) { auto }
allow(Yast::Mode).to receive(:commandline) { commandline }

allow(iscsi_client).to receive(:Abort).and_return(false)
allow(iscsi_client).to receive(:installed_packages).and_return(true)

iscsi_client.main
end

shared_examples "old behavior" do
it "calls to IscsiClientLib#getServiceStatus" do
expect(Yast::IscsiClientLib).to receive(:getServiceStatus)

iscsi_client.Read
end
end

context "when running in command line" do
let(:commandline) { true }

include_examples "old behavior"
end

context "when running in AutoYaST mode" do
let(:auto) { true }

include_examples "old behavior"
end

context "when running in normal mode" do
it "does not call to IscsiClientLib#getServiceStatus" do
expect(Yast::IscsiClientLib).to_not receive(:getServiceStatus)

iscsi_client.Read
end
end
end

describe "#Write" do
before do
allow(Yast::Progress).to receive(:New)
allow(Yast::Progress).to receive(:NextStage)
allow(Yast::Report).to receive(:Error)
allow(Yast::Builtins).to receive(:sleep)
allow(Yast::Stage).to receive(:initial).and_return(false)
allow(Yast::Mode).to receive(:auto) { auto }
allow(Yast::Mode).to receive(:commandline) { commandline }

allow(iscsi_client).to receive(:Abort).and_return(false)

iscsi_client.main
end

shared_examples "old behavior" do
before do
allow(Yast::IscsiClientLib).to receive(:autoyastPrepare)
allow(Yast::IscsiClientLib).to receive(:autoyastWrite)
end

it "does not save the system service" do
expect(service).to_not receive(:save)

iscsi_client.Write
end

it "calls to IscsiClientLib#setServiceStatus" do
expect(Yast::IscsiClientLib).to receive(:setServiceStatus)

iscsi_client.Write
end
end

context "when running in command line" do
let(:commandline) { true }

include_examples "old behavior"
end

context "when running in AutoYaST mode" do
let(:auto) { true }

include_examples "old behavior"
end

context "when running in normal mode" do
before do
allow(iscsi_client).to receive(:services).and_return(services)
end

it "does not call IscsiClientLib#setServiceStatus" do
expect(Yast::IscsiClientLib).to_not receive(:setServiceStatus)

iscsi_client.Write
end

it "saves system services" do
expect(services).to receive(:save)

iscsi_client.Write
end
end
end
end

0 comments on commit 37f83bb

Please sign in to comment.