dk-dumpdb 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,58 @@
1
+ require 'assert'
2
+ require 'dk-dumpdb/task/restore'
3
+
4
+ require 'test/support/task/internal_task'
5
+
6
+ class Dk::Dumpdb::Task::Restore
7
+
8
+ class UnitTests < Assert::Context
9
+ desc "Dk::Dumpdb::Task::Restore"
10
+ setup do
11
+ @task_class = Dk::Dumpdb::Task::Restore
12
+ end
13
+ subject{ @task_class}
14
+
15
+ should "be an internal task" do
16
+ assert_includes Dk::Dumpdb::Task::InternalTask, subject
17
+ end
18
+
19
+ should "know its description" do
20
+ exp = "(dk-dumpdb) run the given script's restore cmds"
21
+ assert_equal exp, subject.description
22
+ end
23
+
24
+ end
25
+
26
+ class InitTests < UnitTests
27
+ include Dk::Dumpdb::Task::InternalTask::TestHelpers
28
+
29
+ desc "when init"
30
+ setup do
31
+ now = Factory.time
32
+ Assert.stub(Time, :now){ now }
33
+
34
+ @restore_cmds = restore_cmds = Factory.integer(3).times.map{ Factory.string }
35
+ set_dk_dumpdb_script_param do
36
+ restore_cmds.each do |cmd_str|
37
+ restore{ cmd_str }
38
+ end
39
+ end
40
+ @runner = test_runner(@task_class, :params => @params)
41
+ end
42
+
43
+ end
44
+
45
+ class RunTests < InitTests
46
+ desc "and run"
47
+ setup do
48
+ @runner.run
49
+ end
50
+ subject{ @runner }
51
+
52
+ should "run all restore cmds" do
53
+ assert_equal @restore_cmds, subject.runs.map(&:cmd_str)
54
+ end
55
+
56
+ end
57
+
58
+ end
@@ -0,0 +1,60 @@
1
+ require 'assert'
2
+ require 'dk-dumpdb/task/setup'
3
+
4
+ require 'test/support/task/internal_task'
5
+
6
+ class Dk::Dumpdb::Task::Setup
7
+
8
+ class UnitTests < Assert::Context
9
+ desc "Dk::Dumpdb::Task::Setup"
10
+ setup do
11
+ @task_class = Dk::Dumpdb::Task::Setup
12
+ end
13
+ subject{ @task_class}
14
+
15
+ should "be an internal task" do
16
+ assert_includes Dk::Dumpdb::Task::InternalTask, subject
17
+ end
18
+
19
+ should "know its description" do
20
+ exp = "(dk-dumpdb) setup a script run"
21
+ assert_equal exp, subject.description
22
+ end
23
+
24
+ end
25
+
26
+ class InitTests < UnitTests
27
+ include Dk::Dumpdb::Task::InternalTask::TestHelpers
28
+
29
+ desc "when init"
30
+ setup do
31
+ now = Factory.time
32
+ Assert.stub(Time, :now){ now }
33
+
34
+ set_dk_dumpdb_script_param
35
+ @runner = test_runner(@task_class, :params => @params)
36
+ end
37
+
38
+ end
39
+
40
+ class RunTests < InitTests
41
+ desc "and run"
42
+ setup do
43
+ @runner.run
44
+ end
45
+ subject{ @runner }
46
+
47
+ should "run 2 cmds" do
48
+ assert_equal 2, subject.runs.size
49
+ mkdir_src, mkdir_targ = subject.runs
50
+
51
+ exp = @params['script'].dump_cmd{ "mkdir -p #{source.output_dir}" }
52
+ assert_equal exp, mkdir_src.cmd_str
53
+
54
+ exp = @params['script'].restore_cmd{ "mkdir -p #{target.output_dir}" }
55
+ assert_equal exp, mkdir_targ.cmd_str
56
+ end
57
+
58
+ end
59
+
60
+ end
@@ -0,0 +1,60 @@
1
+ require 'assert'
2
+ require 'dk-dumpdb/task/teardown'
3
+
4
+ require 'test/support/task/internal_task'
5
+
6
+ class Dk::Dumpdb::Task::Teardown
7
+
8
+ class UnitTests < Assert::Context
9
+ desc "Dk::Dumpdb::Task::Teardown"
10
+ setup do
11
+ @task_class = Dk::Dumpdb::Task::Teardown
12
+ end
13
+ subject{ @task_class}
14
+
15
+ should "be an internal task" do
16
+ assert_includes Dk::Dumpdb::Task::InternalTask, subject
17
+ end
18
+
19
+ should "know its description" do
20
+ exp = "(dk-dumpdb) teardown a script run"
21
+ assert_equal exp, subject.description
22
+ end
23
+
24
+ end
25
+
26
+ class InitTests < UnitTests
27
+ include Dk::Dumpdb::Task::InternalTask::TestHelpers
28
+
29
+ desc "when init"
30
+ setup do
31
+ now = Factory.time
32
+ Assert.stub(Time, :now){ now }
33
+
34
+ set_dk_dumpdb_script_param
35
+ @runner = test_runner(@task_class, :params => @params)
36
+ end
37
+
38
+ end
39
+
40
+ class RunTests < InitTests
41
+ desc "and run"
42
+ setup do
43
+ @runner.run
44
+ end
45
+ subject{ @runner }
46
+
47
+ should "run 2 cmds" do
48
+ assert_equal 2, subject.runs.size
49
+ rmdir_src, rmdir_targ = subject.runs
50
+
51
+ exp = @params['script'].dump_cmd{ "rm -rf #{source.output_dir}" }
52
+ assert_equal exp, rmdir_src.cmd_str
53
+
54
+ exp = @params['script'].restore_cmd{ "rm -rf #{target.output_dir}" }
55
+ assert_equal exp, rmdir_targ.cmd_str
56
+ end
57
+
58
+ end
59
+
60
+ end
@@ -0,0 +1,113 @@
1
+ require 'assert'
2
+ require 'dk-dumpdb/task'
3
+
4
+ require 'dk/task'
5
+ require 'much-plugin'
6
+ require 'dk-dumpdb/task/copy_dump'
7
+ require 'dk-dumpdb/task/dump'
8
+ require 'dk-dumpdb/task/restore'
9
+ require 'dk-dumpdb/task/setup'
10
+ require 'dk-dumpdb/task/teardown'
11
+
12
+ module Dk::Dumpdb::Task
13
+
14
+ class UnitTests < Assert::Context
15
+ desc "Dk::Dumpdb::Task"
16
+ subject{ Dk::Dumpdb::Task }
17
+
18
+ should "use much-plugin" do
19
+ assert_includes MuchPlugin, subject
20
+ end
21
+
22
+ end
23
+
24
+ class MixinTests < UnitTests
25
+ desc "mixin"
26
+ setup do
27
+ @task_class = Class.new do
28
+ include Dk::Dumpdb::Task
29
+
30
+ end
31
+ end
32
+ subject{ @task_class }
33
+
34
+ should have_imeths :script_class
35
+
36
+ should "be a Dk task" do
37
+ assert_includes Dk::Task, subject
38
+ end
39
+
40
+ should "know its script class" do
41
+ assert_nil subject.script_class
42
+
43
+ value = Factory.string
44
+ subject.script_class value
45
+
46
+ assert_equal value, subject.script_class
47
+ end
48
+
49
+ end
50
+
51
+ class InitTests < MixinTests
52
+ include Dk::Task::TestHelpers
53
+
54
+ desc "when init"
55
+ setup do
56
+ @runner = test_runner(@task_class)
57
+ @task = @runner.task
58
+ end
59
+ subject{ @task }
60
+
61
+ end
62
+
63
+ class RunTests < InitTests
64
+ desc "and run"
65
+ setup do
66
+ @task_class.script_class Factory.script_class
67
+
68
+ @script_init_with = nil
69
+ @script = @task_class.script_class.new
70
+ Assert.stub(@task_class.script_class, :new) do |*args|
71
+ @script_init_with = args
72
+ @script
73
+ end
74
+
75
+ @runner.run
76
+ end
77
+ subject{ @runner }
78
+
79
+ should "build an instance of its script class and run it" do
80
+ assert_equal 5, subject.runs.size
81
+
82
+ setup, dump, copydump, restore, teardown = subject.runs
83
+
84
+ assert_equal Setup, setup.task_class
85
+ assert_equal Dump, dump.task_class
86
+ assert_equal CopyDump, copydump.task_class
87
+ assert_equal Restore, restore.task_class
88
+ assert_equal Teardown, teardown.task_class
89
+
90
+ assert_equal [@runner.params], @script_init_with
91
+
92
+ subject.runs.each do |task_run|
93
+ assert_equal @script, task_run.params['script']
94
+ end
95
+ end
96
+
97
+ end
98
+
99
+ class TestHelpersTets < UnitTests
100
+ desc "TestHelpers"
101
+ setup do
102
+ @context_class = Class.new{ include Dk::Dumpdb::Task::TestHelpers }
103
+ @context = @context_class.new
104
+ end
105
+ subject{ @context }
106
+
107
+ should "include Dk task test helpers" do
108
+ assert_includes Dk::Task::TestHelpers, @context_class
109
+ end
110
+
111
+ end
112
+
113
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dk-dumpdb
3
- version: &id003 !ruby/object:Gem::Version
4
- version: 0.0.1
3
+ version: &id002 !ruby/object:Gem::Version
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Redding
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2016-07-28 00:00:00 Z
13
+ date: 2016-08-17 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: assert
@@ -19,26 +19,26 @@ dependencies:
19
19
  requirements:
