Sha256: 4744d3d7e45ee208d4d5a514d1e1f006448e928517e9b77632f83d76fdfc9213

Contents?: true

Size: 1.61 KB

Versions: 3

Compression:

Stored size: 1.61 KB

Contents

require 'spec_helper'

describe Celluloid::IO::DNSResolver do
  describe '#resolve' do
    it 'resolves hostnames statically from hosts file without nameservers' do
      # /etc/resolv.conf doesn't exist on Mac OSX when no networking is
      # disabled, thus .nameservers would return nil
      expect(Celluloid::IO::DNSResolver).to receive(:nameservers).at_most(:once) { nil }
      resolver = Celluloid::IO::DNSResolver.new
      expect(resolver.resolve('localhost')).to eq Resolv::IPv4.create("127.0.0.1")
    end

    it 'resolves hostnames' do
      resolver = Celluloid::IO::DNSResolver.new
      expect(resolver.resolve('localhost')).to eq Resolv::IPv4.create("127.0.0.1")
    end

    it "resolves domain names" do
      resolver    = Celluloid::IO::DNSResolver.new
      nameservers = resolver.resolve("celluloid.io")
      expect(nameservers).to include Resolv::IPv4.create("104.28.21.100")
      expect(nameservers).to include Resolv::IPv4.create("104.28.20.100")
    end

    it "resolves CNAME responses" do
      resolver = Celluloid::IO::DNSResolver.new
      results = resolver.resolve("www.google.com")
      if results.is_a?(Array)
        results.all? {|i| expect(i).to be_an_instance_of(Resolv::IPv4) }
      else
        expect(results).to be_an_instance_of(Resolv::IPv4)
      end
      # www.yahoo.com will be resolved randomly whether multiple or
      # single entry.
      results = resolver.resolve("www.yahoo.com")
      if results.is_a?(Array)
        results.all? {|i| expect(i).to be_an_instance_of(Resolv::IPv4) }
      else
        expect(results).to be_an_instance_of(Resolv::IPv4)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
celluloid-io-0.17.1 spec/celluloid/io/dns_resolver_spec.rb
celluloid-io-0.17.0 spec/celluloid/io/dns_resolver_spec.rb
celluloid-io-0.16.5.pre0 spec/celluloid/io/dns_resolver_spec.rb