Sha256: ec0852a2705a78f96e1d48f5a6cded931681cc583c7fbfe0622a3ff51a3bbdc7

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 KB

Contents

#! /usr/bin/env ruby
# coding: utf-8

require "helper"

class Comana::HostSelector
  attr_reader :groups_hosts
end

class TC_HostSelector < Test::Unit::TestCase
  def setup
    groups_hosts = {
      "GroupA" => ["A00", "A01"],
      "GroupB" => ["B00", "B01", "B02"]
    }
    @hs00 = Comana::HostSelector.new(groups_hosts)

    groups_hosts = {
      "GroupNil" => nil,
      "GroupA" => ["A00", "A01"],
      "GroupB" => ["B00", "B01", "B02"]
    }
    @hs01 = Comana::HostSelector.new(groups_hosts)
  end

  def test_load_file
    hs = Comana::HostSelector.load_file("example/dot.clustersetting")
    assert_equal(Comana::HostSelector, hs.class)
    #pp hs
    #assert_equal(["A00", "A01", "B00", "B01", "B02"], hs.select_all)
    assert_equal({"A"=>["A00", "A01"], "B"=>["B00", "B01", "B02"]}, hs.groups_hosts)
  end

  def test_select_all
    #it 'should return all hosts' do
    assert_equal(["A00", "A01", "B00", "B01", "B02"], @hs00.select_all)

    #it 'should return all hosts without nil' do
    assert_equal(["A00", "A01", "B00", "B01", "B02"], @hs01.select_all)
  end

  def test_select_group
    #it 'should return hosts in GroupA' do
    assert_equal(["A00", "A01"], @hs00.select_group("GroupA"))

    #it 'should raise Comana::HostSelector::NoEntryError' do
    assert_raise(Comana::HostSelector::NoEntryError){
      @hs00.select_group("GroupNil")
    }
  end

  def test_groups
    #it 'should return all groups' do
    assert_equal(["GroupA", "GroupB"], @hs00.groups)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
comana-0.1.0 test/test_hostselector.rb
comana-0.0.10 test/test_hostselector.rb