20
20
  - - ~>
21
21
  - !ruby/object:Gem::Version
22
- version: 2.16.1
22
+ version: 2.16.3
23
23
  type: :development
24
24
  version_requirements: *id001
25
25
  - !ruby/object:Gem::Dependency
26
- name: much-plugin
26
+ name: dk
27
27
  prerelease: false
28
- requirement: &id002 !ruby/object:Gem::Requirement
28
+ requirement: &id003 !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - ~>
31
- - !ruby/object:Gem::Version
32
- version: 0.2.0
33
- type: :development
34
- version_requirements: *id002
31
+ - *id002
32
+ type: :runtime
33
+ version_requirements: *id003
35
34
  - !ruby/object:Gem::Dependency
36
- name: dk
35
+ name: much-plugin
37
36
  prerelease: false
38
37
  requirement: &id004 !ruby/object:Gem::Requirement
39
38
  requirements:
40
39
  - - ~>
41
- - *id003
40
+ - !ruby/object:Gem::Version
41
+ version: 0.2.0
42
42
  type: :runtime
43
43
  version_requirements: *id004
44
44
  description: Build Dk tasks to dump and restore your databases
@@ -58,10 +58,32 @@ files:
58
58
  - README.md
59
59
  - dk-dumpdb.gemspec
60
60
  - lib/dk-dumpdb.rb
