Skip to content

Commit

Permalink
better Travis integration
Browse files Browse the repository at this point in the history
- removed Yast stubs, install real Yast instead
- run all tests at Travis

Conflicts:
	test/helpers_spec.rb
  • Loading branch information
lslezak committed Nov 11, 2014
1 parent 1df0baf commit 1fa7e48
Show file tree
Hide file tree
Showing 17 changed files with 111 additions and 252 deletions.
15 changes: 12 additions & 3 deletions .travis.yml
@@ -1,4 +1,13 @@
language: ruby
rvm:
- "2.1.0"
script: bundle exec rake -f Rakefile.travis
before_install:
- curl http://download.opensuse.org/repositories/YaST:/Head:/Travis/xUbuntu_12.04/Release.key | sudo apt-key add -
- echo "deb http://download.opensuse.org/repositories/YaST:/Head:/Travis/xUbuntu_12.04/ ./" | sudo tee -a /etc/apt/sources.list
- sudo apt-get update -q
- sudo apt-get install --no-install-recommends -y yast2 yast2-slp yast2-add-on
# disable rvm, use system Ruby
- rvm reset
- sudo gem install bundler
script:
- yardoc
- bundle exec rake -f Rakefile.travis
- sudo rake install
5 changes: 4 additions & 1 deletion Gemfile
@@ -1,9 +1,12 @@
source "https://rubygems.org"

gem "suse-connect", :github => "SUSE/connect"
# TODO FIXME: use a correct branch here...
gem "suse-connect", :github => "SUSE/connect", :branch => "v0.2.14"

group :test do
gem "rake"
gem "yard"
gem "yast-rake"
gem "rspec", "~> 2.14.0"
gem "simplecov", :require => false
gem "coveralls", :require => false if ENV["TRAVIS"]
Expand Down
2 changes: 1 addition & 1 deletion Rakefile.travis
Expand Up @@ -7,7 +7,7 @@ ENV["COVERAGE"] = "1"

desc "Run tests"
RSpec::Core::RakeTask.new("test") do |t|
t.pattern = "test/**/*_spec.rb"
t.pattern = "test/**/*_{spec,test}.rb"
end

task :default => :test
Expand Down
1 change: 0 additions & 1 deletion test/addon_selection_dialog_test.rb
Expand Up @@ -6,7 +6,6 @@

before(:each) do
# generic UI stubs for the wizard dialog
stub_const("Yast::UI", double())
allow(Yast::UI).to receive(:WizardCommand)
allow(Yast::UI).to receive(:WidgetExists).and_return(true)
allow(Yast::UI).to receive(:ChangeWidget)
Expand Down
30 changes: 12 additions & 18 deletions test/discover_registration_services_test.rb
Expand Up @@ -5,25 +5,19 @@
require "yast"

describe "discover_registration_services client" do
let(:ui) { double("Yast::UI") }
let(:slpservice) { double("Yast::SlpService") }

before do
# generic UI stubs for the progress dialog
stub_const("Yast::UI", ui)
stub_const("Yast::SlpService", slpservice)

allow(ui).to receive(:GetDisplayInfo).and_return({})
allow(ui).to receive(:BusyCursor)
allow(ui).to receive(:NormalCursor)
allow(ui).to receive(:OpenDialog)
allow(ui).to receive(:CloseDialog)
allow(Yast::UI).to receive(:GetDisplayInfo).and_return({})
allow(Yast::UI).to receive(:BusyCursor)
allow(Yast::UI).to receive(:NormalCursor)
allow(Yast::UI).to receive(:OpenDialog)
allow(Yast::UI).to receive(:CloseDialog)
end

