Skip to content

Commit

Permalink
Converted ip_test from Minitest into RSpec
Browse files Browse the repository at this point in the history
The test is temporarily disabled. It can be enabled once rspec.rpm gets
it into Factory.
  • Loading branch information
mchf committed Sep 24, 2013
1 parent ad78e80 commit 6b32dac
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 93 deletions.
2 changes: 1 addition & 1 deletion library/types/test/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TESTS = ip_test.rb ipv4_netmask_test.rb
TESTS = ipv4_netmask_test.rb
TEST_EXTENSIONS = .rb
RB_LOG_COMPILER = ruby
VERBOSE = 1
Expand Down
180 changes: 88 additions & 92 deletions library/types/test/ip_test.rb
Original file line number Diff line number Diff line change
@@ -1,61 +1,62 @@
#! /usr/bin/env ruby
#! /usr/bin/env rspec --format=doc

ENV["Y2DIR"] = File.expand_path("../../src", __FILE__)

require "minitest/autorun"
require "yast"

Yast.import "IP"
include Yast

describe Yast::IP do
before do
@object = Yast::IPClass.new
@object.main
describe "Yast::IP" do
before( :all) do
Yast.import "IP"
end

describe "when asked for validation string for IPv4" do
it "must return translated text" do
@object.Valid4.must_match /^A valid/
describe "#Valid4" do
it "must return valid IPv4 description" do
expect( IP.Valid4).not_to be_empty
end
end

