Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Moravec committed Dec 13, 2013
1 parent 2741887 commit 2f2be06
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 33 deletions.
54 changes: 23 additions & 31 deletions src/lib/online-update-configuration/zypp_config.rb
@@ -1,43 +1,35 @@
module ZyppConfiguration
class ZyppConfig
SCR_TARGET = '.etc.zypp_conf'
CONFIG_USE_DELTA_RPM = "#{SCR_TARGET}.value.main.\"download.use_deltarpm\""

def zypp_config
@config ||= ZyppConfig.new
def initialize
current_config = get_delta_rpm_config_value
# Default config for delta rpms in zypp.conf is true
@use_delta_rpm = current_config == nil || current_config == 'true'
end

class ZyppConfig
def initialize
current_config = delta_rpm_config_value
# Default settings in zypp.conf for using delta rpms is true
@use_delta_rpm = current_config == nil || current_config == 'true'
end

def use_delta_rpm?
@use_delta_rpm
end
def use_delta_rpm?
@use_delta_rpm
end

def activate_delta_rpm
Yast::Builtins.y2milestone("Activating delta rpms for online update..")
set_config_value(true)
end
def activate_delta_rpm
Yast::Builtins.y2milestone("Activating delta rpms for online update..")
set_delta_rpm_config_value(true)
end

def deactivate_delta_rpm
Yast::Builtins.y2milestone("Deactivating delta rpms for online update..")
set_config_value(false)
end
def deactivate_delta_rpm
Yast::Builtins.y2milestone("Deactivating delta rpms for online update..")
set_delta_rpm_config_value(false)
end

private
private

def set_config_value new_value
return if new_value == use_delta_rpm?
Yast::SCR.Write(Yast::Path.new(CONFIG_USE_DELTA_RPM), new_value)
end
def set_delta_rpm_config_value new_value
return if new_value == use_delta_rpm?
Yast::SCR.Write(Yast::Path.new(CONFIG_USE_DELTA_RPM), new_value)
end

def delta_rpm_config_value
Yast::Builtins.y2milestone("Reading zypp configuration for deltarpms")
Yast::SCR.Read(Yast::Path.new(CONFIG_USE_DELTA_RPM))
end
def get_delta_rpm_config_value
Yast::SCR.Read(Yast::Path.new(CONFIG_USE_DELTA_RPM))
end
end

4 changes: 2 additions & 2 deletions src/modules/OnlineUpdateConfiguration.rb
Expand Up @@ -32,7 +32,7 @@

module Yast
class OnlineUpdateConfigurationClass < Module
include ZyppConfiguration
attr_reader :zypp_config

def main
Yast.import "Pkg"
Expand All @@ -42,7 +42,7 @@ def main

textdomain "online-update-configuration"


@zypp_config = ZyppConfig.new

@enableAOU = false
@skipInteractivePatches = true
Expand Down
6 changes: 6 additions & 0 deletions test/test_helper.rb
@@ -0,0 +1,6 @@
require 'rspec'

ENV["Y2DIR"] = File.expand_path("../../src", __FILE__)

require 'yast'
require 'online-update-configuration/zypp_config'
33 changes: 33 additions & 0 deletions test/zypp_config_test.rb
@@ -0,0 +1,33 @@
#!/usr/bin/env rspec

require_relative 'test_helper'

describe ZyppConfig do
attr_reader :config

it "provides config value for delta rpms if explicitly activated" do
ZyppConfig.any_instance.stub(:get_delta_rpm_config_value).and_return('true')
expect(ZyppConfig.new.use_delta_rpm?).to eq(true)
end

it "provides config value for delta rpms if using default settings" do
ZyppConfig.any_instance.stub(:get_delta_rpm_config_value).and_return(nil)
expect(ZyppConfig.new.use_delta_rpm?).to eq(true)
end

it "provides config value for delta rpms if explicitly deactivated" do
ZyppConfig.any_instance.stub(:get_delta_rpm_config_value).and_return('false')
expect(ZyppConfig.new.use_delta_rpm?).to eq(false)
end

it "can activate and deactivate use of delta rpms in zypp config" do
ZyppConfig.any_instance.stub(:get_delta_rpm_config_value)
ZyppConfig.any_instance.stub(:set_delta_rpm_config_value)
config = ZyppConfig.new
expect(config).to receive(:set_delta_rpm_config_value).with(true)
expect(config.activate_delta_rpm)

expect(config).to receive(:set_delta_rpm_config_value).with(false)
expect(config.deactivate_delta_rpm)
end
end

0 comments on commit 2f2be06

Please sign in to comment.