context "when no SLP server is annnounced" do
it "returns nil and does not ask the user" do
expect(slpservice).to receive(:all).and_return([])
expect(ui).to receive(:UserInput).never
expect(Yast::SlpService).to receive(:all).and_return([])
expect(Yast::UI).to receive(:UserInput).never
expect(Yast::WFM.call("discover_registration_services")).to be_nil
end
end
Expand All @@ -39,22 +33,22 @@
allow(slp_attributes).to receive(:to_h).and_return({:description => "Description"})
allow(slp_service).to receive(:attributes).and_return(slp_attributes)
allow(slp_service).to receive(:slp_url).and_return("service:registration.suse:smt:#{slp_url}")
allow(slpservice).to receive(:all).and_return([slp_service])
allow(Yast::SlpService).to receive(:all).and_return([slp_service])
end

it "returns the SLP server selected by user" do
# stub the user interaction in the SLP server selection dialog
expect(ui).to receive(:UserInput).and_return(:ok)
expect(Yast::UI).to receive(:UserInput).and_return(:ok)
# the first radio button is selected
expect(ui).to receive(:QueryWidget).and_return("0")
expect(Yast::UI).to receive(:QueryWidget).and_return("0")

expect(Yast::WFM.call("discover_registration_services")).to eq(slp_url)
end

it "returns nil when the SLP dialog is canceled" do
# stub the user interaction in the SLP server selection dialog
expect(ui).to receive(:UserInput).and_return(:ok)
expect(ui).to receive(:QueryWidget).and_return("scc")
expect(Yast::UI).to receive(:UserInput).and_return(:ok)
expect(Yast::UI).to receive(:QueryWidget).and_return("scc")

expect(Yast::WFM.call("discover_registration_services")).to be_nil
end
Expand Down
7 changes: 1 addition & 6 deletions test/downloader_spec.rb
@@ -1,15 +1,10 @@
#! /usr/bin/env rspec

require_relative "spec_helper"
require_relative "yast_stubs"
require "registration/downloader"
require 'tmpdir'

describe "Registration::Downloader" do
before do
stub_yast_require
require "registration/downloader"
end

let(:url) { "http://example.com" }

describe ".download" do
Expand Down
8 changes: 1 addition & 7 deletions test/eula_downloader_spec.rb
@@ -1,16 +1,10 @@
#! /usr/bin/env rspec

require_relative "spec_helper"
require_relative "yast_stubs"
require "registration/eula_downloader"
require 'tmpdir'

describe "Registration::EulaDownloader" do

before do
stub_yast_require
require "registration/eula_downloader"
end

describe ".download" do
it "downloads the license with translations" do
en_eula = "English EULA"
Expand Down
2 changes: 1 addition & 1 deletion test/finish_dialog_test.rb
Expand Up @@ -20,7 +20,7 @@

describe "first parameter \"Write\"" do
before(:each) do
stub_const("Yast::Installation", double(:destdir => "/mnt"))
allow(Yast::Installation).to receive(:destdir).and_return("/mnt")
end

after(:each) do
Expand Down
67 changes: 22 additions & 45 deletions test/helpers_spec.rb
@@ -1,17 +1,9 @@
#! /usr/bin/env rspec

require_relative "spec_helper"
require_relative "yast_stubs"
require "registration/helpers"

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

before do
stub_yast_require
require "registration/helpers"
stub_const("Yast::WFM", yast_wfm)
end

describe ".service_description" do
let(:slp_url) { "https://example.com/registration" }
let(:slp_attributes) { double }
Expand Down Expand Up @@ -49,62 +41,47 @@
end

describe ".insecure_registration" do
let(:yast_mode) { double("Yast::Mode") }
let(:yast_linuxrc) { double("Yast::Linuxrc") }

before do
stub_const("Yast::Mode", yast_mode)
stub_const("Yast::Linuxrc", yast_linuxrc)
end

context "outside installation/update" do
before do
allow(yast_mode).to receive(:installation).and_return(false)
allow(yast_mode).to receive(:update).and_return(false)
allow(Yast::Mode).to receive(:installation).and_return(false)
allow(Yast::Mode).to receive(:update).and_return(false)
end

it "returns false and does not check boot parameters" do
expect(yast_linuxrc).to receive(:InstallInf).never
expect(Yast::Linuxrc).to receive(:InstallInf).never
expect(Registration::Helpers.insecure_registration).to eq(false)
end
end

