kanrisuru 0.10.0 → 0.12.1
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.
- checksums.yaml +4 -4
- data/.github/CONTRIBUTING.md +9 -9
- data/.github/ISSUE_TEMPLATE/bug_report.md +7 -8
- data/.rspec +1 -1
- data/CHANGELOG.md +127 -102
- data/CODE_OF_CONDUCT.md +10 -10
- data/README.md +19 -90
- data/kanrisuru.gemspec +2 -1
- data/lib/kanrisuru/command.rb +7 -0
- data/lib/kanrisuru/core/archive.rb +11 -35
- data/lib/kanrisuru/core/disk.rb +0 -3
- data/lib/kanrisuru/core/dmi.rb +1 -1
- data/lib/kanrisuru/core/file.rb +4 -11
- data/lib/kanrisuru/core/find.rb +6 -11
- data/lib/kanrisuru/core/mount.rb +14 -15
- data/lib/kanrisuru/core/socket.rb +2 -1
- data/lib/kanrisuru/core/stream.rb +1 -2
- data/lib/kanrisuru/core/zypper.rb +6 -23
- data/lib/kanrisuru/os_package/collection.rb +58 -0
- data/lib/kanrisuru/os_package/define.rb +34 -0
- data/lib/kanrisuru/os_package/include.rb +163 -0
- data/lib/kanrisuru/os_package.rb +3 -245
- data/lib/kanrisuru/remote/cpu.rb +5 -1
- data/lib/kanrisuru/remote/fstab.rb +5 -5
- data/lib/kanrisuru/result.rb +5 -4
- data/lib/kanrisuru/util.rb +1 -1
- data/lib/kanrisuru/version.rb +1 -1
- data/spec/functional/core/apt_spec.rb +22 -30
- data/spec/functional/core/archive_spec.rb +96 -120
- data/spec/functional/core/find_spec.rb +94 -113
- data/spec/functional/core/mount_spec.rb +121 -0
- data/spec/functional/core/socket_spec.rb +23 -28
- data/spec/functional/core/stream_spec.rb +12 -12
- data/spec/functional/core/transfer_spec.rb +108 -131
- data/spec/functional/core/yum_spec.rb +58 -83
- data/spec/functional/remote/cluster_spec.rb +11 -2
- data/spec/functional/remote/cpu_spec.rb +104 -0
- data/spec/functional/remote/env_spec.rb +3 -5
- data/spec/helper/stub_network.rb +35 -16
- data/spec/helper/test_hosts.rb +11 -1
- data/spec/integration/core/apt_spec.rb +2 -3
- data/spec/integration/core/archive_spec.rb +8 -13
- data/spec/integration/core/disk_spec.rb +2 -3
- data/spec/integration/core/dmi_spec.rb +2 -3
- data/spec/integration/core/file_spec.rb +4 -14
- data/spec/integration/core/find_spec.rb +3 -3
- data/spec/integration/core/group_spec.rb +2 -3
- data/spec/integration/core/ip_spec.rb +2 -3
- data/spec/integration/core/path_spec.rb +2 -3
- data/spec/integration/core/socket_spec.rb +2 -4
- data/spec/integration/core/stat_spec.rb +2 -3
- data/spec/integration/core/stream_spec.rb +6 -9
- data/spec/integration/core/system_spec.rb +2 -4
- data/spec/integration/core/transfer_spec.rb +4 -9
- data/spec/integration/core/user_spec.rb +2 -4
- data/spec/integration/core/yum_spec.rb +2 -3
- data/spec/integration/core/zypper_spec.rb +5 -6
- data/spec/integration/remote/cpu_spec.rb +2 -3
- data/spec/integration/remote/env_spec.rb +2 -3
- data/spec/integration/remote/fstab_spec.rb +2 -3
- data/spec/integration/remote/host_spec.rb +2 -3
- data/spec/integration/remote/memory_spec.rb +2 -2
- data/spec/integration/remote/os_spec.rb +2 -3
- data/spec/integration/remote/remote_file_spec.rb +9 -15
- data/spec/spec_helper.rb +12 -3
- data/spec/unit/command_spec.rb +19 -1
- data/spec/unit/core/find_spec.rb +1 -1
- data/spec/unit/core/yum_spec.rb +1 -1
- data/spec/unit/mode_spec.rb +2 -2
- data/spec/unit/remote/cluster_spec.rb +3 -1
- data/spec/unit/remote/cpu_spec.rb +1 -2
- data/spec/unit/remote/env_spec.rb +1 -3
- data/spec/unit/util_spec.rb +13 -0
- metadata +23 -4
| @@ -2,10 +2,10 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            require 'spec_helper'
         | 
| 4 4 |  | 
| 5 | 
            -
            RSpec.describe Kanrisuru::Core:: | 
| 5 | 
            +
            RSpec.describe Kanrisuru::Core::Archive do
         | 
| 6 6 | 
             
              before(:all) do
         | 
| 7 7 | 
             
                StubNetwork.stub!
         | 
| 8 | 
            -
                StubNetwork.stub_command!(:realpath) do | | 
| 8 | 
            +
                StubNetwork.stub_command!(:realpath) do |_args|
         | 
| 9 9 | 
             
                  Kanrisuru::Core::Path::FilePath.new(directory)
         | 
