Skip to content

Commit 025c830

Browse files
committed
Added new test cases
1 parent d66f9cd commit 025c830

File tree

7 files changed

+120
-23
lines changed

7 files changed

+120
-23
lines changed

ip2proxy_ruby.gemspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ Gem::Specification.new do |s|
3131
"lib/ip2proxy_ruby/i2p_string_data.rb",
3232
"lib/ip2proxy_ruby/ip2proxy_config.rb",
3333
"lib/ip2proxy_ruby/ip2proxy_record.rb",
34-
"spec/assets/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN",
35-
"spec/ip2proxy_ruby_spec.rb",
34+
"spec/assets/PX10.SAMPLE.BIN",
35+
"spec/ip2proxy_ruby_database_spec.rb",
3636
"spec/spec_helper.rb",
37-
"rb/data/IP2PROXY-LITE-PX1.BIN"
37+
"rb/data/PX10.SAMPLE.BIN"
3838
]
3939

4040
if s.respond_to?(:metadata=)

rb/data/IP2PROXY-LITE-PX1.BIN

-86.6 MB
Binary file not shown.

rb/data/PX10.SAMPLE.BIN

1 MB
Binary file not shown.
Binary file not shown.

spec/assets/PX10.SAMPLE.BIN

1 MB
Binary file not shown.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2+
3+
describe "Ip2proxy" do
4+
it "work correctly with invalid ip" do
5+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX10.SAMPLE.BIN")
6+
record = i2p.get_all('1.0.0.x')
7+
expect(record['country_short']).to eq 'INVALID IP ADDRESS'
8+
end
9+
10+
it "work correctly with get_all ipv4" do
11+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX10.SAMPLE.BIN")
12+
record = i2p.get_all('1.0.0.8')
13+
expect(record['country_short']).to eq 'US'
14+
end
15+
16+
it "work correctly with get_country_short" do
17+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX10.SAMPLE.BIN")
18+
record = i2p.get_country_short('1.0.0.8')
19+
expect(record).to eq 'US'
20+
end
21+
22+
it "work correctly with get_country_long" do
23+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX10.SAMPLE.BIN")
24+
record = i2p.get_country_long('1.0.0.8')
25+
expect(record).to eq 'United States of America'
26+
end
27+
28+
it "work correctly with get_region" do
29+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX10.SAMPLE.BIN")
30+
record = i2p.get_region('1.0.0.8')
31+
expect(record).to eq 'California'
32+
end
33+
34+
it "work correctly with get_city" do
35+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX10.SAMPLE.BIN")
36+
record = i2p.get_city('1.0.0.8')
37+
expect(record).to eq 'Los Angeles'
38+
end
39+
40+
it "work correctly with get_isp" do
41+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX10.SAMPLE.BIN")
42+
record = i2p.get_isp('1.0.0.8')
43+
expect(record).to eq 'APNIC and CloudFlare DNS Resolver Project'
44+
end
45+
46+
it "work correctly with get_domain" do
47+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX10.SAMPLE.BIN")
48+
record = i2p.get_domain('1.0.0.8')
49+
expect(record).to eq 'cloudflare.com'
50+
end
51+
52+
it "work correctly with get_usagetype" do
53+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX10.SAMPLE.BIN")
54+
record = i2p.get_usagetype('1.0.0.8')
55+
expect(record).to eq 'CDN'
56+
end
57+
58+
it "work correctly with get_asn" do
59+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX10.SAMPLE.BIN")
60+
record = i2p.get_asn('1.0.0.8')
61+
expect(record).to eq '13335'
62+
end
63+
64+
it "work correctly with get_as" do
65+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX10.SAMPLE.BIN")
66+
record = i2p.get_as('1.0.0.8')
67+
expect(record).to eq 'CLOUDFLARENET'
68+
end
69+
70+
it "work correctly with get_last_seen" do
71+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX10.SAMPLE.BIN")
72+
record = i2p.get_last_seen('1.0.0.8')
73+
expect(record).to eq '22'
74+
end
75+
76+
it "work correctly with get_threat" do
77+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX10.SAMPLE.BIN")
78+
record = i2p.get_threat('1.0.0.8')
79+
expect(record).to eq '-'
80+
end
81+
82+
it "work correctly with is_proxy" do
83+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX10.SAMPLE.BIN")
84+
record = i2p.is_proxy('1.0.0.8')
85+
expect(record).to eq 2
86+
end
87+
88+
it "work correctly with get_proxytype" do
89+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX10.SAMPLE.BIN")
90+
record = i2p.get_proxytype('1.0.0.8')
91+
expect(record).to eq 'DCH'
92+
end
93+
94+
it "work correctly with get_all ipv6" do
95+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX10.SAMPLE.BIN")
96+
record = i2p.get_all('2c0f:ffa0::4')
97+
expect(record['country_short']).to eq 'UG'
98+
end
99+
100+
it "work correctly with get_module_version" do
101+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX10.SAMPLE.BIN")
102+
record = i2p.get_module_version()
103+
expect(record).to eq '3.0.1'
104+
end
105+
106+
it "work correctly with get_package_version" do
107+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX10.SAMPLE.BIN")
108+
record = i2p.get_package_version()
109+
expect(record).to eq '10'
110+
end
111+
112+
it "work correctly with get_database_version" do
113+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX10.SAMPLE.BIN")
114+
record = i2p.get_database_version()
115+
expect(record).to eq '2020.10.23'
116+
end
117+
end

spec/ip2proxy_ruby_spec.rb

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)