context "at installation" do
before do
allow(yast_mode).to receive(:installation).and_return(true)
allow(yast_mode).to receive(:update).and_return(false)
allow(Yast::Mode).to receive(:installation).and_return(true)
allow(Yast::Mode).to receive(:update).and_return(false)
end

it "returns false when reg_ssl_verify option is not used at boot commandline" do
expect(yast_linuxrc).to receive(:InstallInf).with("reg_ssl_verify").
expect(Yast::Linuxrc).to receive(:InstallInf).with("reg_ssl_verify").
and_return(nil)
expect(Registration::Helpers.insecure_registration).to eq(false)
end

it "returns false when reg_ssl_verify=1 boot option is used" do
expect(yast_linuxrc).to receive(:InstallInf).with("reg_ssl_verify").
expect(Yast::Linuxrc).to receive(:InstallInf).with("reg_ssl_verify").
and_return("1")
expect(Registration::Helpers.insecure_registration).to eq(false)
end

it "returns true when reg_ssl_verify=0 boot option is used" do
expect(yast_linuxrc).to receive(:InstallInf).with("reg_ssl_verify").
expect(Yast::Linuxrc).to receive(:InstallInf).with("reg_ssl_verify").
and_return("0")
expect(Registration::Helpers.insecure_registration).to eq(true)
end
end
end

describe ".copy_certificate_to_target" do
let(:yast_scr) { double("Yast::SCR") }
let(:yast_installation) { double("Yast::Installation") }
let(:cert_file) { SUSE::Connect::SSLCertificate::SERVER_CERT_FILE }

before do
stub_const("Yast::SCR", yast_scr)
stub_const("Yast::Installation", yast_installation)
end

it "does nothing when no SSL certificate has been imported" do
expect(File).to receive(:exist?).with(cert_file).and_return(false)
expect(FileUtils).to receive(:cp).never
Expand All @@ -114,10 +91,10 @@