| 10 10 | 
             
                end
         | 
| 11 11 | 
             
              end
         | 
| @@ -26,169 +26,145 @@ RSpec.describe Kanrisuru::Core::Apt do | |
| 26 26 | 
             
              let(:directory) { '/home/ubuntu/dir' }
         | 
| 27 27 |  | 
| 28 28 | 
             
              it 'prepares tar list command' do
         | 
| 29 | 
            -
                [ | 
| 30 | 
            -
                  expect_command(host.tar(action_variant, 'file.txt'), | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
                    ), 
         | 
| 41 | 
            -
                    'tar --restrict -C /home/ubuntu/dir -f ~/file.txt -j -t --occurrence 1 --label --multi-volume'
         | 
| 42 | 
            -
                  )
         | 
| 29 | 
            +
                %w[list t].each do |action_variant|
         | 
| 30 | 
            +
                  expect_command(host.tar(action_variant, 'file.txt'),
         | 
| 31 | 
            +
                                 'tar --restrict -f file.txt -t')
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                  expect_command(host.tar(action_variant, '~/file.txt',
         | 
| 34 | 
            +
                                          compress: 'bzip2',
         | 
| 35 | 
            +
                                          directory: directory,
         | 
| 36 | 
            +
                                          occurrence: 1,
         | 
| 37 | 
            +
                                          label: true,
         | 
| 38 | 
            +
                                          multi_volume: true),
         | 
| 39 | 
            +
                                 'tar --restrict -C /home/ubuntu/dir -f ~/file.txt -j -t --occurrence 1 --label --multi-volume')
         | 
| 43 40 | 
             
                end
         | 
| 44 41 | 
             
              end
         | 
| 45 42 |  | 
| 46 43 | 
             
              it 'prepares tar extract command' do
         | 
| 47 | 
            -
                [ | 
| 48 | 
            -
                  expect_command(host.tar(action_variant, 'archive.tar'), | 
| 49 | 
            -
             | 
| 50 | 
            -
                  )
         | 
| 44 | 
            +
                %w[extract get x].each do |action_variant|
         | 
| 45 | 
            +
                  expect_command(host.tar(action_variant, 'archive.tar'),
         | 
| 46 | 
            +
                                 'tar --restrict -f archive.tar -x')
         | 
| 51 47 |  | 
| 52 48 | 
             
                  expect_command(host.tar(action_variant, 'archive.tar',
         | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 56 | 
            -
             | 
| 57 | 
            -
             | 
| 58 | 
            -
             | 
| 59 | 
            -
             | 
| 60 | 
            -
             | 
| 61 | 
            -
             | 
| 62 | 
            -
             | 
| 63 | 
            -
             | 
| 64 | 
            -
             | 
| 65 | 
            -
             | 
| 66 | 
            -
             | 
| 67 | 
            -
             | 
| 68 | 
            -
             | 
| 69 | 
            -
                    'tar --restrict -C /home/ubuntu/dir -f archive.tar -J -x --occurrence 2 --no-same-owner --no-same-permissions --no-selinux --no-xattrs --multi-volume --label --skip-old-files --overwrite --overwrite-dir --unlink-first --recursive-unlink file.txt'
         | 
| 70 | 
            -
                  )
         | 
| 49 | 
            +
                                          compress: 'xz',
         | 
| 50 | 
            +
                                          directory: directory,
         | 
| 51 | 
            +
                                          occurrence: 2,
         | 
| 52 | 
            +
                                          no_same_owner: true,
         | 
| 53 | 
            +
                                          no_same_permissions: true,
         | 
| 54 | 
            +
                                          no_selinux: true,
         | 
| 55 | 
            +
                                          no_xattrs: true,
         | 
| 56 | 
            +
                                          multi_volume: true,
         | 
| 57 | 
            +
                                          label: true,
         | 
| 58 | 
            +
                                          skip_old_files: true,
         | 
| 59 | 
            +
                                          overwrite: true,
         | 
| 60 | 
            +
                                          overwrite_dir: true,
         | 
| 61 | 
            +
                                          unlink_first: true,
         | 
| 62 | 
            +
                                          recursive_unlink: true,
         | 
| 63 | 
            +
                                          paths: 'file.txt'),
         | 
| 64 | 
            +
                                 'tar --restrict -C /home/ubuntu/dir -f archive.tar -J -x --occurrence 2 --no-same-owner --no-same-permissions --no-selinux --no-xattrs --multi-volume --label --skip-old-files --overwrite --overwrite-dir --unlink-first --recursive-unlink file.txt')
         | 
| 71 65 |  | 
| 72 66 | 
             
                  expect_command(host.tar(action_variant, 'archive.tar',
         | 
| 73 | 
            -
             | 
| 74 | 
            -
             | 
| 75 | 
            -
             | 
| 76 | 
            -
             | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| 79 | 
            -
                    'tar --restrict -f archive.tar -x --preserve-permissions --same-owner --one-file-system --keep-old-files file1.txt file2.txt'
         | 
| 80 | 
            -
                  )
         | 
| 67 | 
            +
                                          preserve_permissions: true,
         | 
| 68 | 
            +
                                          same_owners: true,
         | 
| 69 | 
            +
                                          one_file_system: true,
         | 
| 70 | 
            +
                                          keep_old_files: true,
         | 
| 71 | 
            +
                                          paths: ['file1.txt', 'file2.txt']),
         | 
