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
|
require 'spec_helper'
require 'puppet/node/environment'
require 'puppet/network/http'
require 'matchers/json'
describe Puppet::Network::HTTP::API::V2::Environments do
include JSONMatchers
it "responds with all of the available environments" do
environment = Puppet::Node::Environment.create(:production, ["/first", "/second"], '/manifests')
loader = Puppet::Environments::Static.new(environment)
handler = Puppet::Network::HTTP::API::V2::Environments.new(loader)
response = Puppet::Network::HTTP::MemoryResponse.new
handler.call(Puppet::Network::HTTP::Request.from_hash(:headers => { 'accept' => 'application/json' }), response)
expect(response.code).to eq(200)
expect(response.type).to eq("application/json")
expect(JSON.parse(response.body)).to eq({
"search_paths" => loader.search_paths,
"environments" => {
"production" => {
"settings" => {
"modulepath" => [File.expand_path("/first"), File.expand_path("/second")],
"manifest" => File.expand_path("/manifests"),
"environment_timeout" => 0,
"config_version" => ""
}
}
}
})
end
it "the response conforms to the environments schema for unlimited timeout" do
conf_stub = stub 'conf_stub'
conf_stub.expects(:environment_timeout).returns(1.0 / 0.0)
environment = Puppet::Node::Environment.create(:production, [])
env_loader = Puppet::Environments::Static.new(environment)
env_loader.expects(:get_conf).with(:production).returns(conf_stub)
handler = Puppet::Network::HTTP::API::V2::Environments.new(env_loader)
response = Puppet::Network::HTTP::MemoryResponse.new
handler.call(Puppet::Network::HTTP::Request.from_hash(:headers => { 'accept' => 'application/json' }), response)
expect(response.body).to validate_against('api/schemas/environments.json')
end
it "the response conforms to the environments schema for integer timeout" do
conf_stub = stub 'conf_stub'
conf_stub.expects(:environment_timeout).returns(1)
environment = Puppet::Node::Environment.create(:production, [])
env_loader = Puppet::Environments::Static.new(environment)
env_loader.expects(:get_conf).with(:production).returns(conf_stub)
handler = Puppet::Network::HTTP::API::V2::Environments.new(env_loader)
response = Puppet::Network::HTTP::MemoryResponse.new
handler.call(Puppet::Network::HTTP::Request.from_hash(:headers => { 'accept' => 'application/json' }), response)
expect(response.body).to validate_against('api/schemas/environments.json')
end
end
|