2010-05-04 15:48:59 +00:00
|
|
|
require 'apache/config'
|
2010-05-07 17:56:49 +00:00
|
|
|
require 'fileutils'
|
2010-05-04 15:48:59 +00:00
|
|
|
|
2010-05-07 15:26:40 +00:00
|
|
|
describe Apache::Config, "builds configurations" do
|
|
|
|
let(:apache) { Apache::Config }
|
|
|
|
|
|
|
|
before { apache.reset! }
|
|
|
|
|
|
|
|
def set_apache_env(env)
|
|
|
|
Object.send(:remove_const, :APACHE_ENV) if Object.const_defined? :APACHE_ENV
|
|
|
|
Object.send(:const_set, :APACHE_ENV, env)
|
2010-05-04 15:48:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should handle indent" do
|
2010-05-07 15:26:40 +00:00
|
|
|
apache.line_indent = 1
|
2010-05-04 15:48:59 +00:00
|
|
|
|
2010-05-07 15:26:40 +00:00
|
|
|
[
|
|
|
|
[ 'hello', ' hello' ],
|
|
|
|
[ [ 'hello', 'goodbye' ], [ ' hello', ' goodbye' ] ]
|
|
|
|
].each do |input, output|
|
|
|
|
apache.indent(input).should == output
|
|
|
|
end
|
2010-05-04 15:48:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should add a line to the config" do
|
2010-05-07 15:26:40 +00:00
|
|
|
apache << "hello"
|
|
|
|
apache.to_a.should == [ 'hello' ]
|
|
|
|
|
|
|
|
apache + [ 'goodbye' ]
|
|
|
|
apache.to_a.should == [ 'hello', 'goodbye' ]
|
2010-05-04 15:48:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should handle method_missing" do
|
2010-05-07 15:26:40 +00:00
|
|
|
apache.test "test2", "test3"
|
|
|
|
apache.test_again! "test2", "test3"
|
2010-05-04 15:48:59 +00:00
|
|
|
|
2010-05-07 15:26:40 +00:00
|
|
|
apache.to_a.should == [
|
2010-05-04 15:48:59 +00:00
|
|
|
'Test "test2" "test3"',
|
|
|
|
'TestAgain test2 test3'
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should Apachify the name" do
|
2010-05-07 15:26:40 +00:00
|
|
|
[
|
|
|
|
%w{test Test},
|
|
|
|
%w{test_full_name TestFullName},
|
|
|
|
%w{ssl_option SSLOption},
|
|
|
|
%w{exec_cgi ExecCGI},
|
|
|
|
%w{authz_ldap_authoritative AuthzLDAPAuthoritative},
|
|
|
|
%w{authz_ldap_url AuthzLDAPURL},
|
|
|
|
[ ["name", "other_name"], [ 'Name', 'OtherName' ] ]
|
|
|
|
].each do |input, output|
|
|
|
|
apache.apachify(input).should == output
|
|
|
|
end
|
2010-05-04 15:48:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should quoteize properly" do
|
2010-05-07 15:26:40 +00:00
|
|
|
apache.quoteize("test", "test2").should == %w{"test" "test2"}
|
|
|
|
apache.quoteize(:test, :test2).should == %w{test test2}
|
2010-05-04 15:48:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should blockify a block" do
|
2010-05-07 15:26:40 +00:00
|
|
|
apache.blockify("Tag", [ 'part', 'part2' ]) do
|
2010-05-04 15:48:59 +00:00
|
|
|
something "goes here"
|
2010-05-06 14:40:45 +00:00
|
|
|
end.should == ['', '<Tag "part" "part2">', ' Something "goes here"', '</Tag>', '']
|
2010-05-07 15:26:40 +00:00
|
|
|
end
|
2010-05-04 15:51:06 +00:00
|
|
|
|
2010-05-07 15:26:40 +00:00
|
|
|
it "should blockify the name of a block" do
|
|
|
|
[
|
|
|
|
[ 'part', '"part"' ],
|
|
|
|
[ :part, 'part' ],
|
|
|
|
[ [ 'part', 'part2' ], '"part" "part2"' ]
|
|
|
|
].each do |name, attribute|
|
|
|
|
apache.blockify_name(name).should == attribute
|
|
|
|
end
|
2010-05-04 15:48:59 +00:00
|
|
|
end
|
2010-05-04 21:04:44 +00:00
|
|
|
|
|
|
|
it "should handle a build" do
|
2010-05-07 17:56:49 +00:00
|
|
|
FileUtils.mkdir_p 'test'
|
|
|
|
apache.build('test/fake.conf') { my_test "this" }.should == [ 'MyTest "this"' ]
|
|
|
|
FileUtils.rm 'test/fake.conf'
|
2010-05-07 15:26:40 +00:00
|
|
|
end
|
2010-05-04 21:04:44 +00:00
|
|
|
|
2010-05-07 15:26:40 +00:00
|
|
|
it "should handle building if the environment is correct" do
|
|
|
|
set_apache_env(:test)
|
|
|
|
|
|
|
|
apache.build_if(nil, :other) { my_test 'this' }.should == nil
|
|
|
|
apache.build_if(nil, :test) { my_test 'this' }.should == [ 'MyTest "this"' ]
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should only execute a block if the environment is correct" do
|
|
|
|
set_apache_env(:test)
|
|
|
|
|
|
|
|
test = 0
|
|
|
|
apache.if_environment(:other) { test = 1 }
|
|
|
|
test.should == 0
|
|
|
|
|
|
|
|
test = 0
|
|
|
|
apache.if_environment(:test) { test = 1 }
|
|
|
|
test.should == 1
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should create an IfModule block" do
|
|
|
|
apache.if_module("test") { my_test }
|
|
|
|
apache.to_a.should == [ '', '<IfModule test_module>', ' MyTest', '</IfModule>', '' ]
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should create a Directory block" do
|
|
|
|
dir = File.dirname(__FILE__)
|
|
|
|
|
|
|
|
apache.directory(dir) { my_test }
|
|
|
|
apache.to_a.should == [ '', %{<Directory "#{dir}">}, ' MyTest', '</Directory>', '' ]
|
|
|
|
|
|
|
|
apache.reset!
|
|
|
|
|
|
|
|
apache.directory('/does/not/exist') { my_test }
|
|
|
|
apache.to_a.should == [ '', %{<Directory "/does/not/exist">}, ' MyTest', '</Directory>', '' ]
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should create a LocationMatch block" do
|
|
|
|
apache.location_match(%r{^/$}) { my_test }
|
|
|
|
apache.to_a.should == [ '', '<LocationMatch "^/$">', ' MyTest', '</LocationMatch>', '' ]
|
2010-05-04 21:04:44 +00:00
|
|
|
end
|
2010-05-04 15:48:59 +00:00
|
|
|
end
|