| 72 | 
            +
                                 'tar --restrict -f archive.tar -x --preserve-permissions --same-owner --one-file-system --keep-old-files file1.txt file2.txt')
         | 
| 81 73 | 
             
                end
         | 
| 82 74 | 
             
              end
         | 
| 83 75 |  | 
| 84 76 | 
             
              it 'prepares tar create command' do
         | 
| 85 | 
            -
                [ | 
| 86 | 
            -
                  expect_command(host.tar(action_variant, 'archive.lzma', compress: 'lzma'), | 
| 87 | 
            -
             | 
| 88 | 
            -
             | 
| 89 | 
            -
             | 
| 90 | 
            -
             | 
| 91 | 
            -
             | 
| 92 | 
            -
             | 
| 93 | 
            -
             | 
| 94 | 
            -
             | 
| 95 | 
            -
             | 
| 96 | 
            -
             | 
| 97 | 
            -
             | 
| 98 | 
            -
             | 
| 99 | 
            -
             | 
| 100 | 
            -
             | 
| 101 | 
            -
             | 
| 102 | 
            -
                    ),
         | 
| 103 | 
            -
                    'tar --restrict -f archive.gz -z -c --exclude=file2.txt --exclude=file4.txt file1.txt file3.txt'
         | 
| 104 | 
            -
                  )
         | 
| 77 | 
            +
                %w[create c].each do |action_variant|
         | 
| 78 | 
            +
                  expect_command(host.tar(action_variant, 'archive.lzma', compress: 'lzma'),
         | 
| 79 | 
            +
                                 'tar --restrict -f archive.lzma --lzma -c')
         | 
| 80 | 
            +
                  expect_command(host.tar(action_variant, 'archive.gz'), 'tar --restrict -f archive.gz -c')
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                  expect_command(host.tar(action_variant, 'archive.gz',
         | 
| 83 | 
            +
                                          directory: directory,
         | 
| 84 | 
            +
                                          compress: 'gzip',
         | 
| 85 | 
            +
                                          exclude: 'file2.txt',
         | 
| 86 | 
            +
                                          paths: 'file1.txt'),
         | 
| 87 | 
            +
                                 'tar --restrict -C /home/ubuntu/dir -f archive.gz -z -c --exclude=file2.txt file1.txt')
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                  expect_command(host.tar(action_variant, 'archive.gz',
         | 
| 90 | 
            +
                                          compress: 'gzip',
         | 
| 91 | 
            +
                                          exclude: ['file2.txt', 'file4.txt'],
         | 
| 92 | 
            +
                                          paths: ['file1.txt', 'file3.txt']),
         | 
| 93 | 
            +
                                 'tar --restrict -f archive.gz -z -c --exclude=file2.txt --exclude=file4.txt file1.txt file3.txt')
         | 
| 105 94 | 
             
                end
         | 
| 106 95 | 
             
              end
         | 
| 107 96 |  | 
| 108 97 | 
             
              it 'prepares tar append command' do
         | 
| 109 | 
            -
                [ | 
| 98 | 
            +
                %w[append r].each do |action_variant|
         | 
| 110 99 | 
             
                  expect_command(host.tar(action_variant, 'archive.tar'), 'tar --restrict -f archive.tar -r')
         | 
| 111 100 |  | 
| 112 | 
            -
                  expect_command(host.tar(action_variant, 'archive.tar', | 
| 113 | 
            -
             | 
| 114 | 
            -
             | 
| 115 | 
            -
             | 
| 116 | 
            -
             | 
| 117 | 
            -
                   | 
| 118 | 
            -
             | 
| 119 | 
            -
             | 
| 120 | 
            -
             | 
| 121 | 
            -
                    ), 
         | 
| 122 | 
            -
                    'tar --restrict -f archive.tar -r main.conf main2.conf'
         | 
| 123 | 
            -
                  ) 
         | 
| 124 | 
            -
                end 
         | 
| 101 | 
            +
                  expect_command(host.tar(action_variant, 'archive.tar',
         | 
| 102 | 
            +
                                          directory: directory,
         | 
| 103 | 
            +
                                          paths: 'main.conf'),
         | 
| 104 | 
            +
                                 'tar --restrict -C /home/ubuntu/dir -f archive.tar -r main.conf')
         | 
| 105 | 
            +
             | 
| 106 | 
            +
                  expect_command(host.tar(action_variant, 'archive.tar',
         | 
| 107 | 
            +
                                          paths: ['main.conf', 'main2.conf']),
         | 
| 108 | 
            +
                                 'tar --restrict -f archive.tar -r main.conf main2.conf')
         | 
| 109 | 
            +
                end
         | 
| 125 110 | 
             
              end
         | 
| 126 111 |  | 
| 127 112 | 
             
              it 'prepares tar concat command' do
         | 
| 128 | 
            -
                [ | 
| 113 | 
            +
                %w[catenate concat A].each do |action_variant|
         | 
| 129 114 | 
             
                  expect_command(host.tar(action_variant, 'archive.tar'), 'tar --restrict -f archive.tar -A')
         | 
| 130 115 | 
             
                  expect_command(host.tar(action_variant, 'archive.tar',
         | 
| 131 | 
            -
             | 
| 132 | 
            -
             | 
| 133 | 
            -
             | 
| 134 | 
            -
                    'tar --restrict -C /home/ubuntu/dir -f archive.tar -A archive2.tar'
         | 
| 135 | 
            -
                  )
         | 
| 116 | 
            +
                                          directory: directory,
         | 
| 117 | 
            +
                                          paths: 'archive2.tar'),
         | 
| 118 | 
            +
                                 'tar --restrict -C /home/ubuntu/dir -f archive.tar -A archive2.tar')
         | 
| 136 119 |  | 
| 137 120 | 
             
                  expect_command(host.tar(action_variant, 'archive.tar',
         | 
| 138 | 
            -
             | 
| 139 | 
            -
             | 
| 140 | 
            -
             | 
| 141 | 
            -
                    'tar --restrict -C /home/ubuntu/dir -f archive.tar -A archive2.tar archive3.tar'
         | 
| 142 | 
            -
                  )
         | 
| 121 | 
            +
                                          directory: directory,
         | 
| 122 | 
            +
                                          paths: ['archive2.tar', 'archive3.tar']),
         | 
| 123 | 
            +
                                 'tar --restrict -C /home/ubuntu/dir -f archive.tar -A archive2.tar archive3.tar')
         | 
