Skip to content

Commit

Permalink
Merge 40bd3e3 into a89e197
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Apr 22, 2015
2 parents a89e197 + 40bd3e3 commit 3875391
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/lib/migration/main_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
require "yast"

Yast.import "Mode"
Yast.import "Sequencer"
Yast.import "Pkg"
Yast.import "Sequencer"
Yast.import "Update"

module Migration
# The goal of the class is to provide main single entry point to start
Expand All @@ -44,7 +45,10 @@ def run
private

WORKFLOW_SEQUENCE = {
"ws_start" => "repositories", # TODO: store state before run
"ws_start" => "create_backup",
"create_backup" => {
next: "repositories"
},
"repositories" => {
abort: "restore",
next: "proposals"
Expand All @@ -63,16 +67,32 @@ def run

def aliases
{
"create_backup" => ->() { create_backup },
"restore" => ->() { restore_state },
"repositories" => ->() { repositories },
"perform_update" => ->() { perform_update },
"proposals" => ->() { proposals },
"perform_update" => ->() { perform_update }
"repositories" => ->() { repositories }
}
end

def create_backup
Yast::Update.clean_backup
Yast::Update.create_backup(
"repos",
[
"/etc/zypp/repos.d/*",
"/etc/zypp/credentials",
"/etc/zypp/services.d/*"
]
)

:next
end

def restore_state
# TODO: restore after canceling operation
raise "Restoring state is not implemented yet"
Yast::Update.restore_backup

:abort
end

def repositories
Expand Down
25 changes: 25 additions & 0 deletions test/main_workflow_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@
# current contact information at www.suse.com.
# ------------------------------------------------------------------------------

# fake Update class to avoid loading all Update dependencies
module Yast
class UpdateClass
# we need at least one non-default methods, otherwise ruby-bindings thinks
# it is just namespace
def fake_method
end
end
Update = UpdateClass.new
end

require_relative "test_helper"

require "migration/main_workflow"
Expand All @@ -34,6 +45,10 @@ def mock_client(name, res)
mock_client("inst_prepareprogress", :next)
mock_client("inst_kickoff", :next)
mock_client("inst_rpmcopy", :next)

allow(Yast::Update).to receive(:clean_backup)
allow(Yast::Update).to receive(:create_backup)
allow(Yast::Update).to receive(:restore_backup)
end

it "pass workflow sequence to Yast sequencer" do
Expand All @@ -50,5 +65,15 @@ def mock_client(name, res)
expect(Yast::Pkg).to receive(:SourceLoad)
::Migration::MainWorkflow.run
end

it "restores repositories when clicking on Cancel" do
expect(Yast::Update).to receive(:clean_backup)
expect(Yast::Update).to receive(:create_backup)
expect(Yast::Update).to receive(:restore_backup)

mock_client("migration_proposals", :abort)

expect(::Migration::MainWorkflow.run).to eq :abort
end
end
end

0 comments on commit 3875391

Please sign in to comment.