m2config 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/lib/m2config/schema.sql +5 -4
- data/lib/m2config/server.rb +3 -0
- data/lib/m2config/version.rb +1 -1
- data/spec/dir_spec.rb +4 -4
- data/spec/handler_spec.rb +5 -5
- data/spec/host_spec.rb +9 -9
- data/spec/m2config_spec.rb +5 -5
- data/spec/mimetype_spec.rb +5 -4
- data/spec/proxy_spec.rb +3 -3
- data/spec/route_spec.rb +14 -14
- data/spec/server_spec.rb +12 -11
- data/spec/setting_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afd22b0a55c4bab36dab2e2b4513ece7ee7d8298
|
4
|
+
data.tar.gz: 91c4d8efc772ee183fedacc2539f4b8052126435
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7446db6384946fc6e03ac1b8c8dabc5e9adb42ac21ea864b60d1aaf3601563a08b40f735a21e6acef3180d9f4956b8d368a84eafd04c07a9814b3b4aac296ca9
|
7
|
+
data.tar.gz: b29931e593e44eaa2af9fe3e94a1db86878475aff8d2249a8ebcd9983b07ba4343569068b161e47d4f2efe3dc9b48e6cb23fd60958a155746033ce3be40a8450
|
data/Gemfile
CHANGED
data/lib/m2config/schema.sql
CHANGED
@@ -30,14 +30,15 @@ CREATE TABLE route (id INTEGER PRIMARY KEY,
|
|
30
30
|
target_type TEXT);
|
31
31
|
CREATE TABLE server (id INTEGER PRIMARY KEY,
|
32
32
|
uuid TEXT,
|
33
|
-
default_host TEXT,
|
34
|
-
bind_addr TEXT DEFAULT "0.0.0.0",
|
35
|
-
port INTEGER,
|
36
|
-
chroot TEXT DEFAULT '/var/www',
|
37
33
|
access_log TEXT,
|
38
34
|
error_log TEXT,
|
35
|
+
chroot TEXT DEFAULT '/var/www',
|
39
36
|
pid_file TEXT,
|
40
37
|
control_port TEXT DEFAULT "",
|
38
|
+
default_host TEXT,
|
39
|
+
name TEXT DEFAULT '',
|
40
|
+
bind_addr TEXT DEFAULT "0.0.0.0",
|
41
|
+
port INTEGER,
|
41
42
|
use_ssl INTEGER default 0);
|
42
43
|
CREATE TABLE setting (id INTEGER PRIMARY KEY, key TEXT, value TEXT);
|
43
44
|
CREATE TABLE statistic (id SERIAL,
|
data/lib/m2config/server.rb
CHANGED
@@ -6,6 +6,7 @@ module M2Config
|
|
6
6
|
CONTROL_PORT = ''
|
7
7
|
CHROOT = './'
|
8
8
|
DEFAULT_HOST = 'localhost'
|
9
|
+
NAME = 'main'
|
9
10
|
BIND_ADDR = '0.0.0.0'
|
10
11
|
PORT = 6767
|
11
12
|
USE_SSL = 0
|
@@ -19,9 +20,11 @@ module M2Config
|
|
19
20
|
fields[:pid_file] ||= PID_FILE
|
20
21
|
fields[:chroot] ||= CHROOT
|
21
22
|
fields[:default_host] ||= DEFAULT_HOST
|
23
|
+
fields[:name] ||= NAME
|
22
24
|
fields[:bind_addr] ||= BIND_ADDR
|
23
25
|
fields[:port] ||= PORT
|
24
26
|
fields[:use_ssl] ||= USE_SSL
|
27
|
+
fields[:control_port] ||= CONTROL_PORT
|
25
28
|
super fields, false
|
26
29
|
save
|
27
30
|
end
|
data/lib/m2config/version.rb
CHANGED
data/spec/dir_spec.rb
CHANGED
@@ -5,17 +5,17 @@ describe M2Config::Dir do
|
|
5
5
|
describe "::new" do
|
6
6
|
it "needs to know the base path to handle" do
|
7
7
|
M2Config::Dir.new({base:"images/"})
|
8
|
-
CFG.db[:directory].first[:base].
|
8
|
+
expect(CFG.db[:directory].first[:base]).to eq("images/")
|
9
9
|
end
|
10
10
|
|
11
11
|
it "defaults to application/octet-stream for the default content type" do
|
12
12
|
M2Config::Dir.new({base:"images/"})
|
13
|
-
CFG.db[:directory].first[:default_ctype].
|
13
|
+
expect(CFG.db[:directory].first[:default_ctype]).to eq("application/octet-stream")
|
14
14
|
end
|
15
15
|
|
16
16
|
it "defaults to index.html for the index file" do
|
17
17
|
dir = M2Config::Dir.new({base:"/"})
|
18
|
-
CFG.db[:directory].first[:index_file].
|
18
|
+
expect(CFG.db[:directory].first[:index_file]).to eq("index.html")
|
19
19
|
end
|
20
20
|
|
21
21
|
describe "helps you spot common mistakes" do
|
@@ -40,7 +40,7 @@ describe M2Config::Dir do
|
|
40
40
|
|
41
41
|
describe '#type' do
|
42
42
|
it 'returns its type' do
|
43
|
-
M2Config::Dir.new({base:"/"}).type.
|
43
|
+
expect(M2Config::Dir.new({base:"/"}).type).to eq("dir")
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
data/spec/handler_spec.rb
CHANGED
@@ -9,9 +9,9 @@ describe M2Config::Handler do
|
|
9
9
|
recv_spec:"tcp://10.0.0.1:9898",
|
10
10
|
send_ident: "dev.example.com ID"})
|
11
11
|
res = CFG.db[:handler].first
|
12
|
-
res[:send_spec].
|
13
|
-
res[:recv_spec].
|
14
|
-
res[:send_ident].
|
12
|
+
expect(res[:send_spec]).to eq("tcp://10.0.0.1:8989")
|
13
|
+
expect(res[:recv_spec]).to eq("tcp://10.0.0.1:9898")
|
14
|
+
expect(res[:send_ident]).to eq("dev.example.com ID")
|
15
15
|
end
|
16
16
|
|
17
17
|
it "turns nil into empty string when recv_ident is not set" do
|
@@ -19,7 +19,7 @@ describe M2Config::Handler do
|
|
19
19
|
recv_spec:"tcp://10.0.0.1:9898",
|
20
20
|
send_ident: "dev.example.com ID"})
|
21
21
|
res = CFG.db[:handler].first
|
22
|
-
res[:recv_ident].
|
22
|
+
expect(res[:recv_ident]).to be_empty
|
23
23
|
end
|
24
24
|
|
25
25
|
describe "helps you spot common mistakes" do
|
@@ -34,7 +34,7 @@ describe M2Config::Handler do
|
|
34
34
|
|
35
35
|
describe '#type' do
|
36
36
|
it 'returns its type' do
|
37
|
-
M2Config::Handler.new({send_spec:"tcp://10.0.0.1:8988", recv_spec:"tcp://10.0.0.1:8989", send_ident: "dev.example.com ID"}).type.
|
37
|
+
expect(M2Config::Handler.new({send_spec:"tcp://10.0.0.1:8988", recv_spec:"tcp://10.0.0.1:8989", send_ident: "dev.example.com ID"}).type).to eq("handler")
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
data/spec/host_spec.rb
CHANGED
@@ -9,21 +9,21 @@ describe M2Config::Host do
|
|
9
9
|
it "needs to know the domain name served" do
|
10
10
|
M2Config::Host.new({matching:"example.com", name: "ex"})
|
11
11
|
res = CFG.db[:host].first
|
12
|
-
res[:matching].
|
12
|
+
expect(res[:matching]).to eq("example.com")
|
13
13
|
end
|
14
14
|
|
15
15
|
it "can use the uuid of a server" do
|
16
16
|
host = M2Config::Host.new({matching:"example.com", name: "ex", srvUuid: @srv.uuid})
|
17
17
|
res = CFG.db[:host].where(id: host.id).first
|
18
|
-
res[:server_id].
|
19
|
-
res[:matching].
|
18
|
+
expect(res[:server_id]).to eq(@srv.id)
|
19
|
+
expect(res[:matching]).to eq("example.com")
|
20
20
|
end
|
21
21
|
|
22
22
|
it "can use a server instance" do
|
23
23
|
host = M2Config::Host.new({matching:"example.com", name: "ex", srv: @srv})
|
24
24
|
res = CFG.db[:host].where(id: host.id).first
|
25
|
-
res[:server_id].
|
26
|
-
res[:matching].
|
25
|
+
expect(res[:server_id]).to eq(@srv.id)
|
26
|
+
expect(res[:matching]).to eq("example.com")
|
27
27
|
end
|
28
28
|
|
29
29
|
it "enforces mongrel2 constraint about nil name" do
|
@@ -40,7 +40,7 @@ describe M2Config::Host do
|
|
40
40
|
dirR = M2Config::Route.new({path:"/blog", target: dirH})
|
41
41
|
host.add_route dirR
|
42
42
|
res = CFG.db[:route].first
|
43
|
-
res[:host_id].
|
43
|
+
expect(res[:host_id]).to eq(host.id)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -51,7 +51,7 @@ describe M2Config::Host do
|
|
51
51
|
dir2 = M2Config::Dir.new({base: "images/"})
|
52
52
|
host.add_route M2Config::Route.new({path:"/blog1", target: dir1})
|
53
53
|
host.add_route M2Config::Route.new({path:"/blog1", target: dir2})
|
54
|
-
host.check_routes.
|
54
|
+
expect(host.check_routes).to be_falsey
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'returns true if all routes have different paths' do
|
@@ -62,12 +62,12 @@ describe M2Config::Host do
|
|
62
62
|
r2 = M2Config::Route.new({path:"/images", target: dir2})
|
63
63
|
host.add_route r1
|
64
64
|
host.add_route r2
|
65
|
-
host.check_routes.
|
65
|
+
expect(host.check_routes).to be_truthy
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'withstands the idea of not having any routes' do # , {focus: true}
|
69
69
|
host = M2Config::Host.new({matching:"example.com", name: "ex"})
|
70
|
-
host.check_routes.
|
70
|
+
expect(host.check_routes).to be_truthy
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
data/spec/m2config_spec.rb
CHANGED
@@ -6,12 +6,12 @@ describe M2Config do
|
|
6
6
|
|
7
7
|
describe "::new" do
|
8
8
|
it 'creates a default database when name absent' do
|
9
|
-
File.
|
9
|
+
expect(File).to exist DEFAULT_DB_NAME
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'learns the DB schema from the official schema dump' do
|
13
13
|
for table in TABLES do
|
14
|
-
M2Config::Config.tables.
|
14
|
+
expect(M2Config::Config.tables).to include table
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -22,15 +22,15 @@ describe M2Config do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'populates the MIME table with a nice set of mappings' do
|
25
|
-
M2Config::MimeType[extension:".html"].mimetype.
|
26
|
-
M2Config::MimeType[extension:".css"].mimetype.
|
25
|
+
expect(M2Config::MimeType[extension:".html"].mimetype).to eq("text/html")
|
26
|
+
expect(M2Config::MimeType[extension:".css"].mimetype).to eq("text/css")
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
describe '#[]=' do
|
31
31
|
it 'creates or modifies the value of a setting' do
|
32
32
|
CFG["zeromq.threads"] = 8
|
33
|
-
CFG.db[:setting].where(key:"zeromq.threads").first[:value].
|
33
|
+
expect(CFG.db[:setting].where(key:"zeromq.threads").first[:value]).to eq("8")
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
data/spec/mimetype_spec.rb
CHANGED
@@ -16,7 +16,8 @@ describe M2Config::MimeType do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'allows you to force the redefinition of an existing extension' do
|
19
|
-
|
19
|
+
skip
|
20
|
+
fail
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
@@ -26,7 +27,7 @@ describe M2Config::MimeType do
|
|
26
27
|
CFG.db[:mimetype].delete
|
27
28
|
M2Config::MimeType.populate_table()
|
28
29
|
# M2Config::MimeType.populate_table(nil,ignoreDoubles=true)
|
29
|
-
M2Config::MimeType[extension:'.css'].mimetype.
|
30
|
+
expect(M2Config::MimeType[extension:'.css'].mimetype).to eq('text/css')
|
30
31
|
end
|
31
32
|
|
32
33
|
it 'checks for doubles unless asked not to' do
|
@@ -43,8 +44,8 @@ describe M2Config::MimeType do
|
|
43
44
|
it 'accepts an array of MIME::Types if the whole list is too much' do
|
44
45
|
CFG.db[:mimetype].delete
|
45
46
|
M2Config::MimeType.populate_table [MIME::Type.new(['text/plain', 'zed'])]
|
46
|
-
M2Config::MimeType[extension:'.zed'].mimetype.
|
47
|
-
M2Config::MimeType[extension:'.css'].
|
47
|
+
expect(M2Config::MimeType[extension:'.zed'].mimetype).to eq('text/plain')
|
48
|
+
expect(M2Config::MimeType[extension:'.css']).to eq(nil)
|
48
49
|
end
|
49
50
|
|
50
51
|
it 'frowns when asked to populate a non-empty table' do
|
data/spec/proxy_spec.rb
CHANGED
@@ -8,14 +8,14 @@ describe M2Config::Proxy do
|
|
8
8
|
it "needs an address and a port number" do
|
9
9
|
M2Config::Proxy.new({addr:"legacy.local", port: 8080})
|
10
10
|
res = CFG.db[:proxy].first
|
11
|
-
res[:addr].
|
12
|
-
res[:port].
|
11
|
+
expect(res[:addr]).to eq("legacy.local")
|
12
|
+
expect(res[:port]).to eq(8080)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
describe '#type' do
|
17
17
|
it 'returns its type' do
|
18
|
-
M2Config::Proxy.new({addr:"legacy.local", port: 8080}).type.
|
18
|
+
expect(M2Config::Proxy.new({addr:"legacy.local", port: 8080}).type).to eq("proxy")
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
data/spec/route_spec.rb
CHANGED
@@ -7,9 +7,9 @@ describe M2Config::Route do
|
|
7
7
|
dirH = M2Config::Dir.new({base: "static/"})
|
8
8
|
M2Config::Route.new({path:"/blog", target: dirH})
|
9
9
|
res = CFG.db[:route].first
|
10
|
-
res[:path].
|
11
|
-
res[:target_id].
|
12
|
-
res[:target_type].
|
10
|
+
expect(res[:path]).to eq("/blog")
|
11
|
+
expect(res[:target_id]).to eq(dirH.id)
|
12
|
+
expect(res[:target_type]).to eq(dirH.type)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -22,9 +22,9 @@ describe M2Config::Route do
|
|
22
22
|
r2 = M2Config::Route.new({path:"/king", target: dir2, host: host})
|
23
23
|
r3 = M2Config::Route.new({path:"/king", target: dirH, host: host})
|
24
24
|
M2Config::Route.elect!(r2)
|
25
|
-
host.check_routes.
|
25
|
+
expect(host.check_routes).to be_truthy
|
26
26
|
king = M2Config::Route.where(path: "/king").first
|
27
|
-
king.target.base.
|
27
|
+
expect(king.target.base).to eq("ManceRayder/")
|
28
28
|
end
|
29
29
|
|
30
30
|
it "leaves routes belonging to a different host untouched" do
|
@@ -36,11 +36,11 @@ describe M2Config::Route do
|
|
36
36
|
r2 = M2Config::Route.new({path:"/king", target: dir2, host: host})
|
37
37
|
r3 = M2Config::Route.new({path:"/king", target: dirH, host: host2})
|
38
38
|
M2Config::Route.elect!(r2)
|
39
|
-
host.check_routes.
|
39
|
+
expect(host.check_routes).to be_truthy
|
40
40
|
king = M2Config::Route.where(path: "/king").first
|
41
|
-
king.target.base.
|
41
|
+
expect(king.target.base).to eq("ManceRayder/")
|
42
42
|
onOtherHost = M2Config::Route.where(path:"/king", target_id: dirH.id, host: host2).first
|
43
|
-
onOtherHost.
|
43
|
+
expect(onOtherHost).not_to be_nil
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -51,7 +51,7 @@ describe M2Config::Route do
|
|
51
51
|
r = M2Config::Route.new({path:"/blog", target: dirH})
|
52
52
|
r.host = host.id
|
53
53
|
res = CFG.db[:route].first
|
54
|
-
res[:host_id].
|
54
|
+
expect(res[:host_id]).to eq(host.id)
|
55
55
|
end
|
56
56
|
|
57
57
|
it "can take a Host instance" do
|
@@ -60,7 +60,7 @@ describe M2Config::Route do
|
|
60
60
|
r = M2Config::Route.new({path:"/blog", target: dirH})
|
61
61
|
r.host = host
|
62
62
|
res = CFG.db[:route].first
|
63
|
-
res[:host_id].
|
63
|
+
expect(res[:host_id]).to eq(host.id)
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
@@ -69,7 +69,7 @@ describe M2Config::Route do
|
|
69
69
|
dirH = M2Config::Dir.new({base: "static/"})
|
70
70
|
r = M2Config::Route.new({path:"/blog", target: dirH})
|
71
71
|
r.host = M2Config::Host.new({matching:"example.com", name: "ex"})
|
72
|
-
r.host.matching.
|
72
|
+
expect(r.host.matching).to eq("example.com")
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -80,8 +80,8 @@ describe M2Config::Route do
|
|
80
80
|
newTarget = M2Config::Proxy.new({addr:"127.0.0.1", port: 15970})
|
81
81
|
r.target = newTarget
|
82
82
|
res = CFG.db[:route].first
|
83
|
-
res[:target_id].
|
84
|
-
res[:target_type].
|
83
|
+
expect(res[:target_id]).to eq(newTarget.id)
|
84
|
+
expect(res[:target_type]).to eq(newTarget.type)
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
@@ -89,7 +89,7 @@ describe M2Config::Route do
|
|
89
89
|
it 'returns the Target object' do
|
90
90
|
dirH = M2Config::Dir.new({base: "static/"})
|
91
91
|
r = M2Config::Route.new({path:"/blog", target: dirH})
|
92
|
-
r.target.base.
|
92
|
+
expect(r.target.base).to eq dirH.base
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
data/spec/server_spec.rb
CHANGED
@@ -9,15 +9,16 @@ describe M2Config::Server do
|
|
9
9
|
describe '::new' do
|
10
10
|
it 'creates a server entry with reasonable default settings' do
|
11
11
|
res = CFG.db[:server].first
|
12
|
-
res[:access_log].
|
13
|
-
res[:error_log].
|
14
|
-
res[:pid_file].
|
15
|
-
res[:control_port].
|
16
|
-
res[:chroot].
|
17
|
-
res[:default_host].
|
18
|
-
res[:
|
19
|
-
res[:
|
20
|
-
res[:
|
12
|
+
expect(res[:access_log]).to eq(M2Config::Server::ACCESS_LOG)
|
13
|
+
expect(res[:error_log]).to eq(M2Config::Server::ERROR_LOG)
|
14
|
+
expect(res[:pid_file]).to eq(M2Config::Server::PID_FILE)
|
15
|
+
expect(res[:control_port]).to eq(M2Config::Server::CONTROL_PORT)
|
16
|
+
expect(res[:chroot]).to eq(M2Config::Server::CHROOT)
|
17
|
+
expect(res[:default_host]).to eq(M2Config::Server::DEFAULT_HOST)
|
18
|
+
expect(res[:name]).to eq(M2Config::Server::NAME)
|
19
|
+
expect(res[:bind_addr]).to eq(M2Config::Server::BIND_ADDR)
|
20
|
+
expect(res[:port]).to eq(M2Config::Server::PORT)
|
21
|
+
expect(res[:use_ssl]).to eq(M2Config::Server::USE_SSL)
|
21
22
|
end
|
22
23
|
|
23
24
|
end
|
@@ -25,7 +26,7 @@ describe M2Config::Server do
|
|
25
26
|
describe '::first (from Sequel::Model)' do
|
26
27
|
it 'returns the first server found in the database' do
|
27
28
|
srv = M2Config::Server.first
|
28
|
-
srv.id.
|
29
|
+
expect(srv.id).to eq(@srv.id)
|
29
30
|
end
|
30
31
|
|
31
32
|
it 'raises if there is more than one server' do
|
@@ -38,7 +39,7 @@ describe M2Config::Server do
|
|
38
39
|
it 'accepts an existing Host instance' do
|
39
40
|
@srv.add_host @host
|
40
41
|
res = CFG.db[:host].where(id: @host.id).first
|
41
|
-
res[:server_id].
|
42
|
+
expect(res[:server_id]).to eq(@srv.id)
|
42
43
|
end
|
43
44
|
end
|
44
45
|
end
|
data/spec/setting_spec.rb
CHANGED
@@ -7,14 +7,14 @@ describe M2Config::Setting do
|
|
7
7
|
it "stores the given value under the given key" do
|
8
8
|
M2Config::Setting.new("answer",42)
|
9
9
|
res = CFG.db[:setting].first
|
10
|
-
res[:value].
|
10
|
+
expect(res[:value]).to eq("42")
|
11
11
|
end
|
12
12
|
|
13
13
|
it "updates the existing value if the given key is already present" do
|
14
14
|
M2Config::Setting.new("answer",41)
|
15
15
|
M2Config::Setting.new("answer",42)
|
16
16
|
res = CFG.db[:setting].first
|
17
|
-
res[:value].
|
17
|
+
expect(res[:value]).to eq("42")
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: m2config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arnaud Meuret
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sqlite3
|