Use symbols for container states

This commit is contained in:
Andre Nathan 2014-01-14 09:24:00 -02:00
parent 3ff240462e
commit 9a65ddf036
3 changed files with 18 additions and 15 deletions

View file

@ -369,18 +369,18 @@ container_running_p(VALUE self)
* call-seq:
* container.state
*
* Returns the state of the container.
* Returns a symbol representing the state of the container.
*/
static VALUE
container_state(VALUE self)
{
const char *state;
struct container_data *data;
VALUE rb_state;
Data_Get_Struct(self, struct container_data, data);
state = data->container->state(data->container);
rb_state = rb_str_new2(data->container->state(data->container));
return rb_str_new2(state);
return rb_str_intern(rb_funcall(rb_state, rb_intern("downcase"), 0));
}
/*
@ -1614,11 +1614,14 @@ container_wait(int argc, VALUE *argv, VALUE self)
int ret, timeout;
char *state;
struct container_data *data;
VALUE rb_state, rb_timeout;
VALUE rb_state_str, rb_state, rb_timeout;
rb_scan_args(argc, argv, "11", &rb_state, &rb_timeout);
state = StringValuePtr(rb_state);
rb_state_str = rb_funcall(rb_state, rb_intern("to_s"), 0);
rb_state_str = rb_funcall(rb_state_str, rb_intern("upcase"), 0);
state = StringValuePtr(rb_state_str);
timeout = NIL_P(rb_timeout) ? -1 : NUM2INT(rb_timeout);
Data_Get_Struct(self, struct container_data, data);

View file

@ -19,15 +19,15 @@ class TestLXCRunning < Test::Unit::TestCase
@container.shutdown(3)
if @container.running?
@container.stop
@container.wait('STOPPED', 3)
@container.wait(:stopped, 3)
end
end
def test_container_running
@container.wait('RUNNING', 3)
@container.wait(:running, 3)
assert(@container.init_pid > 1)
assert(@container.running?)
assert_equal('RUNNING', @container.state)
assert_equal(:running, @container.state)
end
def test_container_interfaces
@ -72,23 +72,23 @@ class TestLXCRunning < Test::Unit::TestCase
def test_container_freeze
@container.freeze
@container.wait('FROZEN', 3)
@container.wait(:frozen, 3)
assert(@container.init_pid > 1)
assert(@container.running?)
assert_equal('FROZEN', @container.state)
assert_equal(:frozen, @container.state)
@container.unfreeze
@container.wait('RUNNING', 3)
@container.wait(:running, 3)
assert(@container.init_pid > 1)
assert(@container.running?)
assert_equal('RUNNING', @container.state)
assert_equal(:running, @container.state)
end
def test_container_clone
teardown
assert_nil(@container.init_pid)
assert(!@container.running?)
assert_equal('STOPPED', @container.state)
assert_equal(:stopped, @container.state)
assert_nothing_raised do
begin

View file

@ -28,6 +28,6 @@ class TestLXCUndefined < Test::Unit::TestCase
end
def test_container_stopped
assert_equal('STOPPED', @container.state)
assert_equal(:stopped, @container.state)
end
end