describe "when told to check IPv4" do
valid_ip4s = [
describe "#Check4" do
VALID_IP4S = [
"0.0.0.0",
"127.0.0.1",
"255.255.255.255",
"10.11.12.13",
]
valid_ip4s.each do |valid_ip4|
it "return true for valid IPv4 '#{valid_ip4}'" do
@object.Check4(valid_ip4).must_equal true

VALID_IP4S.each do |valid_ip4|
it "returns true for valid IPv4 '#{valid_ip4}'" do
expect( IP.Check4(valid_ip4)).to be_true
end
end

invalid_ip4s = [
INVALID_IP4S = [
"0.0.0",
"127.0.0.1.1",
"256.255.255.255",
"01.01.012.013",
"10,11.12.13",
]
invalid_ip4s.each do |invalid_ip4|
it "return false for invalid IPv4 '#{invalid_ip4}'" do
@object.Check4(invalid_ip4).must_equal false

INVALID_IP4S.each do |invalid_ip4|
it "returns false for invalid IPv4 '#{invalid_ip4}'" do
expect( IP.Check4(invalid_ip4)).to be_false
end
end

it "return false for empty argument" do
@object.Check4("").must_equal false
it "returns false for empty argument" do
expect( IP.Check4("")).to be_false
end

it "return false for nil argument" do
@object.Check4(nil).must_equal false
it "returns false for nil argument" do
expect( IP.Check4(nil)).to be_false
end
end

describe "when told to check IPv6" do

valid_ip6s = [
describe "#Check6" do
VALID_IP6S = [
"1:2:3:4:5:6:7:8",
"::3:4:5:6:7:8",
"1:2:3:4:5:6::",
Expand All @@ -71,13 +72,14 @@
"1:2:3:4:5:6:127.0.0.1",
"1:2:3::6:127.0.0.1",
]
valid_ip6s.each do |valid_ip6|
it "return true for valid IPv6 '#{valid_ip6}'" do
@object.Check6(valid_ip6).must_equal true

VALID_IP6S.each do |valid_ip6|
it "returns true for valid IPv6 '#{valid_ip6}'" do
expect( IP.Check6(valid_ip6)).to be_true
end
end

invalid_ip6s = [
INVALID_IP6S = [
"1::3:4:5:6::8",
"1:2:3:4:5:6:7:8:9",
"1:2:3:4::5:6:7:8:9",
Expand All @@ -91,104 +93,98 @@
#FIXME deprecated syntax, so we should handle it invalid "::FFFF:127.0.0.1",
#FIXME insufficient regex for ipv4 included in ipv6 "1:2:3:4:5:6:127.0.0.256"
]
invalid_ip6s.each do |invalid_ip6|
it "return false for invalid IPv6 '#{invalid_ip6}" do
@object.Check6(invalid_ip6).must_equal false

INVALID_IP6S.each do |invalid_ip6|
it "returns false for invalid IPv6 '#{invalid_ip6}" do
expect( IP.Check6(invalid_ip6)).to be_false
end
end

it "return false for empty argument" do
@object.Check6("").must_equal false
it "returns false for empty argument" do
expect( IP.Check6("")).to be_false
end

it "return false for nil argument" do
@object.Check6(nil).must_equal false
it "returns false for nil argument" do
expect( IP.Check6(nil)).to be_false
end
end

describe "when told to compute integer value" do
it "return value for valid ipv4" do
result_map = {
"0.0.0.0" => 0,
"127.0.0.1" => 2130706433,
"192.168.110.23" => 3232263703,
"10.20.1.29" => 169083165
}
result_map.each_pair do |k,v|
@object.ToInteger(k).must_equal v
describe "#ToInteger" do
RESULT_MAP_INT = {
"0.0.0.0" => 0,
"127.0.0.1" => 2130706433,
"192.168.110.23" => 3232263703,
"10.20.1.29" => 169083165
}

RESULT_MAP_INT.each_pair do |k,v|
it "returns #{v} for #{k}" do
expect( IP.ToInteger(k)).to be_equal v
end
end

it "return nil if value is not valid ipv4" do
@object.ToInteger("blabla").must_equal nil
it "returns nil if value is not valid IPv4 in dotted format" do
expect( IP.ToInteger("foobar")).to be_equal nil
end
end

describe "when told to create ipv4 string from integer" do
it "it return ipv4" do
result_map = {
"0.0.0.0" => 0,
"127.0.0.1" => 2130706433,
"192.168.110.23" => 3232263703,
"10.20.1.29" => 169083165
}
result_map.each_pair do |k,v|
@object.ToString(v).must_equal k
describe "#ToString" do
RESULT_MAP_INT.each_pair do |k,v|
it "it returns #{k} for #{v}" do
expect( IP.ToString(v)) == k
end
end
end

describe "when told to create string with hex value of ipv4 string" do
it "return value for valid ipv4" do
result_map = {
"0.0.0.0" => "00000000",
"10.10.0.1" => "0A0A0001",
"192.168.1.1" => "C0A80101",
"255.255.255.255" => "FFFFFFFF"
}
result_map.each_pair do |k,v|
@object.ToHex(k).must_equal v
describe "#ToHex" do
RESULT_MAP_HEX = {
"0.0.0.0" => "00000000",
"10.10.0.1" => "0A0A0001",
"192.168.1.1" => "C0A80101",
"255.255.255.255" => "FFFFFFFF"
}

RESULT_MAP_HEX.each_pair do |k,v|
it "returns #{v} for valid #{k}" do
expect( IP.ToHex(k)) == v
end
end

it "return nil if value is not valid ipv4" do
@object.ToHex("blabla").must_equal nil
it "returns nil if value is not valid IPv4 in dotted format" do
expect( IP.ToHex("foobar")).to be_equal nil
end
end

describe "when told to convert IPv4 address into bits" do
it "return value for proper ipv4" do
result_map = {
"80.25.135.2" => "01010000000110011000011100000010",
"172.24.233.211" => "10101100000110001110100111010011"
}
result_map.each_pair do |k,v|
@object.IPv4ToBits(k).must_equal v
RESULT_MAP_BITS = {
"80.25.135.2" => "01010000000110011000011100000010",
"172.24.233.211" => "10101100000110001110100111010011"
}

describe "#IPv4ToBits" do
RESULT_MAP_BITS.each_pair do |k,v|
it "returns bitmap for #{k}" do
expect( IP.IPv4ToBits(k)) == v
end
end

it "return nil if value is not valid ipv4" do
@object.IPv4ToBits("blabla").must_equal nil
it "returns nil if value is not valid IPv4" do
expect( IP.IPv4ToBits("blabla")).to be_equal nil
end
end

describe "when told to convert bits to IPv4 address" do
it "return value for string" do
result_map = {
"80.25.135.2" => "01010000000110011000011100000010",
"172.24.233.211" => "10101100000110001110100111010011"
}
result_map.each_pair do |k,v|
@object.BitsToIPv4(v).must_equal k
describe "#BitsToIPv4" do
RESULT_MAP_BITS.each_pair do |k,v|
it "returns #{k} for #{v}" do
expect( IP.BitsToIPv4(v)) == k
end
end

it "return nil if size of string is not 32" do
@object.BitsToIPv4("101").must_equal nil
it "returns nil if length of bitmap is not 32" do
expect( IP.BitsToIPv4("101")).to be_equal nil
end

it "return nil if value is not valid string with 0 or 1" do
@object.BitsToIPv4("blabla").must_equal nil
it "returns nil if value is not valid bitmap with 0 or 1 only" do
expect( IP.BitsToIPv4("foobar")).to be_equal nil
end
end
end

0 comments on commit 6b32dac

Please sign in to comment.