Skip to content

Commit

Permalink
added test/registration_spec.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Apr 18, 2014
1 parent 8077c5e commit 95b55bd
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions test/registration_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#! /usr/bin/env rspec

require_relative "spec_helper"
require_relative "yast_stubs"

describe "Registration::Registration" do
let(:yast_wfm) { double("Yast::Wfm") }

before do
stub_yast_require
require "registration/registration"

stub_const("Yast::WFM", yast_wfm)
yast_wfm.stub(:GetLanguage).and_return("en")
end

describe ".register" do
it "registers the system using the provided registration code" do
username = "user"
password = "password"
reg_code = "reg_code"

expect(Registration::SwMgmt).to receive(:zypp_config_writable!)
SUSE::Connect::Credentials.any_instance.should_receive(:write)
expect(SUSE::Connect::YaST).to(receive(:announce_system)
.with(hash_including(
:token => reg_code
))
.and_return([username, password])
)

Registration::Registration.new.register("email", reg_code)
end
end

describe ".register_products" do
it "registers the product and adds services" do
product = {
"arch" => "x86_64",
"name" => "SLES",
"version" => "12",
"release_type" => "DVD"
}

source = SUSE::Connect::Source.new("service", "https://example.com")
service = SUSE::Connect::Service.new([source], [], [])

expect(SUSE::Connect::YaST).to(receive(:activate_product)
.with(hash_including(
:product_ident => {:arch => product["arch"],
:product_ident => product["name"],
:product_version => product["version"],
:release_type => product["release_type"]
}
))
.and_return(service)
)
expect(Registration::SwMgmt).to receive(:add_services)

service_list = Registration::Registration.new.register_products([product])
expect(service_list).to eq([service])
end
end

end

0 comments on commit 95b55bd

Please sign in to comment.