Skip to content

Commit

Permalink
add test for execute lib
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Feb 2, 2016
1 parent 2c6a61b commit 777c11c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
4 changes: 3 additions & 1 deletion library/system/test/Makefile.am
@@ -1,8 +1,10 @@
TESTS = \
execute_test.rb \
kernel_test.rb \
hw_detection_test.rb \
fs_snapshot_test.rb \
fs_snapshot_store_test.rb
fs_snapshot_store_test.rb \
proc_cmdline_test.rb

TEST_EXTENSIONS = .rb
RB_LOG_COMPILER = rspec
Expand Down
48 changes: 48 additions & 0 deletions library/system/test/execute_test.rb
@@ -0,0 +1,48 @@
#!/usr/bin/env rspec

require_relative "test_helper"
require "yast2/execute"

Yast.import "Report"

describe Yast::Execute do
it "sets yast logger as cheetah logger" do
expect(Cheetah.default_options[:logger]).to eq Yast::Y2Logger.instance
end

describe ".locally" do
it "passes arguments directly to cheetah" do
expect(Cheetah).to receive(:run).with("ls", "-a")

Yast::Execute.locally("ls", "-a")
end

it "report error if command execution failed" do
expect(Yast::Report).to receive(:Error)
Yast::Execute.locally("false")
end

it "returns nil if command execution failed" do
expect(Yast::Execute.locally("false")).to eq nil
end
end

describe ".on_target" do
it "adds to passed arguments chroot option if scr chrooted" do
Yast::Installation.destdir = "/mnt"
allow(Yast::WFM).to receive(:scr_chrooted?).and_return(true)
expect(Cheetah).to receive(:run).with("ls", "-a", chroot: "/mnt")

Yast::Execute.on_target("ls", "-a")
end

it "report error if command execution failed" do
expect(Yast::Report).to receive(:Error)
Yast::Execute.on_target("false")
end

it "returns nil if command execution failed" do
expect(Yast::Execute.on_target("false")).to eq nil
end
end
end

0 comments on commit 777c11c

Please sign in to comment.