iostreams 1.11.0 → 2.0.0

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.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +20 -2
  3. data/Rakefile +7 -0
  4. data/lib/io_streams/builder.rb +9 -9
  5. data/lib/io_streams/bzip2/writer.rb +1 -1
  6. data/lib/io_streams/encode/reader.rb +2 -2
  7. data/lib/io_streams/encode/writer.rb +5 -5
  8. data/lib/io_streams/gzip/reader.rb +1 -1
  9. data/lib/io_streams/gzip/writer.rb +1 -1
  10. data/lib/io_streams/io_streams.rb +45 -19
  11. data/lib/io_streams/line/reader.rb +2 -2
  12. data/lib/io_streams/line/writer.rb +1 -1
  13. data/lib/io_streams/path.rb +2 -2
  14. data/lib/io_streams/paths/file.rb +10 -10
  15. data/lib/io_streams/paths/http.rb +80 -7
  16. data/lib/io_streams/paths/matcher.rb +3 -3
  17. data/lib/io_streams/paths/s3.rb +3 -3
  18. data/lib/io_streams/paths/sftp.rb +7 -8
  19. data/lib/io_streams/pgp/reader.rb +23 -10
  20. data/lib/io_streams/pgp/writer.rb +93 -32
  21. data/lib/io_streams/pgp.rb +188 -60
  22. data/lib/io_streams/reader.rb +4 -4
  23. data/lib/io_streams/record/reader.rb +3 -4
  24. data/lib/io_streams/record/writer.rb +3 -4
  25. data/lib/io_streams/row/reader.rb +1 -1
  26. data/lib/io_streams/row/writer.rb +1 -1
  27. data/lib/io_streams/stream.rb +36 -30
  28. data/lib/io_streams/symmetric_encryption/reader.rb +2 -2
  29. data/lib/io_streams/symmetric_encryption/writer.rb +4 -4
  30. data/lib/io_streams/tabular/header.rb +18 -6
  31. data/lib/io_streams/tabular/parser/array.rb +0 -10
  32. data/lib/io_streams/tabular/parser/csv.rb +6 -38
  33. data/lib/io_streams/tabular/parser/fixed.rb +5 -5
  34. data/lib/io_streams/tabular/parser/psv.rb +0 -12
  35. data/lib/io_streams/tabular.rb +5 -10
  36. data/lib/io_streams/utils.rb +3 -2
  37. data/lib/io_streams/version.rb +1 -1
  38. data/lib/io_streams/writer.rb +6 -6
  39. data/lib/io_streams/xlsx/reader.rb +1 -1
  40. data/lib/io_streams/zip/writer.rb +22 -10
  41. data/lib/iostreams.rb +0 -1
  42. metadata +28 -111
  43. data/lib/io_streams/deprecated.rb +0 -216
  44. data/lib/io_streams/tabular/utility/csv_row.rb +0 -105
  45. data/test/builder_test.rb +0 -311
  46. data/test/bzip2_reader_test.rb +0 -27
  47. data/test/bzip2_writer_test.rb +0 -56
  48. data/test/deprecated_test.rb +0 -121
  49. data/test/encode_reader_test.rb +0 -51
  50. data/test/encode_writer_test.rb +0 -90
  51. data/test/files/embedded_lines_test.csv +0 -7
  52. data/test/files/multiple_files.zip +0 -0
  53. data/test/files/spreadsheet.xlsx +0 -0
  54. data/test/files/test.csv +0 -4
  55. data/test/files/test.json +0 -3
  56. data/test/files/test.psv +0 -4
  57. data/test/files/text file.txt +0 -3
  58. data/test/files/text.txt +0 -3
  59. data/test/files/text.txt.bz2 +0 -0
  60. data/test/files/text.txt.gz +0 -0
  61. data/test/files/text.txt.gz.zip +0 -0
  62. data/test/files/text.zip +0 -0
  63. data/test/files/text.zip.gz +0 -0
  64. data/test/files/unclosed_quote_large_test.csv +0 -1658
  65. data/test/files/unclosed_quote_test.csv +0 -4
  66. data/test/files/unclosed_quote_test2.csv +0 -3
  67. data/test/gzip_reader_test.rb +0 -27
  68. data/test/gzip_writer_test.rb +0 -52
  69. data/test/io_streams_test.rb +0 -132
  70. data/test/line_reader_test.rb +0 -325
  71. data/test/line_writer_test.rb +0 -59
  72. data/test/minimal_file_reader.rb +0 -25
  73. data/test/path_test.rb +0 -55
  74. data/test/paths/file_test.rb +0 -213
  75. data/test/paths/http_test.rb +0 -34
  76. data/test/paths/matcher_test.rb +0 -120
  77. data/test/paths/s3_test.rb +0 -220
  78. data/test/paths/sftp_test.rb +0 -106
  79. data/test/pgp_reader_test.rb +0 -46
  80. data/test/pgp_test.rb +0 -267
  81. data/test/pgp_writer_test.rb +0 -130
  82. data/test/record_reader_test.rb +0 -60
  83. data/test/record_writer_test.rb +0 -82
  84. data/test/row_reader_test.rb +0 -35
  85. data/test/row_writer_test.rb +0 -56
  86. data/test/stream_test.rb +0 -577
  87. data/test/tabular_test.rb +0 -338
  88. data/test/test_helper.rb +0 -40
  89. data/test/utils_test.rb +0 -20
  90. data/test/xlsx_reader_test.rb +0 -37
  91. data/test/zip_reader_test.rb +0 -53
  92. data/test/zip_writer_test.rb +0 -48