| 143 124 | 
             
                end
         | 
| 144 125 | 
             
              end
         | 
| 145 126 |  | 
| 146 127 | 
             
              it 'prepares tar update command' do
         | 
| 147 | 
            -
                [ | 
| 128 | 
            +
                %w[update u].each do |action_variant|
         | 
| 148 129 | 
             
                  expect_command(host.tar(action_variant, 'archive',
         | 
| 149 | 
            -
             | 
| 150 | 
            -
             | 
| 151 | 
            -
                    'tar --restrict -f archive -u file1.txt'
         | 
| 152 | 
            -
                  )
         | 
| 130 | 
            +
                                          paths: 'file1.txt'),
         | 
| 131 | 
            +
                                 'tar --restrict -f archive -u file1.txt')
         | 
| 153 132 |  | 
| 154 133 | 
             
                  expect_command(host.tar(action_variant, 'archive',
         | 
| 155 | 
            -
             | 
| 156 | 
            -
             | 
| 157 | 
            -
             | 
| 158 | 
            -
                    'tar --restrict -C /home/ubuntu/dir -f archive -u file1.txt file2.txt'
         | 
| 159 | 
            -
                  )
         | 
| 134 | 
            +
                                          directory: directory,
         | 
| 135 | 
            +
                                          paths: ['file1.txt', 'file2.txt']),
         | 
| 136 | 
            +
                                 'tar --restrict -C /home/ubuntu/dir -f archive -u file1.txt file2.txt')
         | 
| 160 137 | 
             
                end
         | 
| 161 138 | 
             
              end
         | 
| 162 139 |  | 
| 163 140 | 
             
              it 'prepares tar diff command' do
         | 
