dumpdb 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +1 -2
- data/dumpdb.gemspec +6 -4
- data/lib/dumpdb.rb +40 -38
- data/lib/dumpdb/runner.rb +11 -11
- data/lib/dumpdb/settings.rb +4 -4
- data/lib/dumpdb/version.rb +1 -1
- data/test/helper.rb +8 -0
- data/test/unit/db_tests.rb +4 -1
- data/test/unit/{script_tests.rb → dumpdb_tests.rb} +28 -26
- data/test/unit/runner_tests.rb +17 -15
- data/test/unit/settings_tests.rb +114 -104
- metadata +21 -58
- data/Rakefile +0 -1
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA512:
|
3
|
+
metadata.gz: b45a5c4f8c56f6beb4b9abb1f28db750d333d73b6b2531a5fba69684d7324bf9d7be336e694831c813bb9fe5ded0fc7769b1bb350ba5f197bd96d4f88b50e25e
|
4
|
+
data.tar.gz: 43ffadbd18f646c146b1b3a4cb74907786162c8d78f0540a35d4223940b88f3e2da564b782eb8f25eb20c691ca0f6b1685bf1223c9f2f876fd54cf3528671dd0
|
5
|
+
SHA1:
|
6
|
+
metadata.gz: 8db6421ca5dfed0343dc706b65d4b924d11039b1
|
7
|
+
data.tar.gz: 97c8455c86faff07ff5c7ffbce8c9eb97eabf6e5
|
data/Gemfile
CHANGED
data/dumpdb.gemspec
CHANGED
@@ -8,17 +8,19 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.version = Dumpdb::VERSION
|
9
9
|
gem.authors = ["Kelly Redding", "Collin Redding"]
|
10
10
|
gem.email = ["kelly@kellyredding.com", "collin.redding@me.com"]
|
11
|
-
gem.description = %q{Dump and restore your databases.}
|
12
11
|
gem.summary = %q{Dump and restore your databases.}
|
12
|
+
gem.description = %q{Dump and restore your databases.}
|
13
13
|
gem.homepage = "http://github.com/redding/dumpdb"
|
14
|
+
gem.license = 'MIT'
|
14
15
|
|
15
16
|
gem.files = `git ls-files`.split($/)
|
16
17
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
19
|
gem.require_paths = ["lib"]
|
19
20
|
|
20
|
-
gem.add_development_dependency("assert", ["~> 2.
|
21
|
+
gem.add_development_dependency("assert", ["~> 2.16.1"])
|
22
|
+
|
23
|
+
gem.add_dependency("much-plugin", ["~> 0.2.0"])
|
24
|
+
gem.add_dependency("scmd", ["~> 3.0.2"])
|
21
25
|
|
22
|
-
gem.add_dependency("scmd", ["~> 3.0"])
|
23
|
-
gem.add_dependency("ns-options", ["~> 1.1", ">= 1.1.1"])
|
24
26
|
end
|
data/lib/dumpdb.rb
CHANGED
@@ -1,60 +1,60 @@
|
|
1
|
-
require '
|
1
|
+
require 'much-plugin'
|
2
2
|
require 'dumpdb/version'
|
3
3
|
require 'dumpdb/settings'
|
4
4
|
require 'dumpdb/db'
|
5
5
|
require 'dumpdb/runner'
|
6
6
|
|
7
7
|
module Dumpdb
|
8
|
+
include MuchPlugin
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
receiver.class_eval do
|
13
|
-
include NsOptions
|
14
|
-
options :settings do
|
15
|
-
option 'ssh', Settings::Ssh, :default => ''
|
16
|
-
option 'dump_file', Settings::DumpFile, :default => ''
|
17
|
-
option 'source', Settings::SourceTarget, :default => {}
|
18
|
-
option 'target', Settings::SourceTarget, :default => {}
|
19
|
-
option 'dump_cmds', Settings::CmdList, :default => []
|
20
|
-
option 'restore_cmds', Settings::CmdList, :default => []
|
21
|
-
end
|
22
|
-
|
23
|
-
extend SettingsDslMethods
|
24
|
-
include SettingsMethods
|
25
|
-
|
26
|
-
def self.inherited(subclass)
|
27
|
-
subclass.settings.apply(self.settings.to_hash)
|
28
|
-
end
|
10
|
+
plugin_included do
|
11
|
+
extend ClassMethods
|
12
|
+
include InstanceMethods
|
29
13
|
|
14
|
+
def self.inherited(subclass)
|
15
|
+
subclass.settings = self.settings
|
30
16
|
end
|
31
|
-
end
|
32
17
|
|
33
|
-
|
18
|
+
end
|
34
19
|
|
35
|
-
|
36
|
-
|
37
|
-
def
|
38
|
-
def
|
20
|
+
module ClassMethods
|
21
|
+
|
22
|
+
def ssh(&block); settings[:ssh] = Settings::Ssh.new(block); end
|
23
|
+
def dump_file(&block); settings[:dump_file] = Settings::DumpFile.new(block); end
|
24
|
+
def source(&block); settings[:source] = Settings::SourceTarget.new(block); end
|
25
|
+
def target(&block); settings[:target] = Settings::SourceTarget.new(block); end
|
26
|
+
|
27
|
+
def dump(&block); settings[:dump_cmds] << Settings::DumpCmd.new(block); end
|
28
|
+
def restore(&block); settings[:restore_cmds] << Settings::RestoreCmd.new(block); end
|
29
|
+
|
30
|
+
def settings
|
31
|
+
@settings ||= {
|
32
|
+
:ssh => Settings::Ssh.new(''),
|
33
|
+
:dump_file => Settings::DumpFile.new(''),
|
34
|
+
:source => Settings::SourceTarget.new({}),
|
35
|
+
:target => Settings::SourceTarget.new({}),
|
36
|
+
:dump_cmds => Settings::CmdList.new([]),
|
37
|
+
:restore_cmds => Settings::CmdList.new([])
|
38
|
+
}
|
39
|
+
end
|
39
40
|
|
40
|
-
def
|
41
|
-
def restore(&block); settings.restore_cmds << Settings::RestoreCmd.new(block); end
|
41
|
+
def settings=(value); @settings = value; end
|
42
42
|
|
43
43
|
end
|
44
44
|
|
45
|
-
module
|
45
|
+
module InstanceMethods
|
46
46
|
|
47
|
-
def
|
48
|
-
|
49
|
-
def
|
50
|
-
def
|
51
|
-
def source; @source ||= settings.source.value(self); end
|
52
|
-
def target; @target ||= settings.target.value(self); end
|
47
|
+
def ssh; @ssh ||= settings[:ssh].value(self); end
|
48
|
+
def dump_file; @dump_file ||= settings[:dump_file].value(self); end
|
49
|
+
def source; @source ||= settings[:source].value(self); end
|
50
|
+
def target; @target ||= settings[:target].value(self); end
|
53
51
|
|
54
|
-
def dump_cmds; @dump_cmds ||= settings
|
55
|
-
def restore_cmds; @restore_cmds ||= settings
|
52
|
+
def dump_cmds; @dump_cmds ||= settings[:dump_cmds].value(self); end
|
53
|
+
def restore_cmds; @restore_cmds ||= settings[:restore_cmds].value(self); end
|
56
54
|
def copy_dump_cmd; @copy_dump_cmd ||= Settings::CopyDumpCmd.new.value(self); end
|
57
55
|
|
56
|
+
def settings; self.class.settings; end
|
57
|
+
|
58
58
|
end
|
59
59
|
|
60
60
|
def dump_cmd(&block); Settings::DumpCmd.new(block).value(self); end
|
@@ -89,4 +89,6 @@ module Dumpdb
|
|
89
89
|
def before_cmd_run(*args); end
|
90
90
|
def after_cmd_run(*args); end
|
91
91
|
|
92
|
+
BadDatabaseName = Class.new(RuntimeError)
|
93
|
+
|
92
94
|
end
|
data/lib/dumpdb/runner.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
require 'dumpdb/settings'
|
2
2
|
|
3
3
|
module Dumpdb
|
4
|
+
|
4
5
|
class Runner
|
5
6
|
|
6
7
|
attr_reader :script, :cmd_runner
|
7
8
|
|
8
9
|
def initialize(script, opts={})
|
9
|
-
@script
|
10
|
+
@script = script
|
10
11
|
@cmd_runner = opts[:cmd_runner] || scmd_cmd_runner
|
11
12
|
end
|
12
13
|
|
@@ -17,22 +18,22 @@ module Dumpdb
|
|
17
18
|
|
18
19
|
begin
|
19
20
|
run_callback 'after_setup'
|
20
|
-
[:dump, :copy_dump, :restore].each{|phase_name| run_phase phase_name}
|
21
|
+
[:dump, :copy_dump, :restore].each{ |phase_name| run_phase phase_name }
|
21
22
|
ensure
|
22
23
|
run_phase 'teardown'
|
23
24
|
run_callback 'after_run'
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
27
|
-
|
28
|
+
private
|
28
29
|
|
29
30
|
def run_setup
|
30
|
-
run_cmd(@script.dump_cmd
|
31
|
-
run_cmd(@script.restore_cmd
|
31
|
+
run_cmd(@script.dump_cmd{ "mkdir -p #{source.output_dir}" })
|
32
|
+
run_cmd(@script.restore_cmd{ "mkdir -p #{target.output_dir}" })
|
32
33
|
end
|
33
34
|
|
34
35
|
def run_dump
|
35
|
-
@script.dump_cmds.each{|cmd| run_cmd(cmd)}
|
36
|
+
@script.dump_cmds.each{ |cmd| run_cmd(cmd) }
|
36
37
|
end
|
37
38
|
|
38
39
|
def run_copy_dump
|
@@ -40,16 +41,14 @@ module Dumpdb
|
|
40
41
|
end
|
41
42
|
|
42
43
|
def run_restore
|
43
|
-
@script.restore_cmds.each{|cmd| run_cmd(cmd)}
|
44
|
+
@script.restore_cmds.each{ |cmd| run_cmd(cmd) }
|
44
45
|
end
|
45
46
|
|
46
47
|
def run_teardown
|
47
|
-
run_cmd(@script.dump_cmd
|
48
|
-
run_cmd(@script.restore_cmd
|
48
|
+
run_cmd(@script.dump_cmd{ "rm -rf #{source.output_dir}" })
|
49
|
+
run_cmd(@script.restore_cmd{ "rm -rf #{target.output_dir}" })
|
49
50
|
end
|
50
51
|
|
51
|
-
private
|
52
|
-
|
53
52
|
def run_phase(phase_name)
|
54
53
|
run_callback "before_#{phase_name}"
|
55
54
|
self.send("run_#{phase_name}")
|
@@ -73,4 +72,5 @@ module Dumpdb
|
|
73
72
|
end
|
74
73
|
|
75
74
|
end
|
75
|
+
|
76
76
|
end
|
data/lib/dumpdb/settings.rb
CHANGED
@@ -6,7 +6,7 @@ module Dumpdb::Settings
|
|
6
6
|
|
7
7
|
attr_reader :proc
|
8
8
|
|
9
|
-
def initialize(proc=nil)
|
9
|
+
def initialize(proc = nil)
|
10
10
|
@proc = proc.kind_of?(::Proc) ? proc : Proc.new { proc }
|
11
11
|
end
|
12
12
|
|
@@ -45,7 +45,7 @@ module Dumpdb::Settings
|
|
45
45
|
|
46
46
|
class DumpCmd < Cmd
|
47
47
|
|
48
|
-
def value(script, placeholder_vals={})
|
48
|
+
def value(script, placeholder_vals = {})
|
49
49
|
val = super(script, script.source.to_hash.merge(placeholder_vals))
|
50
50
|
if script.ssh?
|
51
51
|
val = val.gsub("\\", "\\\\\\").gsub('"', '\"')
|
@@ -58,7 +58,7 @@ module Dumpdb::Settings
|
|
58
58
|
|
59
59
|
class RestoreCmd < Cmd
|
60
60
|
|
61
|
-
def value(script, placeholder_vals={})
|
61
|
+
def value(script, placeholder_vals = {})
|
62
62
|
super(script, script.target.to_hash.merge(placeholder_vals))
|
63
63
|
end
|
64
64
|
|
@@ -78,7 +78,7 @@ module Dumpdb::Settings
|
|
78
78
|
|
79
79
|
class CmdList < ::Array
|
80
80
|
|
81
|
-
def value(script, placeholder_vals={})
|
81
|
+
def value(script, placeholder_vals = {})
|
82
82
|
self.map{ |cmd| cmd.value(script, placeholder_vals) }
|
83
83
|
end
|
84
84
|
|
data/lib/dumpdb/version.rb
CHANGED
data/test/helper.rb
CHANGED
data/test/unit/db_tests.rb
CHANGED
@@ -41,7 +41,7 @@ class Dumpdb::Db
|
|
41
41
|
:custom_value => @custom_value
|
42
42
|
})
|
43
43
|
end
|
44
|
-
subject
|
44
|
+
subject{ @db }
|
45
45
|
|
46
46
|
should have_imeths :host, :port, :user, :pw, :db
|
47
47
|
should have_imeths :output_root, :output_dir, :dump_file
|
@@ -54,8 +54,10 @@ class Dumpdb::Db
|
|
54
54
|
assert_equal @pw, subject.pw
|
55
55
|
assert_equal @db_name, subject.db
|
56
56
|
assert_equal @output_root, subject.output_root
|
57
|
+
|
57
58
|
exp = File.join(@output_root, "#{@host}__#{@db_name}__#{@current_time.to_f}")
|
58
59
|
assert_equal exp, subject.output_dir
|
60
|
+
|
59
61
|
exp = File.join(subject.output_dir, @dump_file_name)
|
60
62
|
assert_equal exp, subject.dump_file
|
61
63
|
end
|
@@ -75,6 +77,7 @@ class Dumpdb::Db
|
|
75
77
|
assert_equal DEFAULT_VALUE, db.db
|
76
78
|
assert_equal DEFAULT_VALUE, db.output_root
|
77
79
|
assert_equal @current_time.to_f.to_s, db.output_dir
|
80
|
+
|
78
81
|
exp = File.join(db.output_dir, 'dump.output')
|
79
82
|
assert_equal exp, db.dump_file
|
80
83
|
end
|
@@ -1,15 +1,22 @@
|
|
1
1
|
require 'assert'
|
2
|
+
require 'dumpdb'
|
3
|
+
|
2
4
|
require 'test/support/fake_cmd_runner'
|
3
5
|
require 'test/support/test_scripts'
|
4
6
|
|
5
7
|
module Dumpdb
|
6
8
|
|
7
|
-
class
|
8
|
-
desc "
|
9
|
+
class UnitTests < Assert::Context
|
10
|
+
desc "Dumpdb"
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
class InitTests < UnitTests
|
15
|
+
desc "when init"
|
9
16
|
setup do
|
10
|
-
@script = LocalScript.new
|
17
|
+
@script = LocalScript.new # mixes in Dumpdb
|
11
18
|
end
|
12
|
-
subject
|
19
|
+
subject{ @script }
|
13
20
|
|
14
21
|
should have_cmeths :settings
|
15
22
|
should have_imeths :settings, :dump_cmd, :restore_cmd
|
@@ -26,23 +33,18 @@ module Dumpdb
|
|
26
33
|
should have_imeths :before_dump, :before_copy_dump, :before_restore
|
27
34
|
should have_imeths :after_dump, :after_copy_dump, :after_restore
|
28
35
|
|
29
|
-
should "store its settings using ns-options" do
|
30
|
-
assert_kind_of NsOptions::Namespace, subject.class.settings
|
31
|
-
assert_same subject.class.settings, subject.settings
|
32
|
-
end
|
33
|
-
|
34
36
|
should "store off the settings for the script" do
|
35
|
-
assert_kind_of Settings::Ssh, subject.settings
|
36
|
-
assert_kind_of Settings::DumpFile, subject.settings
|
37
|
-
assert_kind_of Settings::SourceTarget, subject.settings
|
38
|
-
assert_kind_of Settings::SourceTarget, subject.settings
|
39
|
-
assert_kind_of Settings::CmdList, subject.settings
|
40
|
-
assert_kind_of Settings::CmdList, subject.settings
|
37
|
+
assert_kind_of Settings::Ssh, subject.settings[:ssh]
|
38
|
+
assert_kind_of Settings::DumpFile, subject.settings[:dump_file]
|
39
|
+
assert_kind_of Settings::SourceTarget, subject.settings[:source]
|
40
|
+
assert_kind_of Settings::SourceTarget, subject.settings[:target]
|
41
|
+
assert_kind_of Settings::CmdList, subject.settings[:dump_cmds]
|
42
|
+
assert_kind_of Settings::CmdList, subject.settings[:restore_cmds]
|
41
43
|
end
|
42
44
|
|
43
45
|
end
|
44
46
|
|
45
|
-
class CmdMethsTests <
|
47
|
+
class CmdMethsTests < InitTests
|
46
48
|
|
47
49
|
should "build dump command strings" do
|
48
50
|
assert_equal 'echo local', subject.dump_cmd { "echo #{type}" }
|
@@ -54,7 +56,7 @@ module Dumpdb
|
|
54
56
|
|
55
57
|
end
|
56
58
|
|
57
|
-
class SshTests <
|
59
|
+
class SshTests < InitTests
|
58
60
|
|
59
61
|
should "know if its in ssh mode or not" do
|
60
62
|
assert RemoteScript.new.ssh?
|
@@ -71,27 +73,27 @@ module Dumpdb
|
|
71
73
|
|
72
74
|
end
|
73
75
|
|
74
|
-
class RunTests <
|
76
|
+
class RunTests < InitTests
|
75
77
|
setup do
|
76
|
-
FakeCmdRunner.reset
|
78
|
+
Dumpdb::FakeCmdRunner.reset
|
77
79
|
@script = RunnerScript.new
|
78
80
|
end
|
79
81
|
teardown do
|
80
|
-
FakeCmdRunner.reset
|
82
|
+
Dumpdb::FakeCmdRunner.reset
|
81
83
|
end
|
82
84
|
|
83
85
|
should "run the script when `run` is called" do
|
84
|
-
assert_empty FakeCmdRunner.cmds
|
85
|
-
@script.run(FakeCmdRunner)
|
86
|
+
assert_empty Dumpdb::FakeCmdRunner.cmds
|
87
|
+
@script.run(Dumpdb::FakeCmdRunner)
|
86
88
|
|
87
|
-
assert_not_empty FakeCmdRunner.cmds
|
88
|
-
assert_equal 7, FakeCmdRunner.cmds.size
|
89
|
-
assert_equal "a restore cmd", FakeCmdRunner.cmds[-3]
|
89
|
+
assert_not_empty Dumpdb::FakeCmdRunner.cmds
|
90
|
+
assert_equal 7, Dumpdb::FakeCmdRunner.cmds.size
|
91
|
+
assert_equal "a restore cmd", Dumpdb::FakeCmdRunner.cmds[-3]
|
90
92
|
end
|
91
93
|
|
92
94
|
end
|
93
95
|
|
94
|
-
class InheritedTests <
|
96
|
+
class InheritedTests < InitTests
|
95
97
|
desc "when inherited"
|
96
98
|
setup do
|
97
99
|
@a_remote_script = RemoteScript.new
|
data/test/unit/runner_tests.rb
CHANGED
@@ -1,39 +1,41 @@
|
|
1
1
|
require 'assert'
|
2
|
+
require 'dumpdb/runner'
|
3
|
+
|
2
4
|
require 'test/support/fake_cmd_runner'
|
3
5
|
require 'test/support/test_scripts'
|
4
|
-
require 'dumpdb/runner'
|
5
6
|
|
6
|
-
|
7
|
+
class Dumpdb::Runner
|
7
8
|
|
8
|
-
class
|
9
|
-
desc "
|
9
|
+
class UnitTests < Assert::Context
|
10
|
+
desc "Dumpdb::Runner"
|
10
11
|
setup do
|
11
|
-
FakeCmdRunner
|
12
|
+
@fake_cmd_runner = Dumpdb::FakeCmdRunner
|
13
|
+
@fake_cmd_runner.reset
|
14
|
+
|
12
15
|
@script = RunnerScript.new
|
13
|
-
@runner = Runner.new(@script, :cmd_runner =>
|
16
|
+
@runner = Dumpdb::Runner.new(@script, :cmd_runner => @fake_cmd_runner)
|
14
17
|
end
|
15
18
|
teardown do
|
16
|
-
|
19
|
+
@fake_cmd_runner.reset
|
17
20
|
end
|
18
|
-
subject
|
19
|
-
|
21
|
+
subject{ @runner }
|
20
22
|
|
21
23
|
should have_reader :script, :cmd_runner
|
22
24
|
|
23
25
|
should "run the script" do
|
24
|
-
assert_empty
|
26
|
+
assert_empty @fake_cmd_runner.cmds
|
25
27
|
subject.run
|
26
28
|
|
27
|
-
assert_not_empty
|
28
|
-
assert_equal 7,
|
29
|
-
assert_equal "a restore cmd",
|
29
|
+
assert_not_empty @fake_cmd_runner.cmds
|
30
|
+
assert_equal 7, @fake_cmd_runner.cmds.size
|
31
|
+
assert_equal "a restore cmd", @fake_cmd_runner.cmds[-3]
|
30
32
|
end
|
31
33
|
|
32
34
|
should "call the callbacks" do
|
33
|
-
|
35
|
+
assert_false @script.all_callbacks_called?
|
34
36
|
subject.run
|
35
37
|
|
36
|
-
|
38
|
+
assert_true @script.all_callbacks_called?
|
37
39
|
end
|
38
40
|
|
39
41
|
end
|
data/test/unit/settings_tests.rb
CHANGED
@@ -1,189 +1,162 @@
|
|
1
1
|
require 'assert'
|
2
|
-
require 'test/support/test_scripts'
|
3
2
|
require 'dumpdb/settings'
|
4
3
|
|
5
|
-
|
4
|
+
require 'dumpdb/db'
|
5
|
+
require 'test/support/test_scripts'
|
6
|
+
|
7
|
+
module Dumpdb::Settings
|
6
8
|
|
7
|
-
class
|
8
|
-
desc "
|
9
|
+
class UnitTests < Assert::Context
|
10
|
+
desc "Dumpdb::Settings"
|
9
11
|
setup do
|
10
|
-
@setting = Settings::Base.new
|
11
12
|
@script = LocalScript.new
|
12
13
|
end
|
13
|
-
subject { @setting }
|
14
14
|
|
15
|
-
|
16
|
-
should have_reader :proc
|
15
|
+
end
|
17
16
|
|
18
|
-
|
17
|
+
class BaseTests < UnitTests
|
18
|
+
desc "Base"
|
19
|
+
setup do
|
20
|
+
@setting = Base.new
|
21
|
+
end
|
22
|
+
subject{ @setting }
|
23
|
+
|
24
|
+
should have_readers :proc
|
25
|
+
should have_imeths :value
|
26
|
+
|
27
|
+
should "know its proc" do
|
19
28
|
assert_kind_of ::Proc, subject.proc
|
20
29
|
assert_nil subject.proc.call
|
21
30
|
end
|
22
31
|
|
23
32
|
should "instance eval its proc in the scope of a script to return a value" do
|
24
|
-
setting =
|
33
|
+
setting = Base.new(Proc.new{ "something: #{type}" })
|
25
34
|
|
26
|
-
assert_equal "local",
|
35
|
+
assert_equal "local", @script.type
|
27
36
|
assert_equal "something: local", setting.value(@script)
|
28
37
|
end
|
29
38
|
|
30
39
|
end
|
31
40
|
|
32
|
-
class
|
33
|
-
desc "
|
41
|
+
class SshTests < UnitTests
|
42
|
+
desc "Ssh"
|
34
43
|
|
35
|
-
should "be
|
36
|
-
|
44
|
+
should "be a Base setting" do
|
45
|
+
assert_true Ssh < Base
|
37
46
|
end
|
38
47
|
|
39
48
|
end
|
40
49
|
|
41
|
-
class
|
42
|
-
desc "
|
50
|
+
class DumpFileTests < UnitTests
|
51
|
+
desc "DumpFile"
|
43
52
|
|
44
|
-
should "be
|
45
|
-
|
53
|
+
should "be a Base setting" do
|
54
|
+
assert_true DumpFile < Base
|
46
55
|
end
|
47
56
|
|
48
57
|
end
|
49
58
|
|
50
|
-
class
|
51
|
-
desc "
|
52
|
-
setup do
|
53
|
-
@from_hash = {'host' => 'from_hash'}
|
54
|
-
end
|
59
|
+
class SourceTargetTests < UnitTests
|
60
|
+
desc "SourceTarget"
|
55
61
|
|
56
|
-
should "be
|
57
|
-
|
62
|
+
should "be a Base setting" do
|
63
|
+
assert_true SourceTarget < Base
|
58
64
|
end
|
59
65
|
|
60
|
-
should "
|
61
|
-
|
66
|
+
should "have a Db value built from a hash" do
|
67
|
+
from_hash = { 'host' => 'from_hash' }
|
68
|
+
db = SourceTarget.new(from_hash).value(@script)
|
62
69
|
|
63
|
-
assert_kind_of Db, db
|
70
|
+
assert_kind_of Dumpdb::Db, db
|
64
71
|
assert_equal 'from_hash', db.host
|
65
72
|
end
|
66
73
|
|
67
74
|
end
|
68
75
|
|
69
|
-
class CmdTests <
|
70
|
-
desc "
|
71
|
-
setup do
|
72
|
-
@cmd_str = Proc.new { "this is the #{type} db: :db" }
|
73
|
-
end
|
76
|
+
class CmdTests < UnitTests
|
77
|
+
desc "Cmd"
|
74
78
|
|
75
|
-
should "be
|
76
|
-
|
79
|
+
should "be a Base setting" do
|
80
|
+
assert_true Cmd < Base
|
77
81
|
end
|
78
82
|
|
79
83
|
should "eval and apply any placeholders to the cmd string" do
|
80
|
-
|
84
|
+
cmd_str = Proc.new{ "this is the #{type} db: :db" }
|
85
|
+
cmd_val = Cmd.new(cmd_str).value(@script, @script.source.to_hash)
|
81
86
|
assert_equal "this is the local db: devdb", cmd_val
|
82
87
|
end
|
83
88
|
|
84
89
|
end
|
85
90
|
|
86
|
-
class DumpCmdTests <
|
87
|
-
desc "
|
91
|
+
class DumpCmdTests < UnitTests
|
92
|
+
desc "DumpCmd"
|
93
|
+
|
94
|
+
should "be a Cmd setting" do
|
95
|
+
assert_true DumpCmd < Cmd
|
96
|
+
end
|
88
97
|
|
89
98
|
should "eval and apply any source placeholders to the cmd string" do
|
90
|
-
|
99
|
+
cmd_str = Proc.new{ "this is the #{type} db: :db" }
|
100
|
+
cmd_val = DumpCmd.new(cmd_str).value(@script)
|
91
101
|
assert_equal "this is the local db: devdb", cmd_val
|
92
102
|
end
|
93
103
|
|
94
104
|
should "not escape any double-quotes in the cmds" do
|
95
|
-
orig_cmd
|
96
|
-
cmd_val
|
97
|
-
|
105
|
+
orig_cmd = "do_something --value=\"a_val\""
|
106
|
+
cmd_val = DumpCmd.new(Proc.new{ orig_cmd }).value(@script)
|
98
107
|
assert_equal orig_cmd, cmd_val
|
99
108
|
end
|
100
109
|
|
101
110
|
should "not escape any backslashes in the cmds" do
|
102
|
-
orig_cmd
|
103
|
-
cmd_val
|
104
|
-
|
111
|
+
orig_cmd = "do \\something"
|
112
|
+
cmd_val = DumpCmd.new(Proc.new{ orig_cmd }).value(@script)
|
105
113
|
assert_equal orig_cmd, cmd_val
|
106
114
|
end
|
107
115
|
|
108
116
|
end
|
109
117
|
|
110
|
-
class
|
111
|
-
desc "
|
112
|
-
setup do
|
113
|
-
@script = RemoteScript.new
|
114
|
-
@cmd_str = Proc.new { "echo hello" }
|
115
|
-
end
|
116
|
-
|
117
|
-
should "build the cmds to run remtoely using ssh" do
|
118
|
-
exp_cmd_str = "ssh -A #{@script.ssh_opts} #{@script.ssh} \"echo hello\""
|
119
|
-
cmd_val = Settings::DumpCmd.new(@cmd_str).value(@script)
|
120
|
-
|
121
|
-
assert_equal exp_cmd_str, cmd_val
|
122
|
-
end
|
123
|
-
|
124
|
-
should "escape any double-quotes in the cmds" do
|
125
|
-
orig_cmd = "do_something --value=\"a_val\""
|
126
|
-
exp_esc_cmd = "do_something --value=\\\"a_val\\\""
|
127
|
-
exp_cmd_str = "ssh -A #{@script.ssh_opts} #{@script.ssh} \"#{exp_esc_cmd}\""
|
128
|
-
cmd_val = Settings::DumpCmd.new(Proc.new { orig_cmd }).value(@script)
|
129
|
-
|
130
|
-
assert_equal exp_cmd_str, cmd_val
|
131
|
-
end
|
132
|
-
|
133
|
-
should "escape any backslashes in the cmds" do
|
134
|
-
orig_cmd = "do \\something"
|
135
|
-
exp_esc_cmd = "do \\\\something"
|
136
|
-
exp_cmd_str = "ssh -A #{@script.ssh_opts} #{@script.ssh} \"#{exp_esc_cmd}\""
|
137
|
-
cmd_val = Settings::DumpCmd.new(Proc.new { orig_cmd }).value(@script)
|
138
|
-
|
139
|
-
assert_equal exp_cmd_str, cmd_val
|
140
|
-
end
|
141
|
-
|
142
|
-
should "escape any backslashes before double-quotes in the cmds" do
|
143
|
-
orig_cmd = "do \\something --value=\"a_val\""
|
144
|
-
exp_esc_cmd = "do \\\\something --value=\\\"a_val\\\""
|
145
|
-
exp_cmd_str = "ssh -A #{@script.ssh_opts} #{@script.ssh} \"#{exp_esc_cmd}\""
|
146
|
-
cmd_val = Settings::DumpCmd.new(Proc.new { orig_cmd }).value(@script)
|
118
|
+
class RestoreCmdTests < UnitTests
|
119
|
+
desc "RestoreCmd"
|
147
120
|
|
148
|
-
|
121
|
+
should "be a Cmd setting" do
|
122
|
+
assert_true RestoreCmd < Cmd
|
149
123
|
end
|
150
124
|
|
151
|
-
end
|
152
|
-
|
153
|
-
class RestoreCmdTests < CmdTests
|
154
|
-
desc "for restore commands"
|
155
|
-
|
156
125
|
should "eval and apply any target placeholders to the cmd string" do
|
157
|
-
|
126
|
+
cmd_str = Proc.new{ "this is the #{type} db: :db" }
|
127
|
+
cmd_val = RestoreCmd.new(cmd_str).value(@script)
|
158
128
|
assert_equal "this is the local db: testdb", cmd_val
|
159
129
|
end
|
160
130
|
|
161
131
|
end
|
162
132
|
|
163
|
-
class CopyDumpCmdTests <
|
133
|
+
class CopyDumpCmdTests < UnitTests
|
134
|
+
desc "CopyDumpCmd"
|
164
135
|
|
165
|
-
should "be a
|
166
|
-
|
167
|
-
|
136
|
+
should "be a Cmd setting" do
|
137
|
+
assert_true CopyDumpCmd < Cmd
|
138
|
+
end
|
168
139
|
|
169
|
-
|
140
|
+
should "be a copy cmd for non-ssh scripts" do
|
141
|
+
exp = "cp #{@script.source.dump_file} #{@script.target.dump_file}"
|
142
|
+
assert_equal exp, @script.copy_dump_cmd
|
170
143
|
end
|
171
144
|
|
172
145
|
should "be an sftp cmd for ssh scripts" do
|
173
146
|
script = RemoteScript.new
|
174
|
-
|
175
|
-
|
176
|
-
assert_equal
|
147
|
+
exp = "sftp #{script.ssh_opts} #{script.ssh}:#{script.source.dump_file} " \
|
148
|
+
"#{script.target.dump_file}"
|
149
|
+
assert_equal exp, script.copy_dump_cmd
|
177
150
|
end
|
178
151
|
|
179
152
|
end
|
180
153
|
|
181
|
-
class CmdListTests <
|
182
|
-
desc "
|
154
|
+
class CmdListTests < UnitTests
|
155
|
+
desc "CmdList"
|
183
156
|
setup do
|
184
157
|
@cmds = [
|
185
|
-
|
186
|
-
|
158
|
+
Cmd.new(Proc.new{ "this is the #{type} target db: :db" }),
|
159
|
+
Cmd.new(Proc.new{ "this is the #{type} target host: :host" })
|
187
160
|
]
|
188
161
|
@exp_val_cmds = [
|
189
162
|
"this is the local target db: testdb",
|
@@ -192,15 +165,52 @@ module Dumpdb
|
|
192
165
|
end
|
193
166
|
|
194
167
|
should "be an Array" do
|
195
|
-
assert_kind_of ::Array,
|
168
|
+
assert_kind_of ::Array, CmdList.new
|
196
169
|
end
|
197
170
|
|
198
171
|
should "return the commands, eval'd and placeholders applied" do
|
199
|
-
val_cmds =
|
172
|
+
val_cmds = CmdList.new(@cmds).value(@script, @script.target.to_hash)
|
200
173
|
assert_equal @exp_val_cmds, val_cmds
|
201
174
|
end
|
202
175
|
|
203
176
|
end
|
204
177
|
|
178
|
+
class RemoteDumpCmdTests < UnitTests
|
179
|
+
desc "using ssh"
|
180
|
+
setup do
|
181
|
+
@script = RemoteScript.new
|
182
|
+
@cmd_str = Proc.new{ "echo hello" }
|
183
|
+
end
|
184
|
+
|
185
|
+
should "build the cmds to run remotely using ssh" do
|
186
|
+
exp = "ssh -A #{@script.ssh_opts} #{@script.ssh} \"echo hello\""
|
187
|
+
assert_equal exp, DumpCmd.new(@cmd_str).value(@script)
|
188
|
+
end
|
189
|
+
|
190
|
+
should "escape any double-quotes in the cmds" do
|
191
|
+
orig_cmd = "do_something --value=\"a_val\""
|
192
|
+
exp_esc_cmd = "do_something --value=\\\"a_val\\\""
|
193
|
+
|
194
|
+
exp = "ssh -A #{@script.ssh_opts} #{@script.ssh} \"#{exp_esc_cmd}\""
|
195
|
+
assert_equal exp, DumpCmd.new(Proc.new{ orig_cmd }).value(@script)
|
196
|
+
end
|
197
|
+
|
198
|
+
should "escape any backslashes in the cmds" do
|
199
|
+
orig_cmd = "do \\something"
|
200
|
+
exp_esc_cmd = "do \\\\something"
|
201
|
+
|
202
|
+
exp = "ssh -A #{@script.ssh_opts} #{@script.ssh} \"#{exp_esc_cmd}\""
|
203
|
+
assert_equal exp, DumpCmd.new(Proc.new{ orig_cmd }).value(@script)
|
204
|
+
end
|
205
|
+
|
206
|
+
should "escape any backslashes before double-quotes in the cmds" do
|
207
|
+
orig_cmd = "do \\something --value=\"a_val\""
|
208
|
+
exp_esc_cmd = "do \\\\something --value=\\\"a_val\\\""
|
209
|
+
|
210
|
+
exp = "ssh -A #{@script.ssh_opts} #{@script.ssh} \"#{exp_esc_cmd}\""
|
211
|
+
assert_equal exp, DumpCmd.new(Proc.new{ orig_cmd }).value(@script)
|
212
|
+
end
|
213
|
+
|
214
|
+
end
|
205
215
|
|
206
216
|
end
|
metadata
CHANGED
@@ -1,13 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dumpdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 2
|
8
|
-
- 0
|
9
|
-
- 0
|
10
|
-
version: 2.0.0
|
4
|
+
version: 2.1.0
|
11
5
|
platform: ruby
|
12
6
|
authors:
|
13
7
|
- Kelly Redding
|
@@ -16,61 +10,38 @@ autorequire:
|
|
16
10
|
bindir: bin
|
17
11
|
cert_chain: []
|
18
12
|
|
19
|
-
date:
|
13
|
+
date: 2016-06-14 00:00:00 Z
|
20
14
|
dependencies:
|
21
15
|
- !ruby/object:Gem::Dependency
|
16
|
+
name: assert
|
17
|
+
prerelease: false
|
22
18
|
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
-
none: false
|
24
19
|
requirements:
|
25
20
|
- - ~>
|
26
21
|
- !ruby/object:Gem::Version
|
27
|
-
|
28
|
-
segments:
|
29
|
-
- 2
|
30
|
-
- 15
|
31
|
-
version: "2.15"
|
22
|
+
version: 2.16.1
|
32
23
|
type: :development
|
33
|
-
name: assert
|
34
24
|
version_requirements: *id001
|
35
|
-
prerelease: false
|
36
25
|
- !ruby/object:Gem::Dependency
|
26
|
+
name: much-plugin
|
27
|
+
prerelease: false
|
37
28
|
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
-
none: false
|
39
29
|
requirements:
|
40
30
|
- - ~>
|
41
31
|
- !ruby/object:Gem::Version
|
42
|
-
|
43
|
-
segments:
|
44
|
-
- 3
|
45
|
-
- 0
|
46
|
-
version: "3.0"
|
32
|
+
version: 0.2.0
|
47
33
|
type: :runtime
|
48
|
-
name: scmd
|
49
34
|
version_requirements: *id002
|
50
|
-
prerelease: false
|
51
35
|
- !ruby/object:Gem::Dependency
|
36
|
+
name: scmd
|
37
|
+
prerelease: false
|
52
38
|
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
-
none: false
|
54
39
|
requirements:
|
55
40
|
- - ~>
|
56
41
|
- !ruby/object:Gem::Version
|
57
|
-
|
58
|
-
segments:
|
59
|
-
- 1
|
60
|
-
- 1
|
61
|
-
version: "1.1"
|
62
|
-
- - ">="
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
hash: 17
|
65
|
-
segments:
|
66
|
-
- 1
|
67
|
-
- 1
|
68
|
-
- 1
|
69
|
-
version: 1.1.1
|
42
|
+
version: 3.0.2
|
70
43
|
type: :runtime
|
71
|
-
name: ns-options
|
72
44
|
version_requirements: *id003
|
73
|
-
prerelease: false
|
74
45
|
description: Dump and restore your databases.
|
75
46
|
email:
|
76
47
|
- kelly@kellyredding.com
|
@@ -86,7 +57,6 @@ files:
|
|
86
57
|
- Gemfile
|
87
58
|
- LICENSE
|
88
59
|
- README.md
|
89
|
-
- Rakefile
|
90
60
|
- dumpdb.gemspec
|
91
61
|
- lib/dumpdb.rb
|
92
62
|
- lib/dumpdb/db.rb
|
@@ -99,12 +69,14 @@ files:
|
|
99
69
|
- test/support/fake_cmd_runner.rb
|
100
70
|
- test/support/test_scripts.rb
|
101
71
|
- test/unit/db_tests.rb
|
72
|
+
- test/unit/dumpdb_tests.rb
|
102
73
|
- test/unit/runner_tests.rb
|
103
|
-
- test/unit/script_tests.rb
|
104
74
|
- test/unit/settings_tests.rb
|
105
75
|
- tmp/.gitkeep
|
106
76
|
homepage: http://github.com/redding/dumpdb
|
107
|
-
licenses:
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
108
80
|
|
109
81
|
post_install_message:
|
110
82
|
rdoc_options: []
|
@@ -112,29 +84,20 @@ rdoc_options: []
|
|
112
84
|
require_paths:
|
113
85
|
- lib
|
114
86
|
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
-
none: false
|
116
87
|
requirements:
|
117
|
-
-
|
88
|
+
- &id004
|
89
|
+
- ">="
|
118
90
|
- !ruby/object:Gem::Version
|
119
|
-
hash: 3
|
120
|
-
segments:
|
121
|
-
- 0
|
122
91
|
version: "0"
|
123
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
-
none: false
|
125
93
|
requirements:
|
126
|
-
-
|
127
|
-
- !ruby/object:Gem::Version
|
128
|
-
hash: 3
|
129
|
-
segments:
|
130
|
-
- 0
|
131
|
-
version: "0"
|
94
|
+
- *id004
|
132
95
|
requirements: []
|
133
96
|
|
134
97
|
rubyforge_project:
|
135
|
-
rubygems_version:
|
98
|
+
rubygems_version: 2.6.4
|
136
99
|
signing_key:
|
137
|
-
specification_version:
|
100
|
+
specification_version: 4
|
138
101
|
summary: Dump and restore your databases.
|
139
102
|
test_files:
|
140
103
|
- test/helper.rb
|
@@ -142,6 +105,6 @@ test_files:
|
|
142
105
|
- test/support/fake_cmd_runner.rb
|
143
106
|
- test/support/test_scripts.rb
|
144
107
|
- test/unit/db_tests.rb
|
108
|
+
- test/unit/dumpdb_tests.rb
|
145
109
|
- test/unit/runner_tests.rb
|
146
|
-
- test/unit/script_tests.rb
|
147
110
|
- test/unit/settings_tests.rb
|
data/Rakefile
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require "bundler/gem_tasks"
|