siba 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. data/.gitignore +7 -0
  2. data/Gemfile +4 -0
  3. data/Guardfile +18 -0
  4. data/LICENSE +22 -0
  5. data/README.md +47 -0
  6. data/Rakefile +27 -0
  7. data/bin/siba +5 -0
  8. data/lib/siba.rb +27 -0
  9. data/lib/siba/backup.rb +31 -0
  10. data/lib/siba/console.rb +196 -0
  11. data/lib/siba/errors.rb +8 -0
  12. data/lib/siba/generator.rb +115 -0
  13. data/lib/siba/globals.rb +19 -0
  14. data/lib/siba/helpers/encoding_helper.rb +38 -0
  15. data/lib/siba/helpers/file_helper.rb +89 -0
  16. data/lib/siba/helpers/gem_helper.rb +22 -0
  17. data/lib/siba/helpers/password_strength.rb +94 -0
  18. data/lib/siba/helpers/security_helper.rb +30 -0
  19. data/lib/siba/helpers/string_helper.rb +32 -0
  20. data/lib/siba/helpers/test/extend_test.rb +114 -0
  21. data/lib/siba/helpers/test/file_mock.rb +38 -0
  22. data/lib/siba/helpers/test/helper.rb +55 -0
  23. data/lib/siba/helpers/test/kernel_mock.rb +44 -0
  24. data/lib/siba/helpers/test/removable_constants.rb +18 -0
  25. data/lib/siba/helpers/test/require.rb +12 -0
  26. data/lib/siba/logger_plug.rb +36 -0
  27. data/lib/siba/options_backup.rb +37 -0
  28. data/lib/siba/options_loader.rb +38 -0
  29. data/lib/siba/plugins/archive/tar/archive.rb +117 -0
  30. data/lib/siba/plugins/archive/tar/init.rb +38 -0
  31. data/lib/siba/plugins/archive/tar/options.yml +1 -0
  32. data/lib/siba/plugins/destination/dir/dest_dir.rb +77 -0
  33. data/lib/siba/plugins/destination/dir/init.rb +31 -0
  34. data/lib/siba/plugins/destination/dir/options.yml +2 -0
  35. data/lib/siba/plugins/encryption/gpg/encryption.rb +140 -0
  36. data/lib/siba/plugins/encryption/gpg/init.rb +45 -0
  37. data/lib/siba/plugins/encryption/gpg/options.yml +2 -0
  38. data/lib/siba/plugins/installed_plugins.rb +77 -0
  39. data/lib/siba/plugins/plugin_loader.rb +100 -0
  40. data/lib/siba/plugins/plugins.rb +57 -0
  41. data/lib/siba/plugins/plugins.yml +9 -0
  42. data/lib/siba/plugins/source/files/files.rb +166 -0
  43. data/lib/siba/plugins/source/files/init.rb +33 -0
  44. data/lib/siba/plugins/source/files/options.yml +11 -0
  45. data/lib/siba/restore.rb +113 -0
  46. data/lib/siba/scaffold.rb +166 -0
  47. data/lib/siba/siba_check.rb +75 -0
  48. data/lib/siba/siba_file.rb +89 -0
  49. data/lib/siba/siba_kernel.rb +37 -0
  50. data/lib/siba/siba_logger.rb +172 -0
  51. data/lib/siba/tasks/siba_task.rb +42 -0
  52. data/lib/siba/tasks/siba_tasks.rb +120 -0
  53. data/lib/siba/test_files.rb +76 -0
  54. data/lib/siba/test_files/a_file +1 -0
  55. data/lib/siba/test_files/files_and_dirs/.hidden +1 -0
  56. data/lib/siba/test_files/files_and_dirs/.hidden_dir/file10 +1 -0
  57. data/lib/siba/test_files/files_and_dirs/File With Spaces +1 -0
  58. data/lib/siba/test_files/files_and_dirs/dir1/file10 +1 -0
  59. data/lib/siba/test_files/files_and_dirs/dir1/sub-dir/file111.txt +1 -0
  60. data/lib/siba/test_files/files_and_dirs/file1 +1 -0
  61. data/lib/siba/test_files/files_and_dirs/file2.txt +1 -0
  62. data/lib/siba/tmp_dir.rb +94 -0
  63. data/lib/siba/version.rb +5 -0
  64. data/scaffolds/archive.rb +26 -0
  65. data/scaffolds/destination.rb +20 -0
  66. data/scaffolds/encryption.rb +26 -0
  67. data/scaffolds/project/.gitignore +5 -0
  68. data/scaffolds/project/Gemfile +4 -0
  69. data/scaffolds/project/Guardfile +9 -0
  70. data/scaffolds/project/LICENSE +22 -0
  71. data/scaffolds/project/README.md +33 -0
  72. data/scaffolds/project/Rakefile +28 -0
  73. data/scaffolds/project/lib/siba-c6y-demo.rb +11 -0
  74. data/scaffolds/project/lib/siba-c6y-demo/options.yml +2 -0
  75. data/scaffolds/project/lib/siba-c6y-demo/version.rb +9 -0
  76. data/scaffolds/project/siba-c6y-demo.gemspec +26 -0
  77. data/scaffolds/project/test/helper/require_integration.rb +5 -0
  78. data/scaffolds/project/test/helper/require_unit.rb +4 -0
  79. data/scaffolds/project/test/integration/i9n_init.rb +35 -0
  80. data/scaffolds/project/test/unit/test_init.rb +43 -0
  81. data/scaffolds/project/test/unit/yml/valid.yml +8 -0
  82. data/scaffolds/shared/examples.rb +47 -0
  83. data/scaffolds/shared/init_example.rb +13 -0
  84. data/scaffolds/source.rb +25 -0
  85. data/siba.gemspec +30 -0
  86. data/test/helper/require_integration.rb +4 -0
  87. data/test/helper/require_unit.rb +4 -0
  88. data/test/integration/helpers/i9n_file_helper.rb +50 -0
  89. data/test/integration/i9n_backup.rb +53 -0
  90. data/test/integration/i9n_console.rb +16 -0
  91. data/test/integration/i9n_generator.rb +29 -0
  92. data/test/integration/i9n_options_backup.rb +22 -0
  93. data/test/integration/i9n_scaffold.rb +27 -0
  94. data/test/integration/i9n_siba_file.rb +30 -0
  95. data/test/integration/i9n_test_unicode_files.rb +40 -0
  96. data/test/integration/i9n_tmp_dir.rb +44 -0
  97. data/test/integration/plugins/archive/tar/i9n_archive.rb +18 -0
  98. data/test/integration/plugins/destination/dir/i9n_dest_dir.rb +52 -0
  99. data/test/integration/plugins/encryption/gpg/i9n_encryption.rb +87 -0
  100. data/test/integration/plugins/i9n_installed_plugins.rb +13 -0
  101. data/test/integration/plugins/source/files/i9n_files.rb +146 -0
  102. data/test/integration/tasks/i9n_siba_tasks.rb +30 -0
  103. data/test/integration/yml/valid.yml +16 -0
  104. data/test/unit/helpers/test_encoding_helper.rb +17 -0
  105. data/test/unit/helpers/test_gem_helper.rb +17 -0
  106. data/test/unit/helpers/test_security_helper.rb +21 -0
  107. data/test/unit/helpers/test_string_helper.rb +35 -0
  108. data/test/unit/plugins/archive/tar/test_archive.rb +41 -0
  109. data/test/unit/plugins/archive/tar/test_init.rb +36 -0
  110. data/test/unit/plugins/archive/tar/yml/archive/check_installed.yml +2 -0
  111. data/test/unit/plugins/archive/tar/yml/init/default_compression.yml +1 -0
  112. data/test/unit/plugins/archive/tar/yml/init/invalid_compression.yml +2 -0
  113. data/test/unit/plugins/archive/tar/yml/init/valid.yml +2 -0
  114. data/test/unit/plugins/destination/dir/test_dest_dir.rb +41 -0
  115. data/test/unit/plugins/destination/dir/test_init.rb +36 -0
  116. data/test/unit/plugins/destination/dir/yml/init/valid.yml +2 -0
  117. data/test/unit/plugins/encryption/gpg/test_encryption.rb +70 -0
  118. data/test/unit/plugins/encryption/gpg/test_init.rb +47 -0
  119. data/test/unit/plugins/source/files/test_files.rb +44 -0
  120. data/test/unit/plugins/source/files/test_init.rb +48 -0
  121. data/test/unit/plugins/source/files/test_path_match.rb +140 -0
  122. data/test/unit/plugins/source/files/yml/ignore_list.yml +8 -0
  123. data/test/unit/plugins/source/files/yml/ignore_not_array.yml +5 -0
  124. data/test/unit/plugins/source/files/yml/include_not_array.yml +3 -0
  125. data/test/unit/plugins/source/files/yml/include_subdirs_false.yml +6 -0
  126. data/test/unit/plugins/source/files/yml/include_subdirs_missing.yml +5 -0
  127. data/test/unit/plugins/source/files/yml/no_ignore.yml +4 -0
  128. data/test/unit/plugins/source/files/yml/no_include.yml +1 -0
  129. data/test/unit/plugins/source/files/yml/valid.yml +9 -0
  130. data/test/unit/plugins/test_installed_plugins.rb +32 -0
  131. data/test/unit/plugins/test_plugin_loader.rb +27 -0
  132. data/test/unit/plugins/test_plugins.rb +44 -0
  133. data/test/unit/tasks/test_siba_task.rb +30 -0
  134. data/test/unit/tasks/test_siba_tasks.rb +84 -0
  135. data/test/unit/tasks/yml/task/invalid.yml +4 -0
  136. data/test/unit/tasks/yml/task/valid.yml +7 -0
  137. data/test/unit/test_backup.rb +18 -0
  138. data/test/unit/test_console.rb +166 -0
  139. data/test/unit/test_generator.rb +21 -0
  140. data/test/unit/test_globals.rb +34 -0
  141. data/test/unit/test_log_message.rb +26 -0
  142. data/test/unit/test_logger_plug.rb +49 -0
  143. data/test/unit/test_options_backup.rb +21 -0
  144. data/test/unit/test_options_loader.rb +72 -0
  145. data/test/unit/test_password_strength.rb +76 -0
  146. data/test/unit/test_restore.rb +18 -0
  147. data/test/unit/test_scaffold.rb +26 -0
  148. data/test/unit/test_siba_check.rb +118 -0
  149. data/test/unit/test_siba_logger.rb +174 -0
  150. data/test/unit/test_tmp_dir.rb +21 -0
  151. data/test/unit/yml/options_loader/array.yml +2 -0
  152. data/test/unit/yml/options_loader/empty.yml +0 -0
  153. data/test/unit/yml/options_loader/invalid.yml +4 -0
  154. data/test/unit/yml/options_loader/string.yml +1 -0
  155. data/test/unit/yml/options_loader/utf8_with_bom.yml +2 -0
  156. data/test/unit/yml/options_loader/valid.yml +12 -0
  157. data/test/unit/yml/siba_options_backup.yml +20 -0
  158. data/test/unit/yml/valid.yml +18 -0
  159. metadata +240 -0