| 164 | 
            -
                [ | 
| 165 | 
            -
                  expect_command(host.tar(action_variant, 'archive.tar', directory: directory), | 
| 166 | 
            -
             | 
| 167 | 
            -
             | 
| 168 | 
            -
             | 
| 169 | 
            -
             | 
| 170 | 
            -
             | 
| 171 | 
            -
             | 
| 141 | 
            +
                %w[diff compare d].each do |action_variant|
         | 
| 142 | 
            +
                  expect_command(host.tar(action_variant, 'archive.tar', directory: directory),
         | 
| 143 | 
            +
                                 'tar --restrict -C /home/ubuntu/dir -f archive.tar -d')
         | 
| 144 | 
            +
             | 
| 145 | 
            +
                  expect_command(host.tar(action_variant, 'archive.tar',
         | 
| 146 | 
            +
                                          directory: directory,
         | 
| 147 | 
            +
                                          occurrence: 4),
         | 
| 148 | 
            +
                                 'tar --restrict -C /home/ubuntu/dir -f archive.tar -d --occurrence 4')
         | 
| 172 149 | 
             
                end
         | 
| 173 150 | 
             
              end
         | 
| 174 151 |  | 
| 175 152 | 
             
              it 'prepares tar delete command' do
         | 
| 176 | 
            -
                expect_command(host.tar('delete', 'archive.tar', paths: 'file1.txt'), | 
| 177 | 
            -
             | 
| 178 | 
            -
             | 
| 179 | 
            -
             | 
| 180 | 
            -
             | 
| 181 | 
            -
             | 
| 182 | 
            -
                )
         | 
| 153 | 
            +
                expect_command(host.tar('delete', 'archive.tar', paths: 'file1.txt'),
         | 
| 154 | 
            +
                               'tar --restrict -f archive.tar --delete file1.txt')
         | 
| 155 | 
            +
                expect_command(host.tar('delete', 'archive.tar',
         | 
| 156 | 
            +
                                        paths: ['file1.txt', 'file2.txt'],
         | 
| 157 | 
            +
                                        occurrence: 3),
         | 
| 158 | 
            +
                               'tar --restrict -f archive.tar --delete --occurrence 3 file1.txt file2.txt')
         | 
| 183 159 | 
             
              end
         | 
| 184 160 |  | 
| 185 161 | 
             
              it 'prepares invalid tar command' do
         | 
| 186 | 
            -
                expect  | 
| 162 | 
            +
                expect do
         | 
| 187 163 | 
             
                  host.tar('abc', 'file1.txt')
         | 
| 188 | 
            -
                 | 
| 164 | 
            +
                end.to raise_error(ArgumentError)
         | 
| 189 165 |  | 
| 190 | 
            -
                expect  | 
| 166 | 
            +
                expect do
         | 
| 191 167 | 
             
                  host.tar('create', 'archive.tar', compress: 'xip')
         | 
| 192 | 
            -
                 | 
| 168 | 
            +
                end.to raise_error(ArgumentError)
         | 
| 193 169 | 
             
              end
         | 
| 194 170 | 
             
            end
         | 
| @@ -20,150 +20,131 @@ RSpec.describe Kanrisuru::Core::Find do | |
| 20 20 | 
             
              end
         | 
| 21 21 |  | 
| 22 22 | 
             
              it 'prepares find command' do
         | 
| 23 | 
            -
                expect_command(host.find,  | 
| 23 | 
            +
                expect_command(host.find, 'find')
         | 
| 24 24 |  | 
| 25 | 
            -
                expect_command(host.find(follow: 'never'),  | 
| 26 | 
            -
                expect_command(host.find(follow: 'always'),  | 
| 27 | 
            -
                expect_command(host.find(follow: 'command'),  | 
| 25 | 
            +
                expect_command(host.find(follow: 'never'), 'find -P')
         | 
| 26 | 
            +
                expect_command(host.find(follow: 'always'), 'find -L')
         | 
| 27 | 
            +
                expect_command(host.find(follow: 'command'), 'find -H')
         | 
| 28 28 |  | 
| 29 | 
            -
                expect_command(host.find(paths: '/etc'),  | 
| 30 | 
            -
                expect_command(host.find(paths: ['/etc', '/var', '/home']),  | 
| 29 | 
            +
                expect_command(host.find(paths: '/etc'), 'find /etc')
         | 
| 30 | 
            +
                expect_command(host.find(paths: ['/etc', '/var', '/home']), 'find /etc /var /home')
         | 
| 31 31 |  | 
| 32 | 
            -
                expect  | 
| 32 | 
            +
                expect do
         | 
| 33 33 | 
             
                  host.find(paths: 1)
         | 
| 34 | 
            -
                 | 
| 35 | 
            -
             | 
| 36 | 
            -
                expect_command(host.find(paths: '/', | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
                 | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 50 | 
            -
             | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 56 | 
            -
             | 
| 57 | 
            -
                    maxdepth: 100   
         | 
| 58 | 
            -
                  ),
         | 
| 59 | 
            -
                  "find / -path /lib -name *.so -gid 0 -uid 0 -user root -group root -links 2 -maxdepth 100 -mindepth 0"
         | 
| 60 | 
            -
                )
         | 
| 34 | 
            +
                end.to raise_error(ArgumentError)
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                expect_command(host.find(paths: '/',
         | 
| 37 | 
            +
                                         executable: true,
         | 
| 38 | 
            +
                                         empty: true,
         | 
| 39 | 
            +
                                         readable: true,
         | 
| 40 | 
            +
                                         writeable: true,
         | 
| 41 | 
            +
                                         nogroup: true,
         | 
| 42 | 
            +
                                         nouser: true,
         | 
| 43 | 
            +
                                         mount: true),
         | 
| 44 | 
            +
                               'find / -executable -empty -readable -nogroup -nouser -mount')
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                expect_command(host.find(paths: '/',
         | 
| 47 | 
            +
                                         path: '/lib',
         | 
| 48 | 
            +
                                         name: '*.so',
         | 
| 49 | 
            +
                                         gid: 0,
         | 
| 50 | 
            +
                                         uid: 0,
         | 
| 51 | 
            +
                                         user: 'root',
         | 
| 52 | 
            +
                                         group: 'root',
         | 
| 53 | 
            +
                                         links: 2,
         | 
| 54 | 
            +
                                         mindepth: 0,
         | 
| 55 | 
            +
                                         maxdepth: 100),
         | 
| 56 | 
            +
                               'find / -path /lib -name *.so -gid 0 -uid 0 -user root -group root -links 2 -maxdepth 100 -mindepth 0')
         | 
| 61 57 |  | 
| 62 58 | 
             
                expect_command(host.find(paths: '/var/log',
         | 
| 63 | 
            -
             | 
| 64 | 
            -
             | 
| 65 | 
            -
             | 
| 66 | 
            -
             | 
| 67 | 
            -
             | 
| 68 | 
            -
             | 
| 69 | 
            -
             | 
| 70 | 
            -
                  "find /var/log -atime +1 -ctime +2 -mtime +3 -amin 100 -cmin 200 -mmin 300"
         | 
| 71 | 
            -
                )
         | 
| 59 | 
            +
                                         atime: '+1',
         | 
| 60 | 
            +
                                         ctime: '+2',
         | 
| 61 | 
            +
                                         mtime: '+3',
         | 
| 62 | 
            +
                                         amin: '100',
         | 
| 63 | 
            +
                                         cmin: '200',
         | 
| 64 | 
            +
                                         mmin: '300'),
         | 
| 65 | 
            +
                               'find /var/log -atime +1 -ctime +2 -mtime +3 -amin 100 -cmin 200 -mmin 300')
         | 
| 72 66 |  | 
| 73 67 | 
             
                expect_command(host.find(
         | 
| 74 | 
            -
             | 
| 75 | 
            -
             | 
| 76 | 
            -
             | 
| 77 | 
            -
             | 
| 78 | 
            -
                )
         | 
| 68 | 
            +
                                 paths: '/dev',
         | 
| 69 | 
            +
                                 regex: '/dev/tty[0-9]*'
         | 
| 70 | 
            +
                               ),
         | 
| 71 | 
            +
                               "find /dev -regex '/dev/tty[0-9]*'")
         | 
| 79 72 |  | 
| 80 73 | 
             
                expect_command(host.find(
         | 
| 81 | 
            -
             | 
| 82 | 
            -
             | 
| 83 | 
            -
             | 
| 84 | 
            -
             | 
| 85 | 
            -
             | 
| 86 | 
            -
                )
         | 
| 74 | 
            +
                                 paths: '/dev',
         | 
| 75 | 
            +
                                 regex_type: 'posix-egrep',
         | 
| 76 | 
            +
                                 regex: '/dev/tty[0-9]*'
         | 
| 77 | 
            +
                               ),
         | 
| 78 | 
            +
                               "find /dev -regextype posix-egrep -regex '/dev/tty[0-9]*'")
         | 
| 87 79 |  | 
| 88 80 | 
             
                expect_command(host.find(
         | 
| 89 | 
            -
             | 
| 90 | 
            -
             | 
| 91 | 
            -
             | 
| 92 | 
            -
             | 
| 93 | 
            -
                )
         | 
| 81 | 
            +
                                 paths: '/var/log',
         | 
| 82 | 
            +
                                 size: 100
         | 
| 83 | 
            +
                               ),
         | 
| 84 | 
            +
                               'find /var/log -size 100')
         | 
| 94 85 |  | 
| 95 86 | 
             
                expect_command(host.find(
         | 
| 96 | 
            -
             | 
| 97 | 
            -
             | 
| 98 | 
            -
             | 
| 99 | 
            -
             | 
| 100 | 
            -
             | 
| 101 | 
            -
                
         | 
| 102 | 
            -
             | 
| 103 | 
            -
             | 
| 104 | 
            -
                }.to raise_error(ArgumentError)
         | 
| 87 | 
            +
                                 paths: '/var/log',
         | 
| 88 | 
            +
                                 size: '100'
         | 
| 89 | 
            +
                               ),
         | 
| 90 | 
            +
                               'find /var/log -size 100')
         | 
| 91 | 
            +
             | 
| 92 | 
            +
                expect do
         | 
| 93 | 
            +
                  host.find(size: '100n')
         | 
| 94 | 
            +
                end.to raise_error(ArgumentError)
         | 
| 105 95 |  | 
| 106 96 | 
             
                expect_command(host.find(
         | 
| 107 | 
            -
             | 
| 108 | 
            -
             | 
| 109 | 
            -
             | 
| 110 | 
            -
             | 
| 111 | 
            -
                )
         | 
| 97 | 
            +
                                 paths: '/var/log',
         | 
| 98 | 
            +
                                 size: '-100k'
         | 
| 99 | 
            +
                               ),
         | 
| 100 | 
            +
                               'find /var/log -size -100k')
         | 
| 112 101 |  | 
| 113 102 | 
             
                expect_command(host.find(
         | 
| 114 | 
            -
             | 
| 115 | 
            -
             | 
| 116 | 
            -
             | 
| 117 | 
            -
             | 
| 118 | 
            -
                )
         | 
| 103 | 
            +
                                 paths: '/var/log',
         | 
| 104 | 
            +
                                 size: '+10M'
         | 
| 105 | 
            +
                               ),
         | 
| 106 | 
            +
                               'find /var/log -size +10M')
         | 
| 119 107 |  | 
| 120 108 | 
             
                expect_command(host.find(
         | 
| 121 | 
            -
             | 
| 122 | 
            -
             | 
| 123 | 
            -
             | 
| 124 | 
            -
             | 
| 125 | 
            -
                )
         | 
| 109 | 
            +
                                 paths: '/dev',
         | 
| 110 | 
            +
                                 type: 'directory'
         | 
| 111 | 
            +
                               ),
         | 
| 112 | 
            +
                               'find /dev -type d')
         | 