61
+ - lib/dk-dumpdb/config.rb
62
+ - lib/dk-dumpdb/db.rb
63
+ - lib/dk-dumpdb/script.rb
64
+ - lib/dk-dumpdb/task.rb
65
+ - lib/dk-dumpdb/task/copy_dump.rb
66
+ - lib/dk-dumpdb/task/dump.rb
67
+ - lib/dk-dumpdb/task/internal_task.rb
68
+ - lib/dk-dumpdb/task/restore.rb
69
+ - lib/dk-dumpdb/task/setup.rb
70
+ - lib/dk-dumpdb/task/teardown.rb
61
71
  - lib/dk-dumpdb/version.rb
62
72
  - log/.gitkeep
63
73
  - test/helper.rb
64
74
  - test/support/factory.rb
75
+ - test/support/task/internal_task.rb
76
+ - test/unit/config_tests.rb
77
+ - test/unit/db_tests.rb
78
+ - test/unit/dk-dumpdb_tests.rb
79
+ - test/unit/script_tests.rb
80
+ - test/unit/task/copy_dump_tests.rb
81
+ - test/unit/task/dump_tests.rb
82
+ - test/unit/task/internal_task_tests.rb
83
+ - test/unit/task/restore_tests.rb
84
+ - test/unit/task/setup_tests.rb
85
+ - test/unit/task/teardown_tests.rb
86
+ - test/unit/task_tests.rb
65
87
  - tmp/.gitkeep
66
88
  homepage: http://github.com/redding/dk-dumpdb
67
89
  licenses:
@@ -92,3 +114,15 @@ summary: Build Dk tasks to dump and restore your databases
92
114
  test_files:
93
115
  - test/helper.rb
94
116
  - test/support/factory.rb
117
+ - test/support/task/internal_task.rb
118
+ - test/unit/config_tests.rb
119
+ - test/unit/db_tests.rb
120
+ - test/unit/dk-dumpdb_tests.rb
121
+ - test/unit/script_tests.rb
122
+ - test/unit/task/copy_dump_tests.rb
123
+ - test/unit/task/dump_tests.rb
124
+ - test/unit/task/internal_task_tests.rb
125
+ - test/unit/task/restore_tests.rb
126
+ - test/unit/task/setup_tests.rb
127
+ - test/unit/task/teardown_tests.rb
128
+ - test/unit/task_tests.rb