it "copies the certificate and updates all certificate links" do
expect(File).to receive(:exist?).with(cert_file).and_return(true)
expect(yast_installation).to receive(:destdir).and_return("/mnt")
expect(Yast::Installation).to receive(:destdir).and_return("/mnt")
expect(FileUtils).to receive(:mkdir_p).with("/mnt" + File.dirname(cert_file))
expect(FileUtils).to receive(:cp).with(cert_file, "/mnt" + cert_file)
expect(yast_scr).to receive(:Execute).with(Yast::Path.new(".target.bash"),
expect(Yast::SCR).to receive(:Execute).with(Yast::Path.new(".target.bash"),
SUSE::Connect::SSLCertificate::UPDATE_CERTIFICATES)

expect {Registration::Helpers.copy_certificate_to_target}.to_not raise_error
Expand Down Expand Up @@ -153,28 +130,28 @@

describe ".http_language" do
it "returns the current Yast language" do
expect(yast_wfm).to receive(:GetLanguage).and_return("en")
expect(Registration::Helpers.http_language).to eq("en")
expect(Yast::WFM).to receive(:GetLanguage).and_return("en")
expect(Registration::Helpers.language).to eq("en")
end

it "removes encoding suffix" do
expect(yast_wfm).to receive(:GetLanguage).and_return("en.UTF-8")
expect(Registration::Helpers.http_language).to eq("en")
expect(Yast::WFM).to receive(:GetLanguage).and_return("en.UTF-8")
expect(Registration::Helpers.language).to eq("en")
end

it "replaces _ separator by -" do
expect(yast_wfm).to receive(:GetLanguage).and_return("en_US.UTF-8")
expect(Registration::Helpers.http_language).to eq("en-US")
expect(Yast::WFM).to receive(:GetLanguage).and_return("en_US.UTF-8")
expect(Registration::Helpers.language).to eq("en-US")
end

it "returns nil for C locale" do
expect(yast_wfm).to receive(:GetLanguage).and_return("C")
expect(Registration::Helpers.http_language).to eq(nil)
expect(Yast::WFM).to receive(:GetLanguage).and_return("C")
expect(Registration::Helpers.language).to eq(nil)
end

it "returns nil for POSIX locale" do
expect(yast_wfm).to receive(:GetLanguage).and_return("POSIX")
expect(Registration::Helpers.http_language).to eq(nil)
expect(Yast::WFM).to receive(:GetLanguage).and_return("POSIX")
expect(Registration::Helpers.language).to eq(nil)
end
end

Expand All @@ -196,7 +173,7 @@

describe ".run_network_configuration" do
it "runs 'inst_lan' Yast client" do
expect(yast_wfm).to receive(:call).with("inst_lan", anything)
expect(Yast::WFM).to receive(:call).with("inst_lan", anything)

Registration::Helpers.run_network_configuration
end
Expand Down
22 changes: 8 additions & 14 deletions test/local_server_dialog_test.rb
@@ -1,46 +1,40 @@
#! /usr/bin/env rspec

require_relative "spec_helper"
require "yast"

require "registration/ui/local_server_dialog"


describe Registration::UI::LocalServerDialog do
let(:ui) { double("Yast::UI") }
let(:url) { "https://example.com/register" }

before do
# generic UI stubs for the dialog
stub_const("Yast::UI", ui)

expect(ui).to receive(:OpenDialog)
expect(ui).to receive(:CloseDialog)
allow(ui).to receive(:SetFocus)
expect(Yast::UI).to receive(:OpenDialog)
expect(Yast::UI).to receive(:CloseDialog)
allow(Yast::UI).to receive(:SetFocus)
end

it "returns the URL entered by user" do
# stub the user interaction in the dialog
expect(ui).to receive(:UserInput).and_return(:ok)
expect(Yast::UI).to receive(:UserInput).and_return(:ok)
# the input field contains the URL
expect(ui).to receive(:QueryWidget).twice.and_return(url)
expect(Yast::UI).to receive(:QueryWidget).twice.and_return(url)

expect(Registration::UI::LocalServerDialog.run("")).to eq(url)
end

it "returns nil when the dialog is canceled" do
# stub the user interaction in the dialog
expect(ui).to receive(:UserInput).and_return(:cancel)
expect(Yast::UI).to receive(:UserInput).and_return(:cancel)

expect(Registration::UI::LocalServerDialog.run("")).to be_nil
end

it "reports error when URL is not valid" do
# stub the user interaction in the dialog:
# cancel the dialog after displaying an error for invalid URL
expect(ui).to receive(:UserInput).and_return(:ok, :cancel)
expect(Yast::UI).to receive(:UserInput).and_return(:ok, :cancel)
# the input field contains invalid URL
expect(ui).to receive(:QueryWidget).and_return("foobar")
expect(Yast::UI).to receive(:QueryWidget).and_return("foobar")

expect(Yast::Report).to receive(:Error)
expect(Registration::UI::LocalServerDialog.run(url)).to be_nil
Expand Down
8 changes: 2 additions & 6 deletions test/registration_spec.rb
@@ -1,18 +1,14 @@
#! /usr/bin/env rspec

require_relative "spec_helper"
require_relative "yast_stubs"
require "registration/registration"
require "yaml"

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

before do
stub_yast_require
require "registration/registration"

stub_const("Yast::WFM", yast_wfm)
allow(yast_wfm).to receive(:GetLanguage).and_return("en")
allow(Yast::WFM).to receive(:GetLanguage).and_return("en")
allow(Registration::Helpers).to receive(:insecure_registration).and_return(false)
end

Expand Down
7 changes: 1 addition & 6 deletions test/smt_status_spec.rb
@@ -1,14 +1,9 @@
#! /usr/bin/env rspec

require_relative "spec_helper"
require_relative "yast_stubs"
require "registration/smt_status"

describe "Registration::SmtStatus" do
before do
stub_yast_require
require "registration/smt_status"
end

let(:url) { "https://example.com" }
subject { Registration::SmtStatus.new(url) }

Expand Down

0 comments on commit 1fa7e48

Please sign in to comment.