@@ -1,213 +0,0 @@
1
- require_relative "../test_helper"
2
-
3
- module Paths
4
- class FileTest < Minitest::Test
5
- describe IOStreams::Paths::File do
6
- let(:root) { IOStreams::Paths::File.new("/tmp/iostreams").delete_all }
7
- let(:directory) { root.join("/some_test_dir") }
8
- let(:data) { "Hello World\nHow are you doing?\nOn this fine day" }
9
- let(:file_path) do
10
- path = root.join("some_test_dir/test_file.txt")
11
- path.writer { |io| io << data }
12
- path
13
- end
14
- let(:file_path2) do
15
- path = root.join("some_test_dir/test_file2.txt")
16
- path.writer { |io| io << "Hello World2" }
17
- path
18
- end
19
-
20
- describe "#each" do
21
- it "reads lines" do
22
- records = []
23
- count = file_path.each { |line| records << line }
24
- assert_equal count, data.lines.size
25
- assert_equal data.lines.collect(&:strip), records
26
- end
27
- end
28
-
29
- describe "#each_child" do
30
- it "iterates an empty path" do
31
- none = nil
32
- directory.join("does_not_exist").mkdir.each_child { |path| none = path }
33
- assert_nil none
34
- end
35
-
36
- it "iterates a non-existant path" do
37
- none = nil
38
- directory.join("does_not_exist").each_child { |path| none = path }
39
- assert_nil none
40
- end
41
-
42
- it "find all files" do
43
- expected = [file_path.to_s, file_path2.to_s]
44
- actual = root.children("**/*").collect(&:to_s)
45
- assert_equal expected.sort, actual.sort
46
- end
47
-
48
- it "find matches case-insensitive" do
49
- # Force creation of test files via lazy evaluation
50
- file_path_str = file_path.to_s
51
- file_path2_str = file_path2.to_s
52
-
53
- # Verify files were created
54
- assert File.exist?(file_path_str), "Test file 1 should exist: #{file_path_str}"
55
- assert File.exist?(file_path2_str), "Test file 2 should exist: #{file_path2_str}"
56
-
57
- expected = [file_path_str, file_path2_str]
58
- actual = root.children("**/Test*.TXT").collect(&:to_s)
59
-
60
- assert_equal expected.sort, actual.sort,
61
- "Case-insensitive matching failed. Expected #{expected.sort}, got #{actual.sort}. " \
62
- "Root path: #{root.to_s}, Pattern: '**/Test*.TXT'"
63
- end
64
-
65
- it "find matches case-sensitive" do
66
- skip "TODO"
67
- expected = [file_path.to_s, file_path2.to_s]
68
- actual = root.children("**/Test*.TXT", case_sensitive: true).collect(&:to_s)
69
- refute_equal expected, actual.sort
70
- end
71
-
72
- it "with no block returns enumerator" do
73
- expected = [file_path.to_s, file_path2.to_s]
74
- actual = root.each_child("**/*").first(100).collect(&:to_s)
75
- assert_equal expected.sort, actual.sort
76
- end
77
- end
78
-
79
- describe "#mkpath" do
80
- it "makes path skipping file_name" do
81
- new_path = directory.join("test_mkpath.xls").mkpath
82
- assert ::File.exist?(directory.to_s)
83
- refute ::File.exist?(new_path.to_s)
84
- end
85
- end
86
-
87
- describe "#mkdir" do
88
- it "makes entire path that does not have a file name" do
89
- new_path = directory.join("more_path").mkdir
90
- assert ::File.exist?(directory.to_s)
91
- assert ::File.exist?(new_path.to_s)
92
- end
93
- end
94
-
95
- describe "#exist?" do
96
- it "true on existing file or directory" do
97
- assert ::File.exist?(file_path.to_s)
98
- assert ::File.exist?(directory.to_s)
99
-
100
- assert directory.exist?
101
- assert file_path.exist?
102
- end
103
-
104
- it "false when not found" do
105
- non_existant_directory = directory.join("oh_no")
106
- refute ::File.exist?(non_existant_directory.to_s)
107
-
108
- non_existant_file_path = directory.join("abc.txt")
109
- refute ::File.exist?(non_existant_file_path.to_s)
110
-
111
- refute non_existant_directory.exist?
112
- refute non_existant_file_path.exist?
113
- end
114
- end
115
-
116
- describe "#size" do
117
- it "of file" do
118
- assert_equal data.size, file_path.size
119
- end
120
- end
121
-
122
- describe "#realpath" do
123
- it "already a real path" do
124
- path = ::File.expand_path(__dir__, "../files/test.csv")
125
- assert_equal path, IOStreams::Paths::File.new(path).realpath.to_s
126
- end
127
-
128
- it "removes .." do
129
- path = ::File.join(__dir__, "../files/test.csv")
130
- realpath = ::File.realpath(path)
131
- assert_equal realpath, IOStreams::Paths::File.new(path).realpath.to_s
132
- end
133
- end
134
-
135
- describe "#move_to" do
136
- it "move_to existing file" do
137
- IOStreams.temp_file("iostreams_move_test", ".txt") do |temp_file|
138
- temp_file.write("Hello World")
139
- begin
140
- target = temp_file.directory.join("move_test.txt")
141
- response = temp_file.move_to(target)
142
- assert_equal target, response
143
- assert target.exist?
144
- refute temp_file.exist?
145
- assert_equal "Hello World", response.read
146
- assert_equal target.to_s, response.to_s
147
- ensure
148
- target&.delete
149
- end
150
- end
151
- end
152
-
153
- it "missing source file" do
154
- IOStreams.temp_file("iostreams_move_test", ".txt") do |temp_file|
155
- refute temp_file.exist?
156
- target = temp_file.directory.join("move_test.txt")
157
- assert_raises Errno::ENOENT do
158
- temp_file.move_to(target)
159
- end
160
- refute target.exist?
161
- refute temp_file.exist?
162
- end
163
- end
164
-
165
- it "missing target directories" do
166
- IOStreams.temp_file("iostreams_move_test", ".txt") do |temp_file|
167
- temp_file.write("Hello World")
168
- begin
169
- target = temp_file.directory.join("a/b/c/move_test.txt")
170
- response = temp_file.move_to(target)
171
- assert_equal target, response
172
- assert target.exist?
173
- refute temp_file.exist?
174
- assert_equal "Hello World", response.read
175
- assert_equal target.to_s, response.to_s
176
- ensure
177
- temp_file.directory.join("a").delete_all
178
- end
179
- end
180
- end
181
- end
182
-
183
- describe "#delete" do
184
- it "deletes existing file" do
185
- assert ::File.exist?(file_path.to_s)
186
- file_path.delete
187
- refute ::File.exist?(file_path.to_s)
188
- end
189
-
190
- it "ignores missing file" do
191
- file_path.delete
192
- file_path.delete
193
- end
194
- end
195
-
196
- describe "reader" do
197
- it "reads file" do
198
- assert_equal data, file_path.read
199
- end
200
- end
201
-
202
- describe "writer" do
203
- it "creates file" do
204
- new_file_path = directory.join("new.txt")
205
- refute ::File.exist?(new_file_path.to_s)
206
- new_file_path.writer { |io| io << data }
207
- assert ::File.exist?(new_file_path.to_s)
208
- assert_equal data.size, new_file_path.size
209
- end
210
- end
211
- end
212
- end
213
- end
@@ -1,34 +0,0 @@
1
- require_relative "../test_helper"
2
-
3
- module Paths
4
- class HTTPTest < Minitest::Test
5
- describe IOStreams::Paths::HTTP do
6
- let :url do
7
- "http://example.com/index.html?count=10"
8
- end
9
-
10
- let :ssl_url do
11
- "https://example.com/index.html?count=10"
12
- end
13
-
14
- describe ".open" do
15
- it "reads http" do
16
- result = IOStreams::Paths::HTTP.new(url).read
17
- assert_includes result, "<html>"
18
- end
19
-
20
- it "reads https" do
21
- result = IOStreams::Paths::HTTP.new(ssl_url).read
22
- assert_includes result, "<html>"
23
- end
24
-
25
- it "does not support streams" do
26
- assert_raises URI::InvalidURIError do
27
- io = StringIO.new
28
- IOStreams::Paths::HTTP.new(io)
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
@@ -1,120 +0,0 @@
1
- require_relative "../test_helper"
2
-
3
- module Paths
4
- class MatcherTest < Minitest::Test
5
- describe IOStreams::Paths::Matcher do
6
- let :cases do
7
- [
8
- {
9
- path: "/path/work",
10
- pattern: "a/b/c/**/*",
11
- expected_path: "/path/work/a/b/c",
12
- expected_pattern: "**/*",
13
- recursive: true,
14
- matches: %w[/path/work/a/b/c/any/file /path/work/a/b/c/other/file],
15
- not_matches: %w[/path/work/a/b/c/.profile /path/work/a/b/c/sub/.name]
16
- },
17
- {path: "/path/work", pattern: "a/b/c?/**", expected_path: "/path/work/a/b", expected_pattern: "c?/**", recursive: true},
18
- {path: "/path/work", pattern: "**", expected_path: "/path/work", expected_pattern: "**", recursive: true},
19
- # Case-insensitive exists that returns the actual file name.
20
- {path: "/path/work", pattern: "a/b/file.txt", expected_path: "/path/work/a/b/file.txt", expected_pattern: nil, recursive: false},
21
- {
22
- path: "/path/work",
23
- pattern: "a/b/file*{zip,gz}",
24
- expected_path: "/path/work/a/b",
25
- expected_pattern: "file*{zip,gz}",
26
- recursive: false,
27
- matches: %w[/path/work/a/b/file.GZ /path/work/a/b/FILE.ZIP /path/work/a/b/file123.zIp],
28
- not_matches: %w[/path/work/a/b/.profile /path/work/a/b/filter.zip /path/work/a/b/outgoing/filter.zip],
29
- case_sensitive: false
30
- },
31
- {
32
- path: "/path/work",
33
- pattern: "a/b/*",
34
- expected_path: "/path/work/a/b",
35
- expected_pattern: "*",
36
- recursive: false,
37
- matches: %w[/path/work/a/b/file.GZ /path/work/a/b/FILE.ZIP /path/work/a/b/file123.zIp],
38
- not_matches: %w[/path/work/a/b/.profile /path/work/a/b/my/filter.zip /path/work/a/b/outgoing/filter.zip],
39
- case_sensitive: false
40
- },
41
- {
42
- path: "/path/work",
43
- pattern: "a/b/file*{zip,gz}",
44
- expected_path: "/path/work/a/b",
45
- expected_pattern: "file*{zip,gz}",
46
- recursive: false,
47
- matches: %w[/path/work/a/b/file.gz /path/work/a/b/file.zip],
48
- not_matches: %w[/path/work/a/b/file.GZ /path/work/a/b/FILE.ZIP],
49
- case_sensitive: true
50
- },
51
- {path: "/path/work", pattern: "file.txt", expected_path: "/path/work/file.txt", expected_pattern: nil, recursive: false},
52
- {path: "/path/work", pattern: "*", expected_path: "/path/work", expected_pattern: "*", recursive: false}
53
- ]
54
- end
55
- # , case_sensitive: false, hidden: false
56
-
57
- describe "#recursive?" do
58
- it "identifies recursive paths correctly" do
59
- cases.each do |test_case|
60
- path = IOStreams.path(test_case[:path])
61
- matcher = IOStreams::Paths::Matcher.new(path, test_case[:pattern])
62
- assert_equal test_case[:recursive], matcher.recursive?, test_case
63
- end
64
- end
65
- end
66
-
67
- describe "#path?" do
68
- it "optimizes path correctly" do
69
- cases.each do |test_case|
70
- path = IOStreams.path(test_case[:path])
71
- matcher = IOStreams::Paths::Matcher.new(path, test_case[:pattern])
72
- assert_equal test_case[:expected_path], matcher.path.to_s, test_case
73
- end
74
- end
75
- end
76
-
77
- describe "#pattern" do
78
- it "optimizes pattern correctly" do
79
- cases.each do |test_case|
80
- path = IOStreams.path(test_case[:path])
81
- matcher = IOStreams::Paths::Matcher.new(path, test_case[:pattern])
82
- if test_case[:expected_pattern].nil?
83
- assert_nil matcher.pattern, test_case
84
- else
85
- assert_equal test_case[:expected_pattern], matcher.pattern, test_case
86
- end
87
- end
88
- end
89
- end
90
-
91
- describe "#match?" do
92
- it "matches" do
93
- cases.each do |test_case|
94
- path = IOStreams.path(test_case[:path])
95
- case_sensitive = test_case.fetch(:case_sensitive, false)
96
- matcher = IOStreams::Paths::Matcher.new(path, test_case[:pattern], case_sensitive: case_sensitive)
97
- next unless test_case[:matches]
98
-
99
- test_case[:matches].each do |file_name|
100
- assert matcher.match?(file_name), test_case.merge(file_name: file_name)
101
- end
102
- end
103
- end
104
-
105
- it "should not match" do
106
- cases.each_with_index do |test_case, index|
107
- path = IOStreams.path(test_case[:path])
108
- case_sensitive = test_case.key?(:case_sensitive) ? test_case[:case_sensitive] : false
109
- matcher = IOStreams::Paths::Matcher.new(path, test_case[:pattern], case_sensitive: case_sensitive)
110
- next unless test_case[:not_matches]
111
-
112
- test_case[:not_matches].each do |file_name|
113
- refute matcher.match?(file_name), -> { {case_sensitive: case_sensitive, test_case_number: index + 1, failed_file_name: file_name, test_case: test_case}.ai }
114
- end
115
- end
116
- end
117
- end
118
- end
119
- end
120
- end
@@ -1,220 +0,0 @@
1
- require_relative "../test_helper"
2
-
3
- module Paths
4
- class S3Test < Minitest::Test
5
- describe IOStreams::Paths::S3 do
6
- before do
7
- skip "Supply 'S3_BUCKET_NAME' environment variable with S3 bucket name to test S3 paths" unless ENV["S3_BUCKET_NAME"]
8
- end
9
-
10
- let :file_name do
11
- File.join(File.dirname(__FILE__), "..", "files", "text file.txt")
12
- end
13
-
14
- let :raw do
15
- File.read(file_name)
16
- end
17
-
18
- let(:root_path) { IOStreams::Paths::S3.new("s3://#{ENV['S3_BUCKET_NAME']}/iostreams_test") }
19
-
20
- let :existing_path do
21
- path = root_path.join("test.txt")
22
- path.write(raw) unless path.exist?
23
- path
24
- end
25
-
26
- let :missing_path do
27
- root_path.join("unknown.txt")
28
- end
29
-
30
- let :write_path do
31
- root_path.join("writer_test.txt").delete
32
- end
33
-
34
- describe "#delete" do
35
- it "existing file" do
36
- assert existing_path.delete.is_a?(IOStreams::Paths::S3)
37
- end
38
-
39
- it "missing file" do
40
- assert missing_path.delete.is_a?(IOStreams::Paths::S3)
41
- end
42
- end
43
-
44
- describe "#exist?" do
45
- it "existing file" do
46
- assert existing_path.exist?
47
- end
48
-
49
- it "missing file" do
50
- refute missing_path.exist?
51
- end
52
- end
53
-
54
- describe "#mkpath" do
55
- it "returns self for non-existant path" do
56
- assert existing_path.mkpath.is_a?(IOStreams::Paths::S3)
57
- end
58
-
59
- it "checks for lack of existence" do
60
- assert missing_path.mkpath.is_a?(IOStreams::Paths::S3)
61
- end
62
- end
63
-
64
- describe "#mkdir" do
65
- it "returns self for non-existant path" do
66
- assert existing_path.mkdir.is_a?(IOStreams::Paths::S3)
67
- end
68
-
69
- it "checks for lack of existence" do
70
- assert missing_path.mkdir.is_a?(IOStreams::Paths::S3)
71
- end
72
- end
73
-
74
- describe "#reader" do
75
- it "reads" do
76
- assert_equal raw, existing_path.read
77
- end
78
- end
79
-
80
- describe "#size" do
81
- it "existing file" do
82
- assert_equal raw.size, existing_path.size
83
- end
84
-
85
- it "missing file" do
86
- assert_nil missing_path.size
87
- end
88
- end
89
-
90
- describe "#writer" do
91
- it "writes" do
92
- assert_equal(raw.size, write_path.writer { |io| io.write(raw) })
93
- assert write_path.exist?
94
- assert_equal raw, write_path.read
95
- end
96
- end
97
-
98
- describe "#each_line" do
99
- it "reads line by line" do
100
- lines = []
101
- existing_path.each(:line) { |line| lines << line }
102
- assert_equal raw.lines.collect(&:chomp), lines
103
- end
104
- end
105
-
106
- describe "#each_child" do
107
- # TODO: case_sensitive: false, directories: false, hidden: false
108
- let(:abd_file_names) { %w[abd/test1.txt abd/test5.file abd/extra/file.csv] }
109
- let(:files_for_test) { abd_file_names + %w[xyz/test2.csv xyz/another.csv] }
110
-
111
- let :each_root do
112
- root_path.join("each_child_test")
113
- end
114
-
115
- let :multiple_paths do
116
- files_for_test.collect { |file_name| each_root.join(file_name) }
117
- end
118
-
119
- let :write_raw_data do
120
- multiple_paths.each { |path| path.write(raw) unless path.exist? }
121
- end
122
-
123
- it "existing file returns just the file itself" do
124
- # Glorified exists call
125
- existing_path
126
- assert_equal root_path.join("test.txt").to_s, root_path.children("test.txt").first.to_s
127
- end
128
-
129
- it "missing file does nothing" do
130
- # Glorified exists call
131
- assert_equal [], missing_path.children("readme").collect(&:to_s)
132
- end
133
-
134
- it "returns all the children" do
135
- write_raw_data
136
- assert_equal multiple_paths.collect(&:to_s).sort, each_root.children("**/*").collect(&:to_s).sort
137
- end
138
-
139
- it "returns all the children under a sub-dir" do
140
- write_raw_data
141
- expected = %w[abd/test1.txt abd/test5.file].collect { |file_name| each_root.join(file_name) }
142
- assert_equal expected.collect(&:to_s).sort, each_root.children("abd/*").collect(&:to_s).sort
143
- end
144
-
145
- it "missing path" do
146
- count = 0
147
- missing_path.each_child { |_| count += 1 }
148
- assert_equal 0, count
149
- end
150
-
151
- # Test is here since all the test artifacts have been created already in S3.
152
- describe "IOStreams.each_child" do
153
- it "returns all the children" do
154
- write_raw_data
155
- children = []
156
- IOStreams.each_child(each_root.join("**/*").to_s) { |child| children << child }
157
- assert_equal multiple_paths.collect(&:to_s).sort, children.collect(&:to_s).sort
158
- end
159
- end
160
- end
161
-
162
- describe "#move_to" do
163
- it "moves existing file" do
164
- source = root_path.join("move_test_source.txt")
165
- begin
166
- source.write("Hello World")
167
- target = source.directory.join("move_test_target.txt")
168
- response = source.move_to(target)
169
- assert_equal target, response
170
- assert target.exist?
171
- refute source.exist?
172
- assert_equal "Hello World", response.read
173
- assert_equal target.to_s, response.to_s
174
- ensure
175
- source&.delete
176
- target&.delete
177
- end
178
- end
179
-
180
- it "missing source file" do
181
- source = root_path.join("move_test_source.txt")
182
- refute source.exist?
183
- begin
184
- target = source.directory.join("move_test_target.txt")
185
- assert_raises Aws::S3::Errors::NoSuchKey do
186
- source.move_to(target)
187
- end
188
- refute target.exist?
189
- ensure
190
- source&.delete
191
- target&.delete
192
- end
193
- end
194
-
195
- it "missing target directories" do
196
- source = root_path.join("move_test_source.txt")
197
- begin
198
- source.write("Hello World")
199
- target = source.directory.join("a/b/c/move_test_target.txt")
200
- response = source.move_to(target)
201
- assert_equal target, response
202
- assert target.exist?
203
- refute source.exist?
204
- assert_equal "Hello World", response.read
205
- assert_equal target.to_s, response.to_s
206
- ensure
207
- source&.delete
208
- target&.delete
209
- end
210
- end
211
- end
212
-
213
- describe "#partial_files_visible?" do
214
- it "visible only after upload" do
215
- refute root_path.partial_files_visible?
216
- end
217
- end
218
- end
219
- end
220
- end
@@ -1,106 +0,0 @@
1
- require_relative "../test_helper"
2
-
3
- module Paths
4
- class SFTPTest < Minitest::Test
5
- describe IOStreams::Paths::SFTP do
6
- before do
7
- unless ENV["SFTP_HOSTNAME"]
8
- skip "Supply environment variables to test SFTP paths: SFTP_HOSTNAME, SFTP_USERNAME, SFTP_PASSWORD, and optional SFTP_DIR, SFTP_IDENTITY_FILE"
9
- end
10
- end
11
-
12
- let(:host_name) { ENV["SFTP_HOSTNAME"] }
13
- let(:username) { ENV["SFTP_USERNAME"] }
14
- let(:password) { ENV["SFTP_PASSWORD"] }
15
- let(:ftp_dir) { ENV["SFTP_DIR"] || "iostreams_test" }
16
- let(:identity_username) { ENV["SFTP_IDENTITY_USERNAME"] || username }
17
-
18
- let(:url) { File.join("sftp://", host_name, ftp_dir) }
19
-
20
- let(:file_name) { File.join(File.dirname(__FILE__), "..", "files", "text file.txt") }
21
- let(:raw) { File.read(file_name) }
22
-
23
- let(:root_path) do
24
- if ENV["SFTP_HOST_KEY"]
25
- IOStreams::Paths::SFTP.new(url, username: username, password: password, ssh_options: {"HostKey" => ENV["SFTP_HOST_KEY"]})
26
- else
27
- IOStreams::Paths::SFTP.new(url, username: username, password: password)
28
- end
29
- end
30
-
31
- let :existing_path do
32
- path = root_path.join("test.txt")
33
- path.write(raw)
34
- path
35
- end
36
-
37
- let :missing_path do
38
- root_path.join("unknown_path", "test_file.txt")
39
- end
40
-
41
- let :missing_file_path do
42
- root_path.join("test_file.txt")
43
- end
44
-
45
- let :write_path do
46
- root_path.join("writer_test.txt")
47
- end
48
-
49
- describe "#reader" do
50
- it "reads" do
51
- assert_equal raw, existing_path.read
52
- end
53
-
54
- it "fails when the file does not exist" do
55
- assert_raises IOStreams::Errors::CommunicationsFailure do
56
- missing_file_path.read
57
- end
58
- end
59
-
60
- it "fails when the directory does not exist" do
61
- assert_raises IOStreams::Errors::CommunicationsFailure do
62
- missing_path.read
63
- end
64
- end
65
- end
66
-
67
- describe "#writer" do
68
- it "writes" do
69
- assert_equal(raw.size, write_path.writer { |io| io.write(raw) })
70
- assert_equal raw, write_path.read
71
- end
72
-
73
- it "fails when the directory does not exist" do
74
- assert_raises IOStreams::Errors::CommunicationsFailure do
75
- missing_path.write("Bad path")
76
- end
77
- end
78
-
79
- describe "use identity file instead of password" do
80
- let :root_path do
81
- IOStreams::Paths::SFTP.new(url, username: identity_username, ssh_options: {"IdentityFile" => ENV["SFTP_IDENTITY_FILE"]})
82
- end
83
-
84
- it "writes" do
85
- skip "No identity file env var set: SFTP_IDENTITY_FILE" unless ENV["SFTP_IDENTITY_FILE"]
86
- assert_equal(raw.size, write_path.writer { |io| io.write(raw) })
87
- assert_equal raw, write_path.read
88
- end
89
- end
90
-
91
- describe "use identity key instead of password" do
92
- let :root_path do
93
- key = File.open(ENV["SFTP_IDENTITY_FILE"], "rb", &:read)
94
- IOStreams::Paths::SFTP.new(url, username: identity_username, ssh_options: {"IdentityKey" => key})
95
- end
96
-
97
- it "writes" do
98
- skip "No identity file env var set: SFTP_IDENTITY_FILE" unless ENV["SFTP_IDENTITY_FILE"]
99
- assert_equal(raw.size, write_path.writer { |io| io.write(raw) })
100
- assert_equal raw, write_path.read
101
- end
102
- end
103
- end
104
- end
105
- end
106
- end