Browse Source

Add DNS tests, first tests for the Assrertions module

master
Christian Aust 1 week ago
parent
commit
f19753692f
7 changed files with 57 additions and 1 deletions
  1. +1
    -0
      Gemfile
  2. +8
    -0
      Gemfile.lock
  3. +1
    -0
      lib/sanity.rb
  4. +5
    -0
      lib/sanity/assertions.rb
  5. +25
    -0
      lib/sanity/tests/dns.rb
  6. +14
    -1
      spec/sanity/assertions_spec.rb
  7. +3
    -0
      spec/sanity/tests/dns_spec.rb

+ 1
- 0
Gemfile View File

@ -5,6 +5,7 @@ source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem 'ssl-test'
gem 'dnsruby'
group :development do
gem 'rake', '~> 12.0'

+ 8
- 0
Gemfile.lock View File

@ -2,6 +2,8 @@ GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.4.4)
dnsruby (1.61.4)
simpleidn (~> 0.1)
docile (1.3.2)
rake (12.3.3)
rspec (3.9.0)
@ -21,12 +23,18 @@ GEM
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov-html (0.12.3)
simpleidn (0.1.1)
unf (~> 0.1.4)
ssl-test (1.3.1)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.7)
PLATFORMS
ruby
DEPENDENCIES
dnsruby
rake (~> 12.0)
rspec (~> 3.0)
simplecov

+ 1
- 0
lib/sanity.rb View File

@ -9,6 +9,7 @@ module Sanity
autoload :Suite, 'sanity/suite'
module Tests
autoload :DNS, 'sanity/tests/dns'
autoload :StaticWeb, 'sanity/tests/static_web'
autoload :SSL, 'sanity/tests/ssl'
end

+ 5
- 0
lib/sanity/assertions.rb View File

@ -6,6 +6,11 @@ module Sanity
@assertion_count ||= 0
end
def assert_any?(enum, msg=nil, &block)
fail "No block given" unless block_given?
assert enum.any?(block), (msg || "Expected any of #{enum} to return true")
end
def assert_equals(a, b, msg=nil)
assert(a==b, (msg || "Expected #{a} to equal #{b}"))
end

+ 25
- 0
lib/sanity/tests/dns.rb View File

@ -0,0 +1,25 @@
require 'dnsruby'
module Sanity::Tests
class DNS
include Sanity::Assertions
attr_reader :target
def initialize(target)
@target = target
end
def to_s
"DNS for #{target}"
end
def test_if_resolvable
resolver = Dnsruby::Resolver.new
result = resolver.query(@target, 'A', 'IN')
assert_any?(result.answer, "Expected #{target} to resolve to an A result") do |rr|
rr.type == 'A' && !rr.rdata.nil?
end
end
end
end

+ 14
- 1
spec/sanity/assertions_spec.rb View File

@ -1,3 +1,16 @@
RSpec.describe Sanity::Assertions do
pending
let(:dummy_class) { Class.new { include Sanity::Assertions } }
subject{ dummy_class.new }
describe '#assertion_count' do
it "is defined" do
expect(subject).to respond_to(:assertion_count)
end
end
describe '#assertion_count=' do
it "sets value" do
expect{subject.assertion_count = 1}.to change{subject.assertion_count}.from(0).to(1)
end
end
end

+ 3
- 0
spec/sanity/tests/dns_spec.rb View File

@ -0,0 +1,3 @@
RSpec.describe Sanity::Tests::DNS do
pending
end

Loading…
Cancel
Save