mediawiki-testwiki 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/COPYING +663 -0
- data/ChangeLog +11 -0
- data/README +41 -0
- data/Rakefile +37 -0
- data/lib/media_wiki/test_wiki.rb +34 -0
- data/lib/media_wiki/test_wiki/config.rb +348 -0
- data/lib/media_wiki/test_wiki/docker_helper.rb +83 -0
- data/lib/media_wiki/test_wiki/docker_pool.rb +48 -0
- data/lib/media_wiki/test_wiki/rake_helper.rb +217 -0
- data/lib/media_wiki/test_wiki/rake_tasks.rb +32 -0
- data/lib/media_wiki/test_wiki/rspec_adapter.rb +101 -0
- data/lib/media_wiki/test_wiki/tasks/docker.rake +13 -0
- data/lib/media_wiki/test_wiki/tasks/files.rake +28 -0
- data/lib/media_wiki/test_wiki/tasks/main.rake +17 -0
- data/lib/media_wiki/test_wiki/tasks/setup.rake +46 -0
- data/lib/media_wiki/test_wiki/version.rb +31 -0
- data/lib/mediawiki-testwiki.rb +1 -0
- metadata +134 -0
@@ -0,0 +1,83 @@
|
|
1
|
+
#--
|
2
|
+
###############################################################################
|
3
|
+
# #
|
4
|
+
# mediawiki-testwiki -- MediaWiki test wiki based on Docker #
|
5
|
+
# #
|
6
|
+
# Copyright (C) 2014 Jens Wille #
|
7
|
+
# #
|
8
|
+
# Authors: #
|
9
|
+
# Jens Wille <jens.wille@gmail.com> #
|
10
|
+
# #
|
11
|
+
# mediawiki-testwiki is free software; you can redistribute it and/or modify #
|
12
|
+
# it under the terms of the GNU Affero General Public License as published by #
|
13
|
+
# the Free Software Foundation; either version 3 of the License, or (at your #
|
14
|
+
# option) any later version. #
|
15
|
+
# #
|
16
|
+
# mediawiki-testwiki is distributed in the hope that it will be useful, but #
|
17
|
+
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
|
18
|
+
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public #
|
19
|
+
# License for more details. #
|
20
|
+
# #
|
21
|
+
# You should have received a copy of the GNU Affero General Public License #
|
22
|
+
# along with mediawiki-testwiki. If not, see <http://www.gnu.org/licenses/>. #
|
23
|
+
# #
|
24
|
+
###############################################################################
|
25
|
+
#++
|
26
|
+
|
27
|
+
require 'docker_helper'
|
28
|
+
|
29
|
+
require_relative 'config'
|
30
|
+
|
31
|
+
module MediaWiki
|
32
|
+
|
33
|
+
module TestWiki
|
34
|
+
|
35
|
+
module DockerHelper
|
36
|
+
|
37
|
+
include ::DockerHelper
|
38
|
+
|
39
|
+
def self.docker(silent = false, &block)
|
40
|
+
::DockerHelper::Proxy.new.extend(self).tap { |docker|
|
41
|
+
docker.extend(SilentDocker) if silent
|
42
|
+
Config.enhance(docker, &block)
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def docker_container_name(setup = false)
|
47
|
+
parts = [config.registry_repo, config.version]
|
48
|
+
parts << :setup if setup
|
49
|
+
parts.join('-')
|
50
|
+
end
|
51
|
+
|
52
|
+
def docker_image_name(setup = false)
|
53
|
+
base = "#{config.registry_repo}:#{config.version}"
|
54
|
+
setup ? "#{base}-setup" : "#{config.registry_user}/#{base}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def docker_build(image = nil)
|
58
|
+
super(config.build_path, image)
|
59
|
+
end
|
60
|
+
|
61
|
+
def docker_volume(name = nil)
|
62
|
+
super(config.volume, name)
|
63
|
+
end
|
64
|
+
|
65
|
+
def docker_url(*args)
|
66
|
+
args.size > 1 ? super : super(config.port, *args)
|
67
|
+
end
|
68
|
+
|
69
|
+
module SilentDocker
|
70
|
+
|
71
|
+
def docker_system(*args, &block)
|
72
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
73
|
+
options[:out] = options[:err] = :close
|
74
|
+
super(*args << options, &block)
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#--
|
2
|
+
###############################################################################
|
3
|
+
# #
|
4
|
+
# mediawiki-testwiki -- MediaWiki test wiki based on Docker #
|
5
|
+
# #
|
6
|
+
# Copyright (C) 2014 Jens Wille #
|
7
|
+
# #
|
8
|
+
# Authors: #
|
9
|
+
# Jens Wille <jens.wille@gmail.com> #
|
10
|
+
# #
|
11
|
+
# mediawiki-testwiki is free software; you can redistribute it and/or modify #
|
12
|
+
# it under the terms of the GNU Affero General Public License as published by #
|
13
|
+
# the Free Software Foundation; either version 3 of the License, or (at your #
|
14
|
+
# option) any later version. #
|
15
|
+
# #
|
16
|
+
# mediawiki-testwiki is distributed in the hope that it will be useful, but #
|
17
|
+
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
|
18
|
+
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public #
|
19
|
+
# License for more details. #
|
20
|
+
# #
|
21
|
+
# You should have received a copy of the GNU Affero General Public License #
|
22
|
+
# along with mediawiki-testwiki. If not, see <http://www.gnu.org/licenses/>. #
|
23
|
+
# #
|
24
|
+
###############################################################################
|
25
|
+
#++
|
26
|
+
|
27
|
+
require_relative 'docker_helper'
|
28
|
+
|
29
|
+
module MediaWiki
|
30
|
+
|
31
|
+
module TestWiki
|
32
|
+
|
33
|
+
class DockerPool < ::DockerHelper::Pool
|
34
|
+
|
35
|
+
DEFAULT_BASENAME = 'mediawiki-testwiki'
|
36
|
+
|
37
|
+
def initialize(size = nil, basename = nil, silent = false, &block)
|
38
|
+
super(size, basename, DockerHelper.docker(silent, &block)) {
|
39
|
+
self.image, self.port, self.path =
|
40
|
+
docker.image_name, docker.config.port, docker.config.endpoint
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,217 @@
|
|
1
|
+
#--
|
2
|
+
###############################################################################
|
3
|
+
# #
|
4
|
+
# mediawiki-testwiki -- MediaWiki test wiki based on Docker #
|
5
|
+
# #
|
6
|
+
# Copyright (C) 2014 Jens Wille #
|
7
|
+
# #
|
8
|
+
# Authors: #
|
9
|
+
# Jens Wille <jens.wille@gmail.com> #
|
10
|
+
# #
|
11
|
+
# mediawiki-testwiki is free software; you can redistribute it and/or modify #
|
12
|
+
# it under the terms of the GNU Affero General Public License as published by #
|
13
|
+
# the Free Software Foundation; either version 3 of the License, or (at your #
|
14
|
+
# option) any later version. #
|
15
|
+
# #
|
16
|
+
# mediawiki-testwiki is distributed in the hope that it will be useful, but #
|
17
|
+
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
|
18
|
+
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public #
|
19
|
+
# License for more details. #
|
20
|
+
# #
|
21
|
+
# You should have received a copy of the GNU Affero General Public License #
|
22
|
+
# along with mediawiki-testwiki. If not, see <http://www.gnu.org/licenses/>. #
|
23
|
+
# #
|
24
|
+
###############################################################################
|
25
|
+
#++
|
26
|
+
|
27
|
+
require_relative 'docker_helper'
|
28
|
+
|
29
|
+
module MediaWiki
|
30
|
+
|
31
|
+
module TestWiki
|
32
|
+
|
33
|
+
module RakeHelper
|
34
|
+
|
35
|
+
include DockerHelper
|
36
|
+
|
37
|
+
class << self
|
38
|
+
|
39
|
+
def extended(base)
|
40
|
+
keep = [:noop, :verbose]
|
41
|
+
|
42
|
+
base.define_singleton_method(:docker_system) { |*args, &block|
|
43
|
+
options = !args.last.is_a?(Hash) ? {} :
|
44
|
+
args.pop.keep_if { |k,| keep.include?(k) }
|
45
|
+
|
46
|
+
sh(*args << options, &block)
|
47
|
+
}
|
48
|
+
|
49
|
+
configure(base) unless base.respond_to?(:config)
|
50
|
+
end
|
51
|
+
|
52
|
+
def configure(base, load_tasks = false, &block)
|
53
|
+
Config.enhance(base, &block).tap {
|
54
|
+
require_relative 'rake_tasks' if load_tasks
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
def docker_tasks(name, image)
|
61
|
+
%w[start stop restart clean clobber].each { |task|
|
62
|
+
task(task) { send("docker_#{task}", name, image) }
|
63
|
+
}
|
64
|
+
|
65
|
+
task(:start) { puts "#{name}: #{docker_url(name)}" }
|
66
|
+
end
|
67
|
+
|
68
|
+
def file_size(*args)
|
69
|
+
file_create(*args) { |t| File.write(t.name, '') }.instance_eval {
|
70
|
+
def needed?; !File.size?(name); end
|
71
|
+
yield self if block_given?
|
72
|
+
self
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
def fix_config(file, host)
|
77
|
+
File.write(file, File.read(file).tap { |content|
|
78
|
+
content.sub!(/^\$wgServer\b/, '#\&')
|
79
|
+
content.gsub!(host, 'localhost')
|
80
|
+
})
|
81
|
+
end
|
82
|
+
|
83
|
+
def setup_broken(arg)
|
84
|
+
msg = <<-EOT
|
85
|
+
|
86
|
+
*** Manual configuration is broken for this MediaWiki version. ***
|
87
|
+
|
88
|
+
EOT
|
89
|
+
|
90
|
+
if arg.is_a?(LoadError)
|
91
|
+
abort msg << <<-EOT
|
92
|
+
However, automatic configuration is not available: #{arg}.
|
93
|
+
Please install the `mechanize' gem and try again.
|
94
|
+
EOT
|
95
|
+
elsif arg
|
96
|
+
wait msg << <<-EOT
|
97
|
+
Also, automatic configuration is not supported for this version either.
|
98
|
+
Please create a valid configuration file and press enter when finished:
|
99
|
+
#{arg}
|
100
|
+
EOT
|
101
|
+
else
|
102
|
+
abort msg << <<-EOT
|
103
|
+
However, you have requested to skip automatic configuration.
|
104
|
+
Please unset `NOMECHANIZE' and try again.
|
105
|
+
EOT
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def setup_manual(url, dir, cfg, err = nil, unk = nil)
|
110
|
+
msg = <<-EOT
|
111
|
+
|
112
|
+
Visit #{url} and configure the wiki:
|
113
|
+
EOT
|
114
|
+
|
115
|
+
msg << <<-EOT if unk
|
116
|
+
|
117
|
+
NOTE: These configuration instructions have not been verified for
|
118
|
+
this version of MediaWiki -- please use your own judgement!
|
119
|
+
EOT
|
120
|
+
|
121
|
+
msg << <<-EOT
|
122
|
+
|
123
|
+
- Language
|
124
|
+
- Continue
|
125
|
+
|
126
|
+
- Welcome to MediaWiki!
|
127
|
+
- Continue
|
128
|
+
|
129
|
+
- Connect to database
|
130
|
+
- Database type: SQLite
|
131
|
+
- SQLite data directory: #{dir}
|
132
|
+
- Database name: #{config.database_name}
|
133
|
+
- Continue
|
134
|
+
|
135
|
+
- Name
|
136
|
+
- Name of wiki: #{config.sitename}
|
137
|
+
- Your username: #{config.username}
|
138
|
+
- Password: #{config.password}
|
139
|
+
- Password again: #{config.password}
|
140
|
+
- I'm bored already, just install the wiki.
|
141
|
+
- Continue
|
142
|
+
|
143
|
+
- Install (1)
|
144
|
+
- Continue
|
145
|
+
|
146
|
+
- Install (2)
|
147
|
+
- Continue
|
148
|
+
|
149
|
+
Save #{File.basename(cfg)} (replace existing file if already present):
|
150
|
+
#{cfg}
|
151
|
+
|
152
|
+
Close configuration window and press enter when finished.
|
153
|
+
EOT
|
154
|
+
|
155
|
+
msg << <<-EOT if err
|
156
|
+
|
157
|
+
NOTE: Install the `mechanize' gem to automate this process. (#{err})
|
158
|
+
EOT
|
159
|
+
|
160
|
+
wait(msg)
|
161
|
+
end
|
162
|
+
|
163
|
+
def setup_mechanize(url, dir, cfg)
|
164
|
+
agent = Mechanize.new
|
165
|
+
page = agent.get(url)
|
166
|
+
|
167
|
+
continue = lambda { |&block|
|
168
|
+
form = page.forms.first
|
169
|
+
block[form] if block
|
170
|
+
page = agent.submit(form)
|
171
|
+
}
|
172
|
+
|
173
|
+
2.times { continue.() }
|
174
|
+
|
175
|
+
continue.() { |form|
|
176
|
+
form.sqlite_wgSQLiteDataDir = dir
|
177
|
+
form.sqlite_wgDBname = config.database_name
|
178
|
+
form.radiobuttons_with(value: 'sqlite').first.check
|
179
|
+
}
|
180
|
+
|
181
|
+
continue.() { |form|
|
182
|
+
form.radiobuttons_with(value: 'skip').first.check
|
183
|
+
|
184
|
+
form.config_wgSitename = config.sitename
|
185
|
+
form.config__AdminName = config.username
|
186
|
+
|
187
|
+
form.config__AdminPassword = config.password
|
188
|
+
form.config__AdminPassword2 = config.password
|
189
|
+
}
|
190
|
+
|
191
|
+
2.times { continue.() }
|
192
|
+
|
193
|
+
page.link_with(text: Regexp.new(
|
194
|
+
Regexp.escape(File.basename(cfg)))).click.save!(cfg)
|
195
|
+
end
|
196
|
+
|
197
|
+
def verified_version?(strict = false, list = config.verified_versions)
|
198
|
+
strict ? list.include?(config.version) :
|
199
|
+
list.grep(/\A#{Regexp.escape(config.version[/.*\./])}/).any?
|
200
|
+
end
|
201
|
+
|
202
|
+
def broken_version?(strict = false)
|
203
|
+
verified_version?(strict, config.broken_versions)
|
204
|
+
end
|
205
|
+
|
206
|
+
private
|
207
|
+
|
208
|
+
def wait(msg)
|
209
|
+
puts(msg)
|
210
|
+
$stdin.gets
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#--
|
2
|
+
###############################################################################
|
3
|
+
# #
|
4
|
+
# mediawiki-testwiki -- MediaWiki test wiki based on Docker #
|
5
|
+
# #
|
6
|
+
# Copyright (C) 2014 Jens Wille #
|
7
|
+
# #
|
8
|
+
# Authors: #
|
9
|
+
# Jens Wille <jens.wille@gmail.com> #
|
10
|
+
# #
|
11
|
+
# mediawiki-testwiki is free software; you can redistribute it and/or modify #
|
12
|
+
# it under the terms of the GNU Affero General Public License as published by #
|
13
|
+
# the Free Software Foundation; either version 3 of the License, or (at your #
|
14
|
+
# option) any later version. #
|
15
|
+
# #
|
16
|
+
# mediawiki-testwiki is distributed in the hope that it will be useful, but #
|
17
|
+
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
|
18
|
+
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public #
|
19
|
+
# License for more details. #
|
20
|
+
# #
|
21
|
+
# You should have received a copy of the GNU Affero General Public License #
|
22
|
+
# along with mediawiki-testwiki. If not, see <http://www.gnu.org/licenses/>. #
|
23
|
+
# #
|
24
|
+
###############################################################################
|
25
|
+
#++
|
26
|
+
|
27
|
+
require_relative 'rake_helper'
|
28
|
+
|
29
|
+
extend MediaWiki::TestWiki::RakeHelper
|
30
|
+
|
31
|
+
%w[main files setup docker].each { |task|
|
32
|
+
load "media_wiki/test_wiki/tasks/#{task}.rake" }
|
@@ -0,0 +1,101 @@
|
|
1
|
+
#--
|
2
|
+
###############################################################################
|
3
|
+
# #
|
4
|
+
# mediawiki-testwiki -- MediaWiki test wiki based on Docker #
|
5
|
+
# #
|
6
|
+
# Copyright (C) 2014 Jens Wille #
|
7
|
+
# #
|
8
|
+
# Authors: #
|
9
|
+
# Jens Wille <jens.wille@gmail.com> #
|
10
|
+
# #
|
11
|
+
# mediawiki-testwiki is free software; you can redistribute it and/or modify #
|
12
|
+
# it under the terms of the GNU Affero General Public License as published by #
|
13
|
+
# the Free Software Foundation; either version 3 of the License, or (at your #
|
14
|
+
# option) any later version. #
|
15
|
+
# #
|
16
|
+
# mediawiki-testwiki is distributed in the hope that it will be useful, but #
|
17
|
+
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
|
18
|
+
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public #
|
19
|
+
# License for more details. #
|
20
|
+
# #
|
21
|
+
# You should have received a copy of the GNU Affero General Public License #
|
22
|
+
# along with mediawiki-testwiki. If not, see <http://www.gnu.org/licenses/>. #
|
23
|
+
# #
|
24
|
+
###############################################################################
|
25
|
+
#++
|
26
|
+
|
27
|
+
require_relative 'docker_pool'
|
28
|
+
|
29
|
+
module MediaWiki
|
30
|
+
|
31
|
+
module TestWiki
|
32
|
+
|
33
|
+
module RSpecAdapter
|
34
|
+
|
35
|
+
Proxy = Struct.new(:version, :config, :pool)
|
36
|
+
|
37
|
+
PROXY_NAME = :live_media_wiki
|
38
|
+
|
39
|
+
class << self
|
40
|
+
|
41
|
+
def enhance(config, *args)
|
42
|
+
return if config.respond_to?(PROXY_NAME)
|
43
|
+
init_config(Proxy.new, config, *args)
|
44
|
+
config
|
45
|
+
end
|
46
|
+
|
47
|
+
def extended(base)
|
48
|
+
init_proxy(RSpec.configuration.send(PROXY_NAME), base.metadata)
|
49
|
+
base
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def init_config(mw, config, *args)
|
55
|
+
config.add_setting PROXY_NAME, default: mw
|
56
|
+
|
57
|
+
config.after :context, *args do mw.pool.clean end
|
58
|
+
config.extend self, *args
|
59
|
+
config.include Helpers, *args
|
60
|
+
|
61
|
+
config.filter_run_excluding required_version: lambda { |value|
|
62
|
+
version = mw.version and not
|
63
|
+
Gem::Requirement.new(Array(value)).satisfied_by?(version)
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
def init_proxy(mw, options = {})
|
68
|
+
version, size = options.values_at(:version, :pool_size)
|
69
|
+
|
70
|
+
mw.pool = DockerPool.new(size, nil, true) { |config|
|
71
|
+
mw.version = Gem::Version.new(config.version = version) if version
|
72
|
+
mw.config = { username: config.username, password: config.password }
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
module Helpers
|
79
|
+
|
80
|
+
def live_media_wiki_gateway(*args)
|
81
|
+
described_class.new(@live_media_wiki_url, *args).tap { |gateway|
|
82
|
+
yield gateway if block_given?
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
def live_media_wiki_reset(*args, &block)
|
87
|
+
mw = RSpec.configuration.send(PROXY_NAME)
|
88
|
+
|
89
|
+
@live_media_wiki_url = mw.pool.fetch_url
|
90
|
+
|
91
|
+
mw.config.values_at(:username, :password)
|
92
|
+
.unshift(live_media_wiki_gateway(*args, &block))
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|