Skip to content

Commit

Permalink
Add helper method for variable name and value check
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Moravec committed Aug 23, 2013
1 parent ea3f479 commit f45d2df
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions test/read_test.rb
Expand Up @@ -23,6 +23,7 @@
var_value = get_value(var_name)
var_value.wont_be_empty
get_config_metadata(var_name,:postfix)['Type'].must_match /#{var_value}/
config_file_contains?(var_name, var_value).must_equal true
end
end
end
8 changes: 7 additions & 1 deletion test/test_helper.rb
Expand Up @@ -25,7 +25,7 @@ module TestHelpers

attr_reader :sysconfig, :context

FILES_DIR = Pathname.new(File.join 'files')
FILES_DIR = Pathname.new(File.expand_path( '../files', __FILE__))
TMP_DIR = Pathname.new(File.expand_path('../tmp', __FILE__))

# If needed extend this map as required
Expand Down Expand Up @@ -63,6 +63,12 @@ def get_value config_variable
get_config_value(config_variable, self.context)
end

# Check the written config file for the new value without using the
# yast built-in mechanizm
def config_file_contains?(variable, value=nil)
!(File.readlines(sample_path).grep(/^\s*#{variable}\s*=.*#{value}/).empty?)
end

# Proxy to sysconfig.set_value to make it shorter
def set_value variable_name, variable_value
sysconfig.set_value(get_sysconfig_varid(variable_name), variable_value, false, false)
Expand Down
10 changes: 8 additions & 2 deletions test/write_test.rb
Expand Up @@ -10,16 +10,19 @@
it "should save the changed postfix variable value" do
load_sample :postfix do
var_name = "POSTFIX_MYHOSTNAME"
original_value = get_value(var_name)
new_value = "suse.cz"
sysconfig.Read
original_value = get_value(var_name)
set_value(var_name, new_value)
sysconfig.Modified.must_equal true
modified_var?(var_name).wont_equal false
sysconfig.Summary.must_match(/#{var_name}.*#{new_value}/)
sysconfig.stub(:StartCommand, :success) { sysconfig.Write.must_equal true }
config_file_contains?(var_name, new_value).must_equal true
sysconfig.Read
get_value(var_name).must_equal(new_value)
changed_var_value = get_value(var_name)
changed_var_value.must_equal(new_value)
changed_var_value.wont_equal(original_value)
end
end

Expand All @@ -32,6 +35,7 @@
set_value(var_name, new_value)
sysconfig.Modified.must_equal false
sysconfig.stub(:StartCommand, :success) { sysconfig.Write.must_equal true }
config_file_contains?(var_name, new_value).must_equal false
sysconfig.Read
get_value(var_name).must_equal(original_value)
end
Expand All @@ -47,6 +51,7 @@
set_value(var_name, new_value)
sysconfig.Modified.must_equal false
sysconfig.stub(:StartCommand, :success) { sysconfig.Write.must_equal true }
config_file_contains?(var_name, new_value).must_equal false
sysconfig.Read
get_value(var_name).must_be_empty
end
Expand All @@ -63,6 +68,7 @@
modified_var?(variable_name).wont_equal false
sysconfig.Summary.must_match(/#{variable_name}.*#{new_value}/)
sysconfig.stub(:StartCommand, :success) { sysconfig.Write.must_equal true }
config_file_contains?(variable_name, new_value).must_equal true
sysconfig.Read
get_value(variable_name).must_equal(new_value)
end
Expand Down

0 comments on commit f45d2df

Please sign in to comment.