Permalink
Browse files

restructure tests a bit

added hostgroups + tests
  • Loading branch information...
ohadlevy committed Jun 13, 2011
1 parent 9a7cab5 commit 47b992cb8d41324da94896e470a17a206924308d
View
@@ -18,3 +18,7 @@
puts host.reports
puts host.lastreport
+
+
+hg = Foreman::Hostgroups.new(opts).list
+puts hg.first
View
@@ -13,5 +13,7 @@ module Foreman
autoload :Fact, "foreman/resource/fact"
autoload :Reports, "foreman/resource/reports"
autoload :Report, "foreman/resource/report"
+ autoload :Hostgroup, "foreman/resource/hostgroup"
+ autoload :Hostgroups, "foreman/resource/hostgroups"
end
@@ -0,0 +1,30 @@
+module Foreman
+ class Hostgroup
+
+ attr_reader :name, :id
+
+ def initialize opts = {}
+ opts.each do |k,v|
+ eval("@#{k} = v") if self.respond_to?(k)
+ end
+
+ {:name => name, :id => id}.each do |k,v|
+ raise("Must provide a #{k}") if v.nil?
+ end
+
+ end
+
+ def path
+ "/hostgroups/#{id}"
+ end
+
+ def to_s
+ name
+ end
+
+ def hosts
+ Hosts.new(opts).list("hostgroup = #{name}")
+ end
+
+ end
+end
@@ -0,0 +1,9 @@
+module Foreman
+ class Hostgroups < Collection
+
+ def list(filter = "")
+ super(filter).map {|hg| Hostgroup.new(hg["hostgroup"])}
+ end
+
+ end
+end
View
@@ -1,7 +1,5 @@
-class Foreman::ResourceTest < Test::Unit::TestCase
+class Foreman::CollectionTest < Test::Unit::TestCase
def setup
- opts = {:url => "http://0.0.0.0:3000", :user => "admin", :password => "changeme"}
-
@resource = Foreman::Collection.new(opts)
end
View
@@ -0,0 +1,21 @@
+class Foreman::HostGroupTest < Test::Unit::TestCase
+ def setup
+ @hostgroup = Foreman::Hostgroup.new(:name => "test", :id => 1)
+ @attr = [:name, :id]
+ end
+
+ def test_should_have_attributes
+ @attr.each do |o|
+ assert_not_nil @hostgroup.send(o)
+ end
+ end
+
+ def test_should_have_a_name
+ assert_equal @hostgroup.name, "test"
+ end
+
+ def test_should_have_list_of_hosts
+ assert Foreman::Hostgroups.new(opts).list.first.hosts.first.is_a? Foreman::Host
+ end
+
+end
View
@@ -0,0 +1,14 @@
+class Foreman::HostGroupsTest < Test::Unit::TestCase
+ def setup
+ @resource = Foreman::Hostgroups.new(opts)
+ end
+
+ def test_path
+ assert_equal @resource.send(:path), "hostgroups"
+ end
+
+ def test_list_should_create_hostgroup_objects
+ assert @resource.list.first.is_a?(Foreman::Hostgroup)
+ end
+
+end
View
@@ -1,7 +1,5 @@
class Foreman::ResourceTest < Test::Unit::TestCase
def setup
- opts = {:url => "http://0.0.0.0:3000", :user => "admin", :password => "changeme"}
-
@resource = Foreman::Resource.new(opts)
end
View
@@ -1,3 +1,7 @@
require "test/unit"
$LOAD_PATH.unshift *Dir["#{File.dirname(__FILE__)}/../lib"]
require "foreman"
+
+def opts
+ opts = {:url => "http://0.0.0.0:3000", :user => "admin", :password => "changeme"}
+end

0 comments on commit 47b992c

Please sign in to comment.