Skip to content

Commit

Permalink
Merge pull request #186 from yast/addrepo-unit-test
Browse files Browse the repository at this point in the history
Add a test to Yast::AddOnProduct.AddRepo
  • Loading branch information
imobachgs committed Aug 29, 2016
2 parents 46a0b54 + 9a3a00c commit 682a0fc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/addon_product_test.rb
Expand Up @@ -282,4 +282,45 @@
end
end
end

describe "#AddRepo" do
let(:url) { "ftp://user:mypass@example.net/add-on" }
let(:pth) { "/" }
let(:prio) { 50 }

context "when the repo is added successfully" do
let(:repo_id) { 1 }

it "returns the new repository id" do
expect(Yast::Pkg).to receive(:RepositoryAdd)
.with("enabled" => true, "base_urls" => [url], "prod_dir" => pth, "priority" => prio)
.and_return(repo_id)
expect(subject.AddRepo(url, pth, prio)).to eq(repo_id)
end

it "sets priority if it is greater than -1" do
expect(Yast::Pkg).to receive(:RepositoryAdd)
.with("enabled" => true, "base_urls" => [url], "prod_dir" => pth)
.and_return(repo_id)
expect(subject.AddRepo(url, pth, -2)).to eq(repo_id)
end

it "refresh packages metadata" do
allow(Yast::Pkg).to receive(:RepositoryAdd).and_return(repo_id)
expect(Yast::Pkg).to receive(:SourceSaveAll)
expect(Yast::Pkg).to receive(:SourceRefreshNow).with(repo_id)
expect(Yast::Pkg).to receive(:SourceLoad)
subject.AddRepo(url, pth, prio)
end
end

context "when the repo is not added successfully" do
it "reports the error and returns nil" do
allow(Yast::Pkg).to receive(:RepositoryAdd).and_return(nil)
expect(Yast::Report).to receive(:Error)
.with(format(_("Unable to add product %s."), "ftp://user:PASSWORD@example.net/add-on"))
subject.AddRepo(url, pth, prio)
end
end
end
end
5 changes: 5 additions & 0 deletions test/test_helper.rb
Expand Up @@ -13,3 +13,8 @@

TESTS_PATH = Pathname.new(File.dirname(__FILE__))
FIXTURES_PATH = TESTS_PATH.join("data")

RSpec.configure do |config|
config.extend Yast::I18n # available in context/describe
config.include Yast::I18n # available in it/let/before/...
end

0 comments on commit 682a0fc

Please sign in to comment.