siba 0.4.3
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.
- data/.gitignore +7 -0
- data/Gemfile +4 -0
- data/Guardfile +18 -0
- data/LICENSE +22 -0
- data/README.md +47 -0
- data/Rakefile +27 -0
- data/bin/siba +5 -0
- data/lib/siba.rb +27 -0
- data/lib/siba/backup.rb +31 -0
- data/lib/siba/console.rb +196 -0
- data/lib/siba/errors.rb +8 -0
- data/lib/siba/generator.rb +115 -0
- data/lib/siba/globals.rb +19 -0
- data/lib/siba/helpers/encoding_helper.rb +38 -0
- data/lib/siba/helpers/file_helper.rb +89 -0
- data/lib/siba/helpers/gem_helper.rb +22 -0
- data/lib/siba/helpers/password_strength.rb +94 -0
- data/lib/siba/helpers/security_helper.rb +30 -0
- data/lib/siba/helpers/string_helper.rb +32 -0
- data/lib/siba/helpers/test/extend_test.rb +114 -0
- data/lib/siba/helpers/test/file_mock.rb +38 -0
- data/lib/siba/helpers/test/helper.rb +55 -0
- data/lib/siba/helpers/test/kernel_mock.rb +44 -0
- data/lib/siba/helpers/test/removable_constants.rb +18 -0
- data/lib/siba/helpers/test/require.rb +12 -0
- data/lib/siba/logger_plug.rb +36 -0
- data/lib/siba/options_backup.rb +37 -0
- data/lib/siba/options_loader.rb +38 -0
- data/lib/siba/plugins/archive/tar/archive.rb +117 -0
- data/lib/siba/plugins/archive/tar/init.rb +38 -0
- data/lib/siba/plugins/archive/tar/options.yml +1 -0
- data/lib/siba/plugins/destination/dir/dest_dir.rb +77 -0
- data/lib/siba/plugins/destination/dir/init.rb +31 -0
- data/lib/siba/plugins/destination/dir/options.yml +2 -0
- data/lib/siba/plugins/encryption/gpg/encryption.rb +140 -0
- data/lib/siba/plugins/encryption/gpg/init.rb +45 -0
- data/lib/siba/plugins/encryption/gpg/options.yml +2 -0
- data/lib/siba/plugins/installed_plugins.rb +77 -0
- data/lib/siba/plugins/plugin_loader.rb +100 -0
- data/lib/siba/plugins/plugins.rb +57 -0
- data/lib/siba/plugins/plugins.yml +9 -0
- data/lib/siba/plugins/source/files/files.rb +166 -0
- data/lib/siba/plugins/source/files/init.rb +33 -0
- data/lib/siba/plugins/source/files/options.yml +11 -0
- data/lib/siba/restore.rb +113 -0
- data/lib/siba/scaffold.rb +166 -0
- data/lib/siba/siba_check.rb +75 -0
- data/lib/siba/siba_file.rb +89 -0
- data/lib/siba/siba_kernel.rb +37 -0
- data/lib/siba/siba_logger.rb +172 -0
- data/lib/siba/tasks/siba_task.rb +42 -0
- data/lib/siba/tasks/siba_tasks.rb +120 -0
- data/lib/siba/test_files.rb +76 -0
- data/lib/siba/test_files/a_file +1 -0
- data/lib/siba/test_files/files_and_dirs/.hidden +1 -0
- data/lib/siba/test_files/files_and_dirs/.hidden_dir/file10 +1 -0
- data/lib/siba/test_files/files_and_dirs/File With Spaces +1 -0
- data/lib/siba/test_files/files_and_dirs/dir1/file10 +1 -0
- data/lib/siba/test_files/files_and_dirs/dir1/sub-dir/file111.txt +1 -0
- data/lib/siba/test_files/files_and_dirs/file1 +1 -0
- data/lib/siba/test_files/files_and_dirs/file2.txt +1 -0
- data/lib/siba/tmp_dir.rb +94 -0
- data/lib/siba/version.rb +5 -0
- data/scaffolds/archive.rb +26 -0
- data/scaffolds/destination.rb +20 -0
- data/scaffolds/encryption.rb +26 -0
- data/scaffolds/project/.gitignore +5 -0
- data/scaffolds/project/Gemfile +4 -0
- data/scaffolds/project/Guardfile +9 -0
- data/scaffolds/project/LICENSE +22 -0
- data/scaffolds/project/README.md +33 -0
- data/scaffolds/project/Rakefile +28 -0
- data/scaffolds/project/lib/siba-c6y-demo.rb +11 -0
- data/scaffolds/project/lib/siba-c6y-demo/options.yml +2 -0
- data/scaffolds/project/lib/siba-c6y-demo/version.rb +9 -0
- data/scaffolds/project/siba-c6y-demo.gemspec +26 -0
- data/scaffolds/project/test/helper/require_integration.rb +5 -0
- data/scaffolds/project/test/helper/require_unit.rb +4 -0
- data/scaffolds/project/test/integration/i9n_init.rb +35 -0
- data/scaffolds/project/test/unit/test_init.rb +43 -0
- data/scaffolds/project/test/unit/yml/valid.yml +8 -0
- data/scaffolds/shared/examples.rb +47 -0
- data/scaffolds/shared/init_example.rb +13 -0
- data/scaffolds/source.rb +25 -0
- data/siba.gemspec +30 -0
- data/test/helper/require_integration.rb +4 -0
- data/test/helper/require_unit.rb +4 -0
- data/test/integration/helpers/i9n_file_helper.rb +50 -0
- data/test/integration/i9n_backup.rb +53 -0
- data/test/integration/i9n_console.rb +16 -0
- data/test/integration/i9n_generator.rb +29 -0
- data/test/integration/i9n_options_backup.rb +22 -0
- data/test/integration/i9n_scaffold.rb +27 -0
- data/test/integration/i9n_siba_file.rb +30 -0
- data/test/integration/i9n_test_unicode_files.rb +40 -0
- data/test/integration/i9n_tmp_dir.rb +44 -0
- data/test/integration/plugins/archive/tar/i9n_archive.rb +18 -0
- data/test/integration/plugins/destination/dir/i9n_dest_dir.rb +52 -0
- data/test/integration/plugins/encryption/gpg/i9n_encryption.rb +87 -0
- data/test/integration/plugins/i9n_installed_plugins.rb +13 -0
- data/test/integration/plugins/source/files/i9n_files.rb +146 -0
- data/test/integration/tasks/i9n_siba_tasks.rb +30 -0
- data/test/integration/yml/valid.yml +16 -0
- data/test/unit/helpers/test_encoding_helper.rb +17 -0
- data/test/unit/helpers/test_gem_helper.rb +17 -0
- data/test/unit/helpers/test_security_helper.rb +21 -0
- data/test/unit/helpers/test_string_helper.rb +35 -0
- data/test/unit/plugins/archive/tar/test_archive.rb +41 -0
- data/test/unit/plugins/archive/tar/test_init.rb +36 -0
- data/test/unit/plugins/archive/tar/yml/archive/check_installed.yml +2 -0
- data/test/unit/plugins/archive/tar/yml/init/default_compression.yml +1 -0
- data/test/unit/plugins/archive/tar/yml/init/invalid_compression.yml +2 -0
- data/test/unit/plugins/archive/tar/yml/init/valid.yml +2 -0
- data/test/unit/plugins/destination/dir/test_dest_dir.rb +41 -0
- data/test/unit/plugins/destination/dir/test_init.rb +36 -0
- data/test/unit/plugins/destination/dir/yml/init/valid.yml +2 -0
- data/test/unit/plugins/encryption/gpg/test_encryption.rb +70 -0
- data/test/unit/plugins/encryption/gpg/test_init.rb +47 -0
- data/test/unit/plugins/source/files/test_files.rb +44 -0
- data/test/unit/plugins/source/files/test_init.rb +48 -0
- data/test/unit/plugins/source/files/test_path_match.rb +140 -0
- data/test/unit/plugins/source/files/yml/ignore_list.yml +8 -0
- data/test/unit/plugins/source/files/yml/ignore_not_array.yml +5 -0
- data/test/unit/plugins/source/files/yml/include_not_array.yml +3 -0
- data/test/unit/plugins/source/files/yml/include_subdirs_false.yml +6 -0
- data/test/unit/plugins/source/files/yml/include_subdirs_missing.yml +5 -0
- data/test/unit/plugins/source/files/yml/no_ignore.yml +4 -0
- data/test/unit/plugins/source/files/yml/no_include.yml +1 -0
- data/test/unit/plugins/source/files/yml/valid.yml +9 -0
- data/test/unit/plugins/test_installed_plugins.rb +32 -0
- data/test/unit/plugins/test_plugin_loader.rb +27 -0
- data/test/unit/plugins/test_plugins.rb +44 -0
- data/test/unit/tasks/test_siba_task.rb +30 -0
- data/test/unit/tasks/test_siba_tasks.rb +84 -0
- data/test/unit/tasks/yml/task/invalid.yml +4 -0
- data/test/unit/tasks/yml/task/valid.yml +7 -0
- data/test/unit/test_backup.rb +18 -0
- data/test/unit/test_console.rb +166 -0
- data/test/unit/test_generator.rb +21 -0
- data/test/unit/test_globals.rb +34 -0
- data/test/unit/test_log_message.rb +26 -0
- data/test/unit/test_logger_plug.rb +49 -0
- data/test/unit/test_options_backup.rb +21 -0
- data/test/unit/test_options_loader.rb +72 -0
- data/test/unit/test_password_strength.rb +76 -0
- data/test/unit/test_restore.rb +18 -0
- data/test/unit/test_scaffold.rb +26 -0
- data/test/unit/test_siba_check.rb +118 -0
- data/test/unit/test_siba_logger.rb +174 -0
- data/test/unit/test_tmp_dir.rb +21 -0
- data/test/unit/yml/options_loader/array.yml +2 -0
- data/test/unit/yml/options_loader/empty.yml +0 -0
- data/test/unit/yml/options_loader/invalid.yml +4 -0
- data/test/unit/yml/options_loader/string.yml +1 -0
- data/test/unit/yml/options_loader/utf8_with_bom.yml +2 -0
- data/test/unit/yml/options_loader/valid.yml +12 -0
- data/test/unit/yml/siba_options_backup.yml +20 -0
- data/test/unit/yml/valid.yml +18 -0
- metadata +240 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'helper/require_unit'
|
|
4
|
+
require 'siba/plugins/source/files/init'
|
|
5
|
+
|
|
6
|
+
describe Siba::Source::Files do
|
|
7
|
+
before do
|
|
8
|
+
@yml_path = File.expand_path('../yml', __FILE__)
|
|
9
|
+
@plugin_category="source"
|
|
10
|
+
@plugin_type="files"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "should call path_match?" do
|
|
14
|
+
Siba::Source::Files::Files.path_match? "file", "include"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "must match path" do
|
|
18
|
+
match_list = [
|
|
19
|
+
# ----------------------
|
|
20
|
+
# compare basenames
|
|
21
|
+
["file", "/file"],
|
|
22
|
+
# sub-dirs
|
|
23
|
+
["file", "/dir/dir/file"],
|
|
24
|
+
["file.ext", "/dir/dir/file.ext"],
|
|
25
|
+
# white space
|
|
26
|
+
["file", " /file "],
|
|
27
|
+
[" file ", "/file"],
|
|
28
|
+
# case
|
|
29
|
+
["file", "/FILE"],
|
|
30
|
+
["FILE", "/file"],
|
|
31
|
+
|
|
32
|
+
# ----------------------
|
|
33
|
+
# match basenames against pattern
|
|
34
|
+
["*.tmp", "/file.tmp"],
|
|
35
|
+
["*.jpg", "/.hidden.jpg"],
|
|
36
|
+
["*.tmp", "/dir/file.tmp"],
|
|
37
|
+
[".*", "/.hidden"],
|
|
38
|
+
[".*", "/dir/.hidden"],
|
|
39
|
+
[".*", "/dir/dir/.hidden"],
|
|
40
|
+
# white space
|
|
41
|
+
[" *.tmp ", "/file.tmp"],
|
|
42
|
+
["*.tmp", " /file.tmp "],
|
|
43
|
+
# case
|
|
44
|
+
["*.TMP", "/file.tmp"],
|
|
45
|
+
["*.tmp", "/File.TMP "],
|
|
46
|
+
|
|
47
|
+
# ----------------------
|
|
48
|
+
# match whole path against pattern
|
|
49
|
+
["/root/dir1/file", "/root/dir1/file"],
|
|
50
|
+
["/.*", "/.hidden/file"],
|
|
51
|
+
["*/file", "/dir/file"],
|
|
52
|
+
["*file", "/file"],
|
|
53
|
+
["*file", "/dir/file"],
|
|
54
|
+
["**file", "/dir/file"],
|
|
55
|
+
["**/file", "/root/dir/file"],
|
|
56
|
+
["/file*", "/file"],
|
|
57
|
+
["/file*", "/file_one"],
|
|
58
|
+
["/file*", "/file_one/two"],
|
|
59
|
+
["/file*", "/file_one/two/three"],
|
|
60
|
+
["/file**", "/file"],
|
|
61
|
+
["/file**", "/file_one"],
|
|
62
|
+
["/file**", "/file_one/two"],
|
|
63
|
+
["/file**", "/file_one/two/three"],
|
|
64
|
+
["/dir/*", "/dir/two/three"],
|
|
65
|
+
["**/dir/**", "/root/one/dir/two/file"],
|
|
66
|
+
["*", "/name"],
|
|
67
|
+
["*", "/dir1/dir2/file"],
|
|
68
|
+
["**", "/dir1/dir2/file"],
|
|
69
|
+
["/*", "/name"],
|
|
70
|
+
["/*", "/name/another"],
|
|
71
|
+
# white space
|
|
72
|
+
[" **/dir/** ", "/root/one/dir/two/file"],
|
|
73
|
+
["**/dir/**", " /root/one/dir/two/file "],
|
|
74
|
+
# case
|
|
75
|
+
[" **/DIR/** ", "/root/one/dir/two/file"],
|
|
76
|
+
["**/dir/**", "/ROOT/ONE/DIR/TWO/FILE"],
|
|
77
|
+
]
|
|
78
|
+
|
|
79
|
+
match_list.each do |item|
|
|
80
|
+
pattern = item[0]
|
|
81
|
+
file = item[1]
|
|
82
|
+
unless Siba::Source::Files::Files.path_match?(pattern, file)
|
|
83
|
+
flunk "'#{pattern}' pattern must match '#{file}' path"
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "must NOT match" do
|
|
89
|
+
must_not_match_list = [
|
|
90
|
+
# ----------------------
|
|
91
|
+
# compare basenames
|
|
92
|
+
["file", "/somefile"],
|
|
93
|
+
["file", "/.file"],
|
|
94
|
+
["file", "/file/somefile"],
|
|
95
|
+
["file", "/file/file/somefile"],
|
|
96
|
+
["file", "/file_file"],
|
|
97
|
+
["file", "/file_file/.file"],
|
|
98
|
+
["file", "/file.ext"],
|
|
99
|
+
["ext", "/file.ext"],
|
|
100
|
+
[".ext", "/file.ext"],
|
|
101
|
+
|
|
102
|
+
# ----------------------
|
|
103
|
+
# match basenames against pattern
|
|
104
|
+
["name*", "/somename"],
|
|
105
|
+
|
|
106
|
+
# ----------------------
|
|
107
|
+
# match whole path against pattern
|
|
108
|
+
[".*", "/.hidden/file"],
|
|
109
|
+
["*.ext", "/dir/name.ext/file"],
|
|
110
|
+
["*name", "/dir1/dir2/name/file"],
|
|
111
|
+
["dir", "/dir1/dir/file"],
|
|
112
|
+
["dir", "/dir/name/file"],
|
|
113
|
+
["dir/name", "/name"],
|
|
114
|
+
["dir/name", "/root/dir/name"],
|
|
115
|
+
["/file*", "/root/file"],
|
|
116
|
+
["/file/*", "/file"],
|
|
117
|
+
]
|
|
118
|
+
|
|
119
|
+
must_not_match_list.each do |item|
|
|
120
|
+
pattern = item[0]
|
|
121
|
+
file = item[1]
|
|
122
|
+
if Siba::Source::Files::Files.path_match?(pattern, file)
|
|
123
|
+
flunk "'#{pattern}' pattern must NOT match '#{file}' path"
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
it "ingored? should be false with no ignore data" do
|
|
129
|
+
create_plugin("no_ignore").files.ignored?("file").must_equal false
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
it "ingored? should respect ignore list" do
|
|
133
|
+
task = create_plugin("ignore_list").files
|
|
134
|
+
task.ignored?("/file").must_equal false
|
|
135
|
+
task.ignored?("/file1").must_equal true
|
|
136
|
+
task.ignored?("/file2").must_equal true
|
|
137
|
+
task.ignored?("/.hidden").must_equal true
|
|
138
|
+
task.ignored?("/dir/file").must_equal false
|
|
139
|
+
end
|
|
140
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
type: files
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#cagegory encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'helper/require_unit'
|
|
4
|
+
|
|
5
|
+
describe Siba::InstalledPlugins do
|
|
6
|
+
before do
|
|
7
|
+
@cls = Siba::InstalledPlugins
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should call all_installed" do
|
|
11
|
+
@cls.all_installed.must_be_instance_of Hash
|
|
12
|
+
@cls.all_installed.wont_be_empty
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should call installed?" do
|
|
16
|
+
@cls.installed?("source", "files").must_equal true
|
|
17
|
+
@cls.installed?("source", "unknown").must_equal false
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should return plugin path" do
|
|
21
|
+
@cls.plugin_path("source", "files")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "plugin_path should fail is plugin is not installed" do
|
|
25
|
+
->{@cls.plugin_path("source", "unknown")}.must_raise Siba::Error
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "should get gem name" do
|
|
29
|
+
@cls.gem_name("source", "files").must_be_instance_of String
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'helper/require_unit'
|
|
4
|
+
|
|
5
|
+
describe Siba::LogMessage do
|
|
6
|
+
before do
|
|
7
|
+
@loader = Siba::PluginLoader.loader
|
|
8
|
+
@options = {"type"=>"tar"}
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "should load plugin" do
|
|
12
|
+
@loader.load "archive", "tar", @options
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should fail when plugin name is incorrect" do
|
|
16
|
+
->{@loader.load "incorrect", "tar", @options}.must_raise Siba::PluginLoadError
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should fail when plugin type is unknown" do
|
|
21
|
+
->{@loader.load "archive", "incorrect", @options}.must_raise Siba::PluginLoadError
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "should fail when options are incorrect" do
|
|
25
|
+
->{@loader.load "archive", "tar", "incorrect options"}.must_raise Siba::PluginLoadError
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'helper/require_unit'
|
|
4
|
+
|
|
5
|
+
describe Siba::Plugins do
|
|
6
|
+
before do
|
|
7
|
+
@obj = Siba::Plugins
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should get CATEGORIES" do
|
|
11
|
+
@obj::CATEGORIES.must_be_instance_of Array
|
|
12
|
+
@obj::CATEGORIES.must_include "source"
|
|
13
|
+
@obj::CATEGORIES.must_include "archive"
|
|
14
|
+
@obj::CATEGORIES.must_include "encryption"
|
|
15
|
+
@obj::CATEGORIES.must_include "destination"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "should call categories_str" do
|
|
19
|
+
@obj.categories_str.wont_be_empty
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "should call get_list" do
|
|
23
|
+
@obj.get_list.wont_be_empty
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "should call plugin_description" do
|
|
27
|
+
@obj.plugin_description("destination", "dir").wont_be_empty
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "plugin_description should fail if uncorrect plugin name" do
|
|
31
|
+
->{@obj.plugin_description("destination", "unknown")}.must_raise Siba::Error
|
|
32
|
+
->{@obj.plugin_description("unknown", "dir")}.must_raise Siba::Error
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "should call plugin_type_and_description" do
|
|
36
|
+
@obj.plugin_type_and_description("destination", "dir", 20).wont_be_empty
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "should call category_and_type_correct?" do
|
|
40
|
+
@obj.category_and_type_correct?("destination", "dir").must_equal true
|
|
41
|
+
@obj.category_and_type_correct?("destination", "incorrect").must_equal false
|
|
42
|
+
@obj.category_and_type_correct?("incorrect", "dir").must_equal false
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'helper/require_unit'
|
|
4
|
+
|
|
5
|
+
describe Siba::SibaTask do
|
|
6
|
+
before do
|
|
7
|
+
@yml_path = File.expand_path('../yml/task', __FILE__)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should load task with NO sub-tasks" do
|
|
11
|
+
task_category = "archive"
|
|
12
|
+
options = load_options "valid"
|
|
13
|
+
new_task = Siba::SibaTask.new options, task_category
|
|
14
|
+
new_task.wont_be_nil
|
|
15
|
+
new_task.plugin.wont_be_nil
|
|
16
|
+
new_task.category.must_equal task_category
|
|
17
|
+
new_task.type.must_equal "tar"
|
|
18
|
+
new_task.options.must_equal options[task_category]
|
|
19
|
+
wont_log "error"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "should raise errors" do
|
|
23
|
+
options = load_options "valid"
|
|
24
|
+
->{Siba::SibaTask.new options, "unknown"}.must_raise Siba::CheckError
|
|
25
|
+
|
|
26
|
+
options = load_options "invalid"
|
|
27
|
+
->{Siba::SibaTask.new options, "invalid"}.must_raise Siba::CheckError
|
|
28
|
+
->{Siba::SibaTask.new options, "archive"}.must_raise Siba::PluginLoadError
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'helper/require_unit'
|
|
4
|
+
|
|
5
|
+
describe Siba::SibaTasks do
|
|
6
|
+
before do
|
|
7
|
+
@yml_path = File.expand_path('../../yml/', __FILE__)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should load tasks" do
|
|
11
|
+
create_tasks "valid"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
it "should get tasks" do
|
|
16
|
+
siba_tasks = create_tasks "valid"
|
|
17
|
+
siba_tasks.tasks["source"].must_be_instance_of Siba::SibaTask
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should backup on all tasks" do
|
|
21
|
+
create_tasks("valid").backup
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "should call restore" do
|
|
25
|
+
create_tasks("valid").restore "backup_name"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "should call get_backups_list" do
|
|
29
|
+
create_tasks("valid").get_backups_list
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "should return correct backup name" do
|
|
33
|
+
st = Siba::SibaTasks
|
|
34
|
+
Siba.backup_name = "siba"
|
|
35
|
+
|
|
36
|
+
# Monthly backup on the 1st day of each month
|
|
37
|
+
st.backup_name(Time.new 2012, 1, 1).must_equal "siba-month-01"
|
|
38
|
+
st.backup_name(Time.new 2012, 12, 1).must_equal "siba-month-12"
|
|
39
|
+
|
|
40
|
+
# Weekly backup on Sunday
|
|
41
|
+
st.backup_name(Time.new 2012, 1, 8).must_equal "siba-week-2-sun"
|
|
42
|
+
st.backup_name(Time.new 2012, 1, 15).must_equal "siba-week-3-sun"
|
|
43
|
+
st.backup_name(Time.new 2012, 1, 22).must_equal "siba-week-4-sun"
|
|
44
|
+
st.backup_name(Time.new 2012, 1, 29).must_equal "siba-week-5-sun"
|
|
45
|
+
st.backup_name(Time.new 2012, 2, 5).must_equal "siba-week-1-sun"
|
|
46
|
+
|
|
47
|
+
# Daily backup
|
|
48
|
+
st.backup_name(Time.new 2012, 1, 2).must_equal "siba-day-2-mon"
|
|
49
|
+
st.backup_name(Time.new 2012, 1, 3).must_equal "siba-day-3-tue"
|
|
50
|
+
st.backup_name(Time.new 2012, 1, 4).must_equal "siba-day-4-wed"
|
|
51
|
+
st.backup_name(Time.new 2012, 1, 5).must_equal "siba-day-5-thu"
|
|
52
|
+
st.backup_name(Time.new 2012, 1, 6).must_equal "siba-day-6-fri"
|
|
53
|
+
st.backup_name(Time.new 2012, 1, 7).must_equal "siba-day-7-sat"
|
|
54
|
+
st.backup_name(Time.new 2012, 1, 9).must_equal "siba-day-2-mon"
|
|
55
|
+
|
|
56
|
+
Siba.backup_name = "cuba"
|
|
57
|
+
st.backup_name(Time.new 2012, 1, 9).must_equal "cuba-day-2-mon"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "backup name should raise error is Siba.backup_name is not set" do
|
|
61
|
+
st = Siba::SibaTasks
|
|
62
|
+
Siba.backup_name = nil
|
|
63
|
+
->{st.backup_name(Time.new 2012, 1, 9)}.must_raise Siba::Error
|
|
64
|
+
|
|
65
|
+
Siba.backup_name = " "
|
|
66
|
+
->{st.backup_name(Time.new 2012, 1, 9)}.must_raise Siba::Error
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "should init tasks but skip source" do
|
|
70
|
+
options = load_options "valid"
|
|
71
|
+
tasks = Siba::SibaTasks.new options, File.join(@yml_path, "valid.yml"), false
|
|
72
|
+
tasks.tasks["source"].wont_be_nil
|
|
73
|
+
|
|
74
|
+
tasks = Siba::SibaTasks.new options, File.join(@yml_path, "valid.yml"), true
|
|
75
|
+
tasks.tasks["source"].must_be_nil
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
private
|
|
79
|
+
|
|
80
|
+
def create_tasks(yml_file_name)
|
|
81
|
+
options = load_options yml_file_name
|
|
82
|
+
Siba::SibaTasks.new options, File.join(@yml_path, "#{yml_file_name}.yml"), false
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'helper/require_unit'
|
|
4
|
+
|
|
5
|
+
describe Siba::Backup do
|
|
6
|
+
before do
|
|
7
|
+
@yml_path = File.expand_path('../yml', __FILE__)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should call restore" do
|
|
11
|
+
Siba::LoggerPlug.close
|
|
12
|
+
Siba::SibaLogger.quiet = true
|
|
13
|
+
path_to_options_file = File.join @yml_path, "valid.yml"
|
|
14
|
+
Siba::Backup.new.backup path_to_options_file, nil
|
|
15
|
+
wont_log_from "warn"
|
|
16
|
+
Siba.tmp_dir_clean?.must_equal true
|
|
17
|
+
end
|
|
18
|
+
end
|