| 126 113 |  | 
| 127 114 | 
             
                expect_command(host.find(
         | 
| 128 | 
            -
             | 
| 129 | 
            -
             | 
| 130 | 
            -
             | 
| 131 | 
            -
             | 
| 132 | 
            -
                )
         | 
| 115 | 
            +
                                 paths: '/dev',
         | 
| 116 | 
            +
                                 type: 'file'
         | 
| 117 | 
            +
                               ),
         | 
| 118 | 
            +
                               'find /dev -type f')
         | 
| 133 119 |  | 
| 134 120 | 
             
                expect_command(host.find(
         | 
| 135 | 
            -
             | 
| 136 | 
            -
             | 
| 137 | 
            -
             | 
| 138 | 
            -
             | 
| 139 | 
            -
                )
         | 
| 121 | 
            +
                                 paths: '/dev',
         | 
| 122 | 
            +
                                 type: 'symlinks'
         | 
| 123 | 
            +
                               ),
         | 
| 124 | 
            +
                               'find /dev -type l')
         | 
| 140 125 |  | 
| 141 126 | 
             
                expect_command(host.find(
         | 
| 142 | 
            -
             | 
| 143 | 
            -
             | 
| 144 | 
            -
             | 
| 145 | 
            -
             | 
| 146 | 
            -
                )
         | 
| 127 | 
            +
                                 paths: '/dev',
         | 
| 128 | 
            +
                                 type: 'block'
         | 
| 129 | 
            +
                               ),
         | 