@@ -0,0 +1,17 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'helper/require_unit'
4
+
5
+ describe Siba::EncodingHelper do
6
+ before do
7
+ @str_arg = "str"
8
+ @array_arg = ["str1","str2",nil]
9
+ @result = "result"
10
+ end
11
+
12
+ it "should run encode_to_external" do
13
+ str = Siba::EncodingHelper.encode_to_external @str_arg
14
+ str.must_equal @str_arg
15
+ str.encoding.must_equal Siba::EncodingHelper::EXTERNAL_ENCODING
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'helper/require_unit'
4
+
5
+ describe Siba::GemHelper do
6
+ before do
7
+ @cls = Siba::GemHelper
8
+ end
9
+
10
+ it "should call all_local_gems" do
11
+ @cls.all_local_gems[0].must_be_instance_of Gem::Specification
12
+ end
13
+
14
+ it "should call gem_path" do
15
+ @cls.gem_path("rake").must_be_instance_of String
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'helper/require_unit'
4
+
5
+ describe Siba::SecurityHelper do
6
+ before do
7
+ @sh = Siba::SecurityHelper
8
+ end
9
+
10
+ it "should generate password for yaml" do
11
+ @sh.generate_password_for_yaml.length.must_equal 16
12
+ @sh.generate_password_for_yaml(8).length.must_equal 8
13
+ end
14
+
15
+ it "should generate alphanumeric password" do
16
+ @sh.alphanumeric_password.length.must_equal 16
17
+ @sh.alphanumeric_password(9).length.must_equal 9
18
+ @sh.alphanumeric_password(9, true)
19
+ @sh.alphanumeric_password(9, true, true)
20
+ end
21
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'helper/require_unit'
4
+
5
+ describe Siba::StringHelper do
6
+ before do
7
+ @sh = Siba::StringHelper
8
+ end
9
+
10
+ it "must call str_to_alphnumeric" do
11
+ @sh.str_to_alphnumeric("Hello world").must_equal "hello-world"
12
+ @sh.str_to_alphnumeric(" hello ").must_equal "hello"
13
+ @sh.str_to_alphnumeric('hello`~!@#$%^&*()":<>?/-=[]{}world').must_equal "hello-world"
14
+ @sh.str_to_alphnumeric('one . two three').must_equal "one-two-three"
15
+ @sh.str_to_alphnumeric('one#$%').must_equal "one"
16
+ @sh.str_to_alphnumeric('#$%').must_equal ""
17
+ end
18
+
19
+ it "must camelize" do
20
+ @sh.camelize("test").must_equal "Test"
21
+ @sh.camelize("another_test_str").must_equal "AnotherTestStr"
22
+ @sh.camelize("another-test-str").must_equal "AnotherTestStr"
23
+ end
24
+
25
+ it "should call escape_for_yaml" do
26
+ str = 'test\one"two'
27
+ value = @sh.escape_for_yaml(str)
28
+ reloaded = YAML.load("key: \"#{value}\"")
29
+ reloaded["key"].must_equal str
30
+ end
31
+
32
+ it "should call format_time" do
33
+ @sh.format_time(Time.now).must_be_instance_of String
34
+ end
35
+ end
@@ -0,0 +1,41 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'helper/require_unit'
4
+ require 'siba/plugins/archive/tar/init'
5
+
6
+ describe Siba::Archive::Tar::Init do
7
+ before do
8
+ @yml_path = File.expand_path('../yml/archive', __FILE__)
9
+ end
10
+
11
+ it "should create archive and run check_installed" do
12
+ fmock = mock_file :run_this, true, ["test installed"]
13
+ archive = Siba::Archive::Tar::Archive.new "gzip"
14
+ fmock.verify
15
+ end
16
+
17
+ it "should run archive" do
18
+ file_name = "file"
19
+ dest_dir = "/dir"
20
+
21
+ Siba::Archive::Tar::Archive.new("none")
22
+ .archive("",dest_dir,file_name)
23
+ .must_match /^#{file_name}\.tar$/
24
+
25
+ Siba::Archive::Tar::Archive.new("gzip")
26
+ .archive("",dest_dir,file_name)
27
+ .must_match /^#{file_name}\.tar.gz$/
28
+
29
+ Siba::Archive::Tar::Archive.new("bzip2")
30
+ .archive("",dest_dir,file_name)
31
+ .must_match /^#{file_name}\.tar.bz2$/
32
+ end
33
+
34
+ it "should run extract" do
35
+ Siba::Archive::Tar::Archive.new("gzip").extract("/path_to_archive","/dest_dir")
36
+ end
37
+
38
+ it "backup should fail" do
39
+ ->{Siba::Archive::Tar::Archive.new("incorrect").archive("","","")}.must_raise Siba::CheckError
40
+ end
41
+ end
@@ -0,0 +1,36 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'helper/require_unit'
4
+ require 'siba/plugins/archive/tar/init'
5
+
6
+ describe Siba::Archive::Tar::Init do
7
+ before do
8
+ @yml_path = File.expand_path('../yml/init', __FILE__)
9
+ @plugin_category="archive"
10
+ @plugin_type="tar"
11
+ end
12
+
13
+ it "should load" do
14
+ archive = create_plugin("valid")
15
+ archive.archive.compression.must_be_instance_of String
16
+ end
17
+
18
+ it "init should raise error if compression is incorrect" do
19
+ ->{create_plugin("invalid_compression")}.must_raise Siba::CheckError
20
+ end
21
+
22
+ it "init should use default compression if undefined in options" do
23
+ archive = create_plugin("default_compression")
24
+ archive.archive.compression.must_equal Siba::Archive::Tar::DefaultCompression
25
+ end
26
+
27
+ it "should run backup" do
28
+ archive = create_plugin("valid")
29
+ archive.backup("/src-dir", "/dst-dir", "file_name").must_be_instance_of String
30
+ end
31
+
32
+ it "should run restore" do
33
+ archive = create_plugin("valid")
34
+ archive.restore "/path-to-archive", "/to_dir"
35
+ end
36
+ end
@@ -0,0 +1,2 @@
1
+ type: tar
2
+ compression: gzip
@@ -0,0 +1,2 @@
1
+ type: tar
2
+ compression: incorrect
@@ -0,0 +1,2 @@
1
+ type: tar
2
+ compression: gzip
@@ -0,0 +1,41 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'helper/require_unit'
4
+ require 'siba/plugins/destination/dir/init'
5
+
6
+ describe Siba::Destination::Dir::DestDir do
7
+ before do
8
+ @dir = "/some-dir"
9
+ @cls = Siba::Destination::Dir::DestDir
10
+ end
11
+
12
+ it "should init" do
13
+ @cls.new @dir
14
+ end
15
+
16
+ it "should access dir" do
17
+ dest_dir = @cls.new @dir
18
+ dest_dir.dir = @dir
19
+ dest_dir.dir.must_equal @dir
20
+ end
21
+
22
+ it "init should test access to destination dir" do
23
+ dest_dir = @cls.new @dir
24
+ dest_dir.test_dir_access
25
+ end
26
+
27
+ it "should call copy_backup_to_dest" do
28
+ dest_dir = @cls.new @dir
29
+ dest_dir.copy_backup_to_dest "/backup"
30
+ end
31
+
32
+ it "should call restore_backup_to_dir" do
33
+ dest_dir = @cls.new @dir
34
+ dest_dir.restore_backup_to_dir "name", "/backup"
35
+ end
36
+
37
+ it "should call get_backup_dir" do
38
+ dest_dir = @cls.new @dir
39
+ dest_dir.get_backups_list "my"
40
+ end
41
+ end
@@ -0,0 +1,36 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'helper/require_unit'
4
+ require 'siba/plugins/destination/dir/init'
5
+
6
+ describe Siba::Destination::Dir::Init do
7
+ before do
8
+ @yml_path = File.expand_path('../yml/init', __FILE__)
9
+ @plugin_category="destination"
10
+ @plugin_type="dir"
11
+ end
12
+
13
+ it "should load" do
14
+ plugin = create_plugin("valid")
15
+ plugin.dest_dir.must_be_instance_of Siba::Destination::Dir::DestDir
16
+ end
17
+
18
+ it "load should fail when dir is missing" do
19
+ ->{create_plugin({})}.must_raise Siba::CheckError
20
+ ->{create_plugin({"dir" => nil})}.must_raise Siba::CheckError
21
+ ->{create_plugin({"dir" => ""})}.must_raise Siba::CheckError
22
+ ->{create_plugin({"dir" => " "})}.must_raise Siba::CheckError
23
+ end
24
+
25
+ it "should call backup" do
26
+ create_plugin("valid").backup "backup"
27
+ end
28
+
29
+ it "should call restore" do
30
+ create_plugin("valid").restore "backup", "/dir"
31
+ end
32
+
33
+ it "should call get_backups_list" do
34
+ create_plugin("valid").get_backups_list "bak"
35
+ end
36
+ end
@@ -0,0 +1,2 @@
1
+ type: dir
2
+ dir: /somedir
@@ -0,0 +1,70 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'helper/require_unit'
4
+ require 'siba/plugins/encryption/gpg/init'
5
+
6
+ describe Siba::Encryption::Gpg::Encryption do
7
+ before do
8
+ @passphrase = "aj(dJ6Hja2Jj$kjask"
9
+ end
10
+
11
+ it "init should call test_encryption" do
12
+ fmock = mock_file :run_this, nil, ["test_encryption"]
13
+ Siba::Encryption::Gpg::Encryption.new(@passphrase)
14
+ fmock.verify
15
+ end
16
+
17
+ it "init should call check_cipher" do
18
+ fmock = mock_file :run_this, nil, ["check_cipher"]
19
+ Siba::Encryption::Gpg::Encryption.new(@passphrase)
20
+ fmock.verify
21
+ end
22
+
23
+ it "must call encrypt" do
24
+ encryption = Siba::Encryption::Gpg::Encryption.new(@passphrase)
25
+ path_to_archive = "/path/to/archive.tar.gz"
26
+ path_to_encrypted_file = encryption.encrypt(path_to_archive)
27
+ path_to_encrypted_file.must_equal "#{path_to_archive}.gpg"
28
+ end
29
+
30
+ it "must call decrypt" do
31
+ encryption = Siba::Encryption::Gpg::Encryption.new(@passphrase)
32
+ path = "/path/to/archive.tar.gz"
33
+ path_to_decrypted_file = encryption.decrypt(path + ".gpg")
34
+ path_to_decrypted_file.must_equal path
35
+ end
36
+
37
+ it "must call decrypt with output file parameter" do
38
+ encryption = Siba::Encryption::Gpg::Encryption.new(@passphrase)
39
+ path = "/path/to/archive.tar.gz.gz"
40
+ output = "/output.file"
41
+ path_to_decrypted_file = encryption.decrypt(path + ".gpg", output)
42
+ path_to_decrypted_file.must_equal output
43
+ end
44
+
45
+ it "parse_cipher_names must work" do
46
+ parse_data = [
47
+ ["text \n Cipher: a, b,\nc,d", ["A","B","C","D"]],
48
+ ["text \n Cipher: a, b,\nc,d\nHash: a, b, c", ["A","B","C","D"]]
49
+ ]
50
+ parse_data.each do |a|
51
+ Siba::Encryption::Gpg::Encryption.parse_cipher_names(a[0]).must_equal a[1]
52
+ end
53
+ end
54
+
55
+ it "init must warn if the password is weak" do
56
+ Siba::Encryption::Gpg::Encryption.new "passwordisweak"
57
+ must_log "warn"
58
+ end
59
+
60
+ it "init must NOT warn if the password is strong" do
61
+ Siba::Encryption::Gpg::Encryption.new "A4n90!1j$Ox*"
62
+ wont_log "warn"
63
+ end
64
+
65
+ it "must call test_encryption" do
66
+ encryption = Siba::Encryption::Gpg::Encryption.new(@passphrase)
67
+ encryption.test_encryption
68
+ end
69
+
70
+ end
@@ -0,0 +1,47 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'helper/require_unit'
4
+ require 'siba/plugins/encryption/gpg/init'
5
+
6
+ describe Siba::Encryption::Gpg::Init do
7
+ before do
8
+ @plugin_category="encryption"
9
+ @plugin_type="gpg"
10
+ @options = {'passphrase' => "my pass word", "cipher" => "AES256"}
11
+ end
12
+
13
+ it "must init plugin" do
14
+ plugin = create_plugin(@options)
15
+ plugin.encryption.wont_be_nil
16
+ plugin.encryption.passphrase.wont_be_nil
17
+ plugin.encryption.cipher.wont_be_nil
18
+ plugin.encryption.passphrase.must_equal @options["passphrase"]
19
+ plugin.encryption.cipher.must_equal @options["cipher"]
20
+ end
21
+
22
+ it "must init with missing" do
23
+ plugin = create_plugin({'passphrase'=>'pass'})
24
+ plugin.encryption.cipher.must_be_nil
25
+ end
26
+
27
+ it "must init with numeric passphrase" do
28
+ plugin = create_plugin({'passphrase'=>123})
29
+ plugin.encryption.passphrase.must_equal "123"
30
+ end
31
+
32
+ it "init must fail if empty passphrase" do
33
+ ->{create_plugin({'passphrase' => nil})}.must_raise Siba::CheckError
34
+ ->{create_plugin({'passphrase' => ""})}.must_raise Siba::CheckError
35
+ ->{create_plugin({'passphrase' => " "})}.must_raise Siba::CheckError
36
+ end
37
+
38
+ it "must call backup" do
39
+ plugin = create_plugin(@options)
40
+ plugin.backup("/path/to/archive", "/dest_dir").must_be_instance_of String
41
+ end
42
+
43
+ it "must call restore" do
44
+ plugin = create_plugin(@options)
45
+ plugin.restore("/path/to/backup", "/dest_dir").must_be_instance_of String
46
+ end
47
+ end
@@ -0,0 +1,44 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'helper/require_unit'
4
+ require 'siba/plugins/source/files/init'
5
+
6
+ describe Siba::Source::Files::Files do
7
+ before do
8
+ @f = Siba::Source::Files::Files
9
+ end
10
+ it "ignored? must NOT log if no files are excluded" do
11
+ @f.new([], [], true).ignored?("/.hidden")
12
+ wont_log "info"
13
+ end
14
+
15
+ it "ignored? must log if files are excluded" do
16
+ @f.new([], ["*"], true).ignored?("/.hidden")
17
+ must_log "info"
18
+ end
19
+
20
+ it "should call backup" do
21
+ @f.new([], [], true).backup "/dest-dir"
22
+ end
23
+
24
+ it "should call copy_file" do
25
+ @f.new([], [], true).copy_file "/src", "/dst"
26
+ end
27
+
28
+ it "should call copy_dir" do
29
+ @f.new([], [], true).copy_dir "/src", "/dst", true
30
+ end
31
+
32
+ it "should call sub_dir_name" do
33
+ @f.sub_dir_name(1, 1, true, "/dir1/dir2/file","/root").must_equal "/root/1-file-file"
34
+ @f.sub_dir_name(1, 2, false, "/dir1/dir2/file","/root").must_equal "/root/01-dir-file"
35
+ @f.sub_dir_name(23, 1, false, "/dir1/dir2/file","/root").must_equal "/root/23-dir-file"
36
+ @f.sub_dir_name(12, 3, true, "/dir1/dir2/file","/root").must_equal "/root/012-file-file"
37
+ @f.sub_dir_name(5, 3, true, "/dir1/dir2/file","/root").must_equal "/root/005-file-file"
38
+ @f.sub_dir_name(3, 2, false, "/","/root").must_equal "/root/03-dir-root"
39
+ end
40
+
41
+ it "should call restore" do
42
+ @f.new([], [], true).restore "/from-dir"
43
+ end
44
+ end
@@ -0,0 +1,48 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'helper/require_unit'
4
+ require 'siba/plugins/source/files/init'
5
+
6
+ describe Siba::Source::Files::Init 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 load" do
14
+ create_plugin("valid").files.ignore.must_be_instance_of Array
15
+ end
16
+
17
+ it "load should fail no include" do
18
+ -> {create_plugin("no_include")}.must_raise Siba::CheckError
19
+ end
20
+
21
+ it "load should fail include is not array" do
22
+ -> {create_plugin("include_not_array")}.must_raise Siba::CheckError
23
+ end
24
+
25
+ it "should load ignore list" do
26
+ create_plugin("valid").files.ignore.must_be_instance_of Array
27
+ end
28
+
29
+ it "load should fail ignore is not array" do
30
+ -> {create_plugin("ignore_not_array")}.must_raise Siba::CheckError
31
+ end
32
+
33
+ it "should load include_subdirs=true when it is missing in options" do
34
+ create_plugin("include_subdirs_missing").files.include_subdirs.must_equal true
35
+ end
36
+
37
+ it "should load include_subdirs=false" do
38
+ create_plugin("include_subdirs_false").files.include_subdirs.must_equal false
39
+ end
40
+
41
+ it "backup should copy file" do
42
+ create_plugin("valid").backup "dir"
43
+ end
44
+
45
+ it "should call restore" do
46
+ create_plugin("valid").restore "/from_dir"
47
+ end
48
+ end