Skip to content

Commit

Permalink
minor tweaks to fix test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
chorankates-sfdc committed Aug 25, 2016
1 parent f529436 commit 7b08faf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion lib/rouster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ def os_type
end
end

@logger.error(sprintf('unable to determine OS, looking for[%s]', files)) if res.nil?
@logger.error(sprintf('unable to determine OS, looking for[%s]', files)) if res.eql?(:invalid)

@ostype = res
res
Expand Down
46 changes: 24 additions & 22 deletions test/functional/deltas/test_get_os.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@

class TestValidateFileFunctional < Test::Unit::TestCase

# TODO this should probably be further abstracted into the implementation, but this is fine for now
FLAG_FILES = {
:ubuntu => '/etc/os-release', # debian too
:solaris => '/etc/release',
:redhat => '/etc/redhat-release', # centos too
:osx => '/System/Library/CoreServices/SystemVersion.plist',
}

def setup
# expose private methods
Rouster.send(:public, *Rouster.private_instance_methods)
Expand All @@ -15,11 +23,21 @@ def setup
@app = Rouster.new(:name => 'app')
end

def teardown; end # NOOP
def teardown
# put the flag file back in place
FLAG_FILES.each_pair do |_os, ff|
bkup = sprintf('%s.bkup', ff)
if @app.is_file?(bkup)
@app.run(sprintf('mv %s %s', bkup, ff))
end
end
end

def test_happy_path

assert_not_nil(@app.os_type, sprintf('unable to determine vm[%s] OS', @app))
type = @app.os_type
assert_not_nil(type, sprintf('unable to determine vm[%s] OS', @app))
assert_not_equal(:invalid, type)

assert_nothing_raised do
@app.get_services
Expand All @@ -29,38 +47,22 @@ def test_happy_path

def test_unhappy_path
# move the flag file out of the way
# TODO should we move these out to constants? probably
flag_files = {
:ubuntu => '/etc/os-release', # debian too
:solaris => '/etc/release',
:redhat => '/etc/redhat-release', # centos too
:osx => '/System/Library/CoreServices/SystemVersion.plist',
}

# TODO need to assert that .run() is called
flag_files.each_pair do |_os, ff|
FLAG_FILES.each_pair do |_os, ff|
if @app.is_file?(ff)
@app.run(sprintf('mv %s %s.bkup', ff, ff))
end
end

assert_equal(:invalid, @app.os_type, sprintf('got wrong value for unmarked OS[%s]', @app.os_type))
type = @app.os_type

assert_equal(:invalid, type, sprintf('got wrong value for unmarked OS[%s]', type))

e = assert_raise do
@app.get_services
end

assert_equal(Rouster::InternalError, e.class, sprintf('wrong exception raised[%s] [%s]', e.class, e.message))

# TODO need to asser that .run() is called
# put the flag file back in place
flag_files.each_pair do |_os, ff|
bkup = sprintf('%s.bkup', ff)
if @app.is_file?(bkup)
@app.run(sprintf('mv %s %s', bkup, ff))
end
end

end

end

0 comments on commit 7b08faf

Please sign in to comment.