| 130 | 
            +
                               'find /dev -type b')
         | 
| 147 131 |  | 
| 148 132 | 
             
                expect_command(host.find(
         | 
| 149 | 
            -
             | 
| 150 | 
            -
             | 
| 151 | 
            -
             | 
| 152 | 
            -
             | 
| 153 | 
            -
                )
         | 
| 133 | 
            +
                                 paths: '/dev',
         | 
| 134 | 
            +
                                 type: 'character'
         | 
| 135 | 
            +
                               ),
         | 
| 136 | 
            +
                               'find /dev -type c')
         | 
| 154 137 |  | 
| 155 138 | 
             
                expect_command(host.find(
         | 
| 156 | 
            -
             | 
| 157 | 
            -
             | 
| 158 | 
            -
             | 
| 159 | 
            -
             | 
| 160 | 
            -
                )
         | 
| 139 | 
            +
                                 paths: '/dev',
         | 
| 140 | 
            +
                                 type: 'pipe'
         | 
| 141 | 
            +
                               ),
         | 
| 142 | 
            +
                               'find /dev -type p')
         | 
| 161 143 |  | 
| 162 144 | 
             
                expect_command(host.find(
         | 
| 163 | 
            -
             | 
| 164 | 
            -
             | 
| 165 | 
            -
             | 
| 166 | 
            -
             | 
| 167 | 
            -
                )
         | 
| 145 | 
            +
                                 paths: '/dev',
         | 
| 146 | 
            +
                                 type: 'socket'
         | 
| 147 | 
            +
                               ),
         | 
| 148 | 
            +
                               'find /dev -type s')
         | 
| 168 149 | 
             
              end
         | 
| 169 150 | 
             
            end
         | 
| @@ -0,0 +1,121 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'spec_helper'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            RSpec.describe Kanrisuru::Core::Mount do
         | 
| 6 | 
            +
              before(:all) do
         | 
| 7 | 
            +
                StubNetwork.stub!
         | 
| 8 | 
            +
              end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              after(:all) do
         | 
| 11 | 
            +
                StubNetwork.unstub!
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              let(:host) do
         | 
| 15 | 
            +
                Kanrisuru::Remote::Host.new(
         | 
| 16 | 
            +
                  host: 'localhost',
         | 
| 17 | 
            +
                  username: 'ubuntu',
         | 
| 18 | 
            +
                  keys: ['id_rsa']
         | 
| 19 | 
            +
                )
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              it 'prepares mount command' do
         | 
| 23 | 
            +
                expect_command(host.mount, 'mount')
         | 
| 24 | 
            +
                expect_command(host.mount(bind_old: '/mnt/dira', bind_new: '/mnt/dirb'), 'mount --bind /mnt/dira /mnt/dirb')
         | 
| 25 | 
            +
                expect_command(host.mount(rbind_old: '/mnt/dira', rbind_new: '/mnt/dirb'), 'mount --rbind /mnt/dira /mnt/dirb')
         | 
| 26 | 
            +
                expect_command(host.mount(move_old: '/mnt/dira', move_new: '/mnt/dirb'), 'mount --move /mnt/dira /mnt/dirb')
         | 
| 27 | 
            +
                expect_command(host.mount(
         | 
| 28 | 
            +
                                 label: 'cloudimg-rootfs',
         | 
| 29 | 
            +
                                 uuid: '5fbaea960d09e2ad',
         | 
| 30 | 
            +
                                 sloppy: true,
         | 
| 31 | 
            +
                                 internal_only: true,
         | 
| 32 | 
            +
                                 fake: true,
         | 
| 33 | 
            +
                                 no_mtab: true,
         | 
| 34 | 
            +
                                 no_canonicalize: true,
         | 
| 35 | 
            +
                                 device: '/dev/vda9',
         | 
| 36 | 
            +
                                 directory: '/mnt/dir1'
         | 
| 37 | 
            +
                               ), 'mount -L cloudimg-rootfs -U 5fbaea960d09e2ad -f -i -s --no-mtab --no-canonicalize /dev/vda9 /mnt/dir1')
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                expect_command(host.mount(
         | 
| 40 | 
            +
                                 fs_opts: { async: true, auto: true, group: true, relatime: true, owner: true },
         | 
| 41 | 
            +
                                 device: '/dev/tty',
         | 
| 42 | 
            +
                                 directory: '/mnt/dir2'
         | 
| 43 | 
            +
                               ), 'mount -o async,auto,group,relatime,owner /dev/tty /mnt/dir2')
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                expect do
         | 
