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,35 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'helper/require_integration'
|
|
4
|
+
require 'siba-c6y-demo/init'
|
|
5
|
+
|
|
6
|
+
# Integration test example
|
|
7
|
+
# 'rake test:i9n' command runs integration tests
|
|
8
|
+
describe Siba::C6y::Demo::Init do
|
|
9
|
+
it "should run integration test" do
|
|
10
|
+
# All file operations will work normally in integration tests
|
|
11
|
+
# You can use the following helper methods
|
|
12
|
+
|
|
13
|
+
# Get path to test tmp dir (will be cleaned automatically after each test)
|
|
14
|
+
SibaTest.tmp_dir
|
|
15
|
+
|
|
16
|
+
# Make a sub dir with a random name in a test tmp dir
|
|
17
|
+
tmp_sub_dir = mkdir_in_tmp_dir "prefix"
|
|
18
|
+
|
|
19
|
+
# Copy the test file to tmp dir (siba/lib/siba/test_files/a_file)
|
|
20
|
+
path_to_test_file = prepare_test_file "prefix"
|
|
21
|
+
|
|
22
|
+
# Copy the test dir to tmp dir (siba/lib/siba/test_files/files_and_dirs)
|
|
23
|
+
path_to_test_dir = prepare_test_dir "prefix"
|
|
24
|
+
path_to_test_dir2 = prepare_test_dir "prefix"
|
|
25
|
+
|
|
26
|
+
# Compare dirs recursively
|
|
27
|
+
dirs_same? path_to_test_dir, path_to_test_dir2
|
|
28
|
+
|
|
29
|
+
# Read test yml and replace values (see siba/test/integration/yml/valid.yml)
|
|
30
|
+
# path_to_options = prepare_options path_to_yml,
|
|
31
|
+
# { src_dir: path_to_test_dir,
|
|
32
|
+
# src_file: path_to_test_file,
|
|
33
|
+
# dest_dir: path_to_test_dir2 }
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'helper/require_unit'
|
|
4
|
+
require 'siba-c6y-demo/init'
|
|
5
|
+
|
|
6
|
+
# Unit test example
|
|
7
|
+
# 'rake' command runs unit tests
|
|
8
|
+
# 'guard' command will run unit tests automatically
|
|
9
|
+
describe Siba::C6y::Demo do
|
|
10
|
+
before do
|
|
11
|
+
@yml_path = File.expand_path('../yml', __FILE__)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "should load plugin" do
|
|
15
|
+
# helper to load options from YAML from @yml_path dir
|
|
16
|
+
options_hash = load_options "valid"
|
|
17
|
+
|
|
18
|
+
plugin = Siba::C6y::Demo::Init.new options_hash
|
|
19
|
+
plugin.must_be_instance_of Siba::C6y::Demo::Init
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "siba should load plugin" do
|
|
23
|
+
# helper to load the plugin by siba (build and install demo gem to make it work)
|
|
24
|
+
# @plugin_category = "c6y"
|
|
25
|
+
# @plugin_type = "demo"
|
|
26
|
+
# plugin = create_plugin "valid"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "should check log" do
|
|
30
|
+
# ... code
|
|
31
|
+
# must_log "info"
|
|
32
|
+
# wont_log "warn"
|
|
33
|
+
# wont_log_from "warn"
|
|
34
|
+
# show_log
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "should verify file operations" do
|
|
38
|
+
# fmock = mock_file(:file_directory?, true, ["Path"])
|
|
39
|
+
# fmock.expect(:file_utils_cd, nil, ["/dir"])
|
|
40
|
+
# ... code
|
|
41
|
+
# fmock.verify
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Examples:
|
|
2
|
+
#
|
|
3
|
+
# -- Logging --
|
|
4
|
+
# "logger" object is available after including Siba::LoggerPlug
|
|
5
|
+
logger.debug "Detailed information shown in 'verbose' mode and in log file"
|
|
6
|
+
logger.info "Useful information about current operation"
|
|
7
|
+
logger.warn "A warning"
|
|
8
|
+
logger.error "A handleable error message"
|
|
9
|
+
raise Siba::Error, "An unhandleable error. It will be caught at the upper level and logged." if false
|
|
10
|
+
|
|
11
|
+
# -- File operations --
|
|
12
|
+
# "siba_file" object is available after including Siba::FilePlug
|
|
13
|
+
# You can use it for file operations
|
|
14
|
+
# instead of calling Dir, File, FileUtils directly.
|
|
15
|
+
# It mocks all methods of these classes in unit tests
|
|
16
|
+
# but runs them normally and in integration tests.
|
|
17
|
+
current_dir = siba_file.dir_pwd # for Dir.pwd
|
|
18
|
+
dir = siba_file.file_directory? current_dir #for File.directory?
|
|
19
|
+
siba_file.file_utils_cd dir #for FileUtils.cd
|
|
20
|
+
siba_file.run_this do
|
|
21
|
+
# The block will not be run during unit tests
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# These methods can be used directly as they do not access file system
|
|
25
|
+
File.join "a","b"
|
|
26
|
+
File.basename "a"
|
|
27
|
+
File.dirname "a"
|
|
28
|
+
|
|
29
|
+
# Helpers to run shell commands (wont be run in unit tests)
|
|
30
|
+
siba_file.shell_ok? "cd ."
|
|
31
|
+
output = siba_file.run_shell "git help"
|
|
32
|
+
|
|
33
|
+
# -- Temporary dirs and files --
|
|
34
|
+
# Use Siba.tmp_dir to store temporary files
|
|
35
|
+
tmp_dir = Siba.tmp_dir
|
|
36
|
+
|
|
37
|
+
# Create a sub-dir with a random name in the temp dir
|
|
38
|
+
path_to_tmp_dir = Siba::TestFiles.mkdir_in_tmp_dir "you_dir_prefix"
|
|
39
|
+
|
|
40
|
+
# Note: Siba.tmp_dir will be removed automatically,
|
|
41
|
+
# so there is no need to clean anything.
|
|
42
|
+
|
|
43
|
+
# Some Siba::FileHelper methods
|
|
44
|
+
files_and_dirs = Siba::FileHelper.entries current_dir
|
|
45
|
+
my_file = File.join tmp_dir, "myfile"
|
|
46
|
+
Siba::FileHelper.write my_file, "Write UTF-8 text"
|
|
47
|
+
Siba::FileHelper.read my_file
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# The backup is started after all plugins are initialized
|
|
2
|
+
# Therefore, this is a good place to do some checking (access, shell commands etc.)
|
|
3
|
+
# to make sure everything works before backup is started
|
|
4
|
+
|
|
5
|
+
# Examples:
|
|
6
|
+
#
|
|
7
|
+
# Load and validate options
|
|
8
|
+
key = Siba::SibaCheck.options_string options, "key"
|
|
9
|
+
key2 = Siba::SibaCheck.options_string options, "missing", true, "default value"
|
|
10
|
+
array = Siba::SibaCheck.options_string_array options, "array"
|
|
11
|
+
bool = Siba::SibaCheck.options_bool options, "bool"
|
|
12
|
+
Siba.settings # Gets the global app settings (value of "settings" key in YAML file)
|
|
13
|
+
raise Siba::Error, "Something wrong" if false
|
data/scaffolds/source.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
module Siba::C6y
|
|
4
|
+
module Demo
|
|
5
|
+
class Init
|
|
6
|
+
include Siba::FilePlug
|
|
7
|
+
include Siba::LoggerPlug
|
|
8
|
+
|
|
9
|
+
def initialize(options)
|
|
10
|
+
## init_example.rb ##
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Collect source files and put them into dest_dir
|
|
14
|
+
# No return value is expected
|
|
15
|
+
def backup(dest_dir)
|
|
16
|
+
## examples.rb ##
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Restore source files from_dir
|
|
20
|
+
# No return value is expected
|
|
21
|
+
def restore(from_dir)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
data/siba.gemspec
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
3
|
+
require "siba/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = "siba"
|
|
7
|
+
s.version = Siba::VERSION
|
|
8
|
+
s.authors = ["Evgeny Neumerzhitskiy"]
|
|
9
|
+
s.email = ["sausageskin@gmail.com"]
|
|
10
|
+
s.homepage = ""
|
|
11
|
+
s.summary = %q{Simple backup and restore utility.}
|
|
12
|
+
s.description = %q{This is a backup and restore utility. SIBA implements backup rotation scheme. It retains a one year history of backups by keeping up to 23 files: 6 daily, 5 weekly and 12 monthly backups. Backups are compressed and encrypted. Various backup sources and destinations can be added through extension gems.}
|
|
13
|
+
|
|
14
|
+
s.rubyforge_project = "siba"
|
|
15
|
+
|
|
16
|
+
s.files = `git ls-files`.split("\n")
|
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
19
|
+
s.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
s.required_rubygems_version = '~>1.8'
|
|
22
|
+
|
|
23
|
+
s.add_development_dependency 'minitest', '~>2.10'
|
|
24
|
+
s.add_development_dependency 'rake', '~>0.9'
|
|
25
|
+
s.add_development_dependency 'guard-minitest', '~>0.4'
|
|
26
|
+
|
|
27
|
+
# specify any dependencies here; for example:
|
|
28
|
+
# s.add_development_dependency "rspec"
|
|
29
|
+
# s.add_runtime_dependency "rest-client"
|
|
30
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'helper/require_integration'
|
|
4
|
+
|
|
5
|
+
describe Siba::FileHelper do
|
|
6
|
+
before do
|
|
7
|
+
@obj = Siba::FileHelper
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should call dir_empty?" do
|
|
11
|
+
test_dir = prepare_test_dir "dir-not-empty"
|
|
12
|
+
@obj.dir_empty?(test_dir).must_equal false
|
|
13
|
+
|
|
14
|
+
empty_test_dir = mkdir_in_tmp_dir "dir-empty"
|
|
15
|
+
@obj.dir_empty?(empty_test_dir).must_equal true
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "should call entries" do
|
|
19
|
+
test_dir = prepare_test_dir "dir-not-empty"
|
|
20
|
+
entries_to_compare = siba_file.dir_entries(test_dir) - %w{ . .. }
|
|
21
|
+
entries = @obj.entries test_dir
|
|
22
|
+
entries.wont_be_empty
|
|
23
|
+
entries.must_equal entries_to_compare
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "should call dirs_count" do
|
|
27
|
+
test_dir = prepare_test_dir "dir-not-empty"
|
|
28
|
+
dirs_count = @obj.dirs_count test_dir
|
|
29
|
+
dirs_count.must_equal 2
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "should call dirs_same?" do
|
|
33
|
+
test_dir1 = prepare_test_dir "dirs-same-1"
|
|
34
|
+
test_dir2 = prepare_test_dir "dirs-same-2"
|
|
35
|
+
@obj.dirs_same? test_dir1, test_dir2
|
|
36
|
+
|
|
37
|
+
# add a file to one dir
|
|
38
|
+
new_file1 = prepare_test_file "unexpected", test_dir2
|
|
39
|
+
->{@obj.dirs_same? test_dir1, test_dir2}.must_raise Siba::Error
|
|
40
|
+
|
|
41
|
+
# add the file to the other dir
|
|
42
|
+
siba_file.file_utils_cp new_file1, test_dir1
|
|
43
|
+
new_file2 = File.join test_dir1, File.basename(new_file1)
|
|
44
|
+
@obj.dirs_same? test_dir1, test_dir2
|
|
45
|
+
|
|
46
|
+
# change a file in one dir
|
|
47
|
+
siba_file.file_open(new_file2,"a") {|a| a.write("new text")}
|
|
48
|
+
->{@obj.dirs_same? test_dir1, test_dir2}.must_raise Siba::Error
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'helper/require_integration'
|
|
4
|
+
|
|
5
|
+
describe Siba::Backup do
|
|
6
|
+
before do
|
|
7
|
+
@yml_path = File.expand_path '../yml', __FILE__
|
|
8
|
+
@path_to_src_yml = File.join @yml_path, "valid.yml"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "should run backup and restore" do
|
|
12
|
+
Siba::LoggerPlug.close
|
|
13
|
+
Siba::SibaLogger.quiet = true
|
|
14
|
+
|
|
15
|
+
src_dir = prepare_test_dir "bf-src-dir"
|
|
16
|
+
src_file = prepare_test_file "bf-src-file"
|
|
17
|
+
dest_dir = mkdir_in_tmp_dir "bf-dest-dir"
|
|
18
|
+
|
|
19
|
+
test_yml_path = prepare_yml @path_to_src_yml,
|
|
20
|
+
{ src_dir: src_dir,
|
|
21
|
+
src_file: src_file,
|
|
22
|
+
dest_dir: dest_dir }
|
|
23
|
+
|
|
24
|
+
log_file = File.join File.dirname(test_yml_path), "testlog.log"
|
|
25
|
+
|
|
26
|
+
# Test backup
|
|
27
|
+
Siba::Backup.new.backup test_yml_path, log_file
|
|
28
|
+
Siba::FileHelper.entries(dest_dir).find{|a| a =~ /\.gpg$/}.wont_be_nil
|
|
29
|
+
siba_file.file_file?(log_file).must_equal true, "Must create log file"
|
|
30
|
+
Siba.tmp_dir_clean?.must_equal true, "Tmp dir must be cleaned"
|
|
31
|
+
Siba::LoggerPlug.opened?.must_equal false, "Logger must be closed"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# Test restore
|
|
35
|
+
sources_copy_dir = mkdir_in_tmp_dir "source-copy"
|
|
36
|
+
FileUtils.mv src_dir, sources_copy_dir
|
|
37
|
+
path_to_dir_copy = File.join sources_copy_dir, File.basename(src_dir)
|
|
38
|
+
FileUtils.mv src_file, sources_copy_dir
|
|
39
|
+
path_to_file_copy = File.join sources_copy_dir, File.basename(src_file)
|
|
40
|
+
File.directory?(src_dir).must_equal false
|
|
41
|
+
File.file?(src_file).must_equal false
|
|
42
|
+
|
|
43
|
+
Siba::SibaLogger.quiet = true
|
|
44
|
+
SibaTest::KernelMock.gets_return_value = "yes"
|
|
45
|
+
Siba::Restore.new.restore test_yml_path
|
|
46
|
+
|
|
47
|
+
File.directory?(src_dir).must_equal true
|
|
48
|
+
File.file?(src_file).must_equal true
|
|
49
|
+
dirs_same? src_dir, path_to_dir_copy
|
|
50
|
+
FileUtils.compare_file(src_file, path_to_file_copy).must_equal true
|
|
51
|
+
wont_log_from "warn"
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'helper/require_integration'
|
|
4
|
+
|
|
5
|
+
describe Siba::Console do
|
|
6
|
+
before do
|
|
7
|
+
@console = Siba::Console.new true
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should call generate command" do
|
|
11
|
+
SibaTest::KernelMock.gets_return_value = "1"
|
|
12
|
+
path_to_yml = generate_path("gen") + ".yml"
|
|
13
|
+
@console.parse ["generate", path_to_yml]
|
|
14
|
+
Siba::FileHelper.read(path_to_yml).wont_be_empty
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'helper/require_integration'
|
|
4
|
+
|
|
5
|
+
describe Siba::Generator do
|
|
6
|
+
before do
|
|
7
|
+
SibaTest::KernelMock.gets_return_value = "1"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should create generator" do
|
|
11
|
+
test_file = generate_path "gen"
|
|
12
|
+
@obj = Siba::Generator.new test_file
|
|
13
|
+
path_to_yml = @obj.generate
|
|
14
|
+
Siba::FileHelper.read(path_to_yml).wont_be_empty
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "generator should fail if file exists" do
|
|
18
|
+
path = generate_path "gen"
|
|
19
|
+
path = "#{path}.yml"
|
|
20
|
+
FileUtils.touch path
|
|
21
|
+
File.file?(path).must_equal true
|
|
22
|
+
@obj = Siba::Generator.new path
|
|
23
|
+
->{@obj.generate}.must_raise Siba::Error
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "should call get_plugin_yaml_path" do
|
|
27
|
+
Siba::Generator.get_plugin_yaml_path("source", "files").wont_be_empty
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'helper/require_integration'
|
|
4
|
+
|
|
5
|
+
describe Siba::OptionsBackup do
|
|
6
|
+
before do
|
|
7
|
+
@cls = Siba::OptionsBackup
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should save options backup" do
|
|
11
|
+
new_curret_dir = "change_current_dir"
|
|
12
|
+
Siba.current_dir = new_curret_dir
|
|
13
|
+
yml_path = File.expand_path "../yml", __FILE__
|
|
14
|
+
options_path = File.join yml_path, "valid.yml"
|
|
15
|
+
source_dir = mkdir_in_tmp_dir "sob"
|
|
16
|
+
@cls.save_options_backup options_path, source_dir
|
|
17
|
+
options_backup_path = File.join source_dir, Siba::OptionsBackup::OPTIONS_BACKUP_FILE_NAME
|
|
18
|
+
@yml_path = source_dir
|
|
19
|
+
options = load_options Siba::OptionsBackup::OPTIONS_BACKUP_FILE_NAME
|
|
20
|
+
options["current_dir"].must_equal new_curret_dir
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'helper/require_integration'
|
|
4
|
+
|
|
5
|
+
describe Siba::Scaffold do
|
|
6
|
+
before do
|
|
7
|
+
@gem_name = "myname"
|
|
8
|
+
@obj = Siba::Scaffold.new "destination", @gem_name
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "should run scaffold" do
|
|
12
|
+
Siba::LoggerPlug.close
|
|
13
|
+
Siba::SibaLogger.quiet = true
|
|
14
|
+
|
|
15
|
+
dest_dir = mkdir_in_tmp_dir "scf-d"
|
|
16
|
+
Siba::FileHelper.dir_empty?(dest_dir).must_equal true
|
|
17
|
+
@obj.scaffold dest_dir
|
|
18
|
+
Siba::FileHelper.dir_empty?(dest_dir).must_equal false
|
|
19
|
+
dest_dir = File.join dest_dir, @gem_name
|
|
20
|
+
File.directory?(dest_dir).must_equal true
|
|
21
|
+
Siba::FileHelper.dirs_count(dest_dir).must_be :>, 1
|
|
22
|
+
git_dir = File.join dest_dir, ".git"
|
|
23
|
+
File.directory?(git_dir).must_equal true, "Must create git repository"
|
|
24
|
+
wont_log_from "warn"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'helper/require_integration'
|
|
4
|
+
|
|
5
|
+
describe Siba::Backup do
|
|
6
|
+
before do
|
|
7
|
+
@siba_file = Siba::SibaFile.new
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should fail if incorrect" do
|
|
11
|
+
->{@siba_file.unknown}.must_raise NoMethodError
|
|
12
|
+
->{@siba_file.file_unknown}.must_raise NoMethodError
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should run file_expand_path" do
|
|
16
|
+
dirname = "dir/ep"
|
|
17
|
+
one = @siba_file.file_expand_path(dirname)
|
|
18
|
+
two = @siba_file.file_expand_path(dirname)
|
|
19
|
+
three = @siba_file.file_expand_path(dirname)
|
|
20
|
+
one.must_equal File.expand_path(dirname), "Should show absolute path"
|
|
21
|
+
two.must_equal File.expand_path(dirname), "Should show absolute path"
|
|
22
|
+
three.must_equal File.expand_path(dirname), "Should show absolute path"
|
|
23
|
+
@siba_file.file_expand_path("~/#{dirname}").must_equal File.expand_path("~/#{dirname}"), "Path relative to home folder"
|
|
24
|
+
tmp_dir = mkdir_in_tmp_dir "f-e-p"
|
|
25
|
+
Siba.current_dir = tmp_dir
|
|
26
|
+
tmp_dir2 = mkdir_in_tmp_dir "f-e-p2"
|
|
27
|
+
siba_file.file_utils_cd tmp_dir2
|
|
28
|
+
@siba_file.file_expand_path("#{dirname}").must_equal File.join(tmp_dir,dirname), "Path relative to Siba.current_dir"
|
|
29
|
+
end
|
|
30
|
+
end
|