File: site_spec.rb

package info (click to toggle)
puppet-agent 7.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 19,092 kB
  • sloc: ruby: 245,074; sh: 456; makefile: 38; xml: 33
file content (96 lines) | stat: -rw-r--r-- 2,489 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
require 'spec_helper'

require 'puppet/http'

describe Puppet::HTTP::Site do
  let(:scheme)      { 'https' }
  let(:host)        { 'rubygems.org' }
  let(:port)        { 443 }

  def create_site(scheme, host, port)
    described_class.new(scheme, host, port)
  end

  it 'accepts scheme, host, and port' do
    site = create_site(scheme, host, port)

    expect(site.scheme).to eq(scheme)
    expect(site.host).to eq(host)
    expect(site.port).to eq(port)
  end

  it 'generates an external URI string' do
    site = create_site(scheme, host, port)

    expect(site.addr).to eq("https://rubygems.org:443")
  end

  it 'considers sites to be different when the scheme is different' do
    https_site = create_site('https', host, port)
    http_site = create_site('http', host, port)

    expect(https_site).to_not eq(http_site)
  end

  it 'considers sites to be different when the host is different' do
    rubygems_site = create_site(scheme, 'rubygems.org', port)
    github_site = create_site(scheme, 'github.com', port)

    expect(rubygems_site).to_not eq(github_site)
  end

  it 'considers sites to be different when the port is different' do
    site_443 = create_site(scheme, host, 443)
    site_80 = create_site(scheme, host, 80)

    expect(site_443).to_not eq(site_80)
  end

  it 'compares values when determining equality' do
    site = create_site(scheme, host, port)

    sites = {}
    sites[site] = site

    another_site = create_site(scheme, host, port)

    expect(sites.include?(another_site)).to be_truthy
  end

  it 'computes the same hash code for equivalent objects' do
    site = create_site(scheme, host, port)
    same_site = create_site(scheme, host, port)

    expect(site.hash).to eq(same_site.hash)
  end

  it 'uses ssl with https' do
    site = create_site('https', host, port)

    expect(site).to be_use_ssl
  end

  it 'does not use ssl with http' do
    site = create_site('http', host, port)

    expect(site).to_not be_use_ssl
  end

  it 'moves to a new URI location' do
    site = create_site('http', 'host1', 80)

    uri = URI.parse('https://host2:443/some/where/else')
    new_site = site.move_to(uri)

    expect(new_site.scheme).to eq('https')
    expect(new_site.host).to eq('host2')
    expect(new_site.port).to eq(443)
  end

  it 'creates a site from a URI' do
    site = create_site('https', 'rubygems.org', 443)
    uri = URI.parse('https://rubygems.org/gems/puppet/')

    expect(described_class.from_uri(uri)).to eq(site)
  end
end