| 46 | 
            +
                  host.mount(fs_opts: { value: true }, device: '/home/ubuntu/dir', directory: '/mnt/dir3')
         | 
| 47 | 
            +
                end.to raise_error(ArgumentError)
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                expect_command(host.mount(
         | 
| 50 | 
            +
                                 type: 'ext2',
         | 
| 51 | 
            +
                                 device: '/dev/tty',
         | 
| 52 | 
            +
                                 directory: '/mnt/dir2'
         | 
| 53 | 
            +
                               ), 'mount -t ext2 /dev/tty /mnt/dir2')
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                expect_command(host.mount(
         | 
| 56 | 
            +
                                 type: 'ext4',
         | 
| 57 | 
            +
                                 fs_opts: { acl: true, journal: 'update', usrquota: true, async: true, owner: true, group: true },
         | 
| 58 | 
            +
                                 device: '/dev/tty',
         | 
| 59 | 
            +
                                 directory: '/mnt/dir2'
         | 
| 60 | 
            +
                               ), 'mount -t ext4 -o acl,journal=update,usrquota,async,owner,group /dev/tty /mnt/dir2')
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                expect_command(host.mount(type: 'nontfs,xfs', all: true), 'mount -t nontfs,xfs -a')
         | 
| 63 | 
            +
                expect_command(host.mount(type: 'fat,xfs', all: true), 'mount -t fat,xfs -a')
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                expect do
         | 
| 66 | 
            +
                  host.mount(
         | 
| 67 | 
            +
                    type: 'ext2',
         | 
| 68 | 
            +
                    fs_opts: { acl: true, journal: 'update', usrquota: true, async: true, owner: true, group: true },
         | 
| 69 | 
            +
                    device: '/dev/tty',
         | 
| 70 | 
            +
                    directory: '/mnt/dir2'
         | 
| 71 | 
            +
                  )
         | 
| 72 | 
            +
                end.to raise_error(ArgumentError)
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                expect do
         | 
| 75 | 
            +
                  host.mount(
         | 
| 76 | 
            +
                    type: 'ext4',
         | 
| 77 | 
            +
                    fs_opts: { acl: true, journal: true, usrquota: true, async: true, owner: true, group: true },
         | 
| 78 | 
            +
                    device: '/dev/tty',
         | 
| 79 | 
            +
                    directory: '/mnt/dir2'
         | 
| 80 | 
            +
                  )
         | 
| 81 | 
            +
                end.to raise_error(ArgumentError)
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                expect_command(host.mount(all: true, test_opts: { _netdev: true }), 'mount -a -O _netdev')
         | 
| 84 | 
            +
                expect_command(host.mount(all: true, test_opts: { async: true, blocksize: 512, uid: 0, gid: 0, dots: true }, type: 'fat'),
         | 
| 85 | 
            +
                               'mount -t fat -a -O async,blocksize=512,uid=0,gid=0,dots')
         | 
| 86 | 
            +
             | 
| 87 | 
            +
                expect_command(host.mount(
         | 
| 88 | 
            +
                                 type: 'loop',
         | 
| 89 | 
            +
                                 fs_opts: { loop: '/dev/loop3' },
         | 
| 90 | 
            +
                                 device: '/mnt',
         | 
| 91 | 
            +
                                 directory: '/tmp/fdimage'
         | 
| 92 | 
            +
                               ),
         | 
| 93 | 
            +
                               'mount -t loop -o loop=/dev/loop3 /mnt /tmp/fdimage')
         | 
| 94 | 
            +
              end
         | 
| 95 | 
            +
             | 
| 96 | 
            +
              it 'prepares umount command' do
         | 
| 97 | 
            +
                expect_command(host.umount, 'umount')
         | 
| 98 | 
            +
                expect_command(host.umount(
         | 
| 99 | 
            +
                                 fake: true,
         | 
| 100 | 
            +
                                 no_canonicalize: true,
         | 
| 101 | 
            +
                                 no_mtab: true,
         | 
| 102 | 
            +
                                 fail_remount_readonly: true,
         | 
| 103 | 
            +
                                 free_loopback: true,
         | 
| 104 | 
            +
                                 lazy: true,
         | 
| 105 | 
            +
                                 force: true,
         | 
| 106 | 
            +
                                 device: '/dev/vda1'
         | 
| 107 | 
            +
                               ),
         | 
| 108 | 
            +
                               'umount --fake --no-canonicalize -n -r -d -l -f /dev/vda1')
         | 
| 109 | 
            +
             | 
| 110 | 
            +
                expect_command(host.umount(
         | 
| 111 | 
            +
                                 all: true,
         | 
| 112 | 
            +
                                 type: 'ext4,nofat'
         | 
| 113 | 
            +
                               ), 'umount -a -t ext4,nofat')
         | 
| 114 | 
            +
             | 
| 115 | 
            +
                expect_command(host.umount(
         | 
| 116 | 
            +
                                 all: true,
         | 
| 117 | 
            +
                                 type: 'ext4',
         | 
| 118 | 
            +
                                 test_opts: { barrier: 1, nouid32: true }
         | 
| 119 | 
            +
                               ), 'umount -a -t ext4 -O barrier=1,nouid32')
         | 
| 120 | 
            +
              end
         | 
| 121 | 
            +
            end
         |