iostreams 1.10.3 → 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.
- checksums.yaml +4 -4
- data/README.md +20 -2
- data/Rakefile +7 -0
- data/lib/io_streams/builder.rb +10 -10
- data/lib/io_streams/bzip2/writer.rb +1 -1
- data/lib/io_streams/encode/reader.rb +2 -2
- data/lib/io_streams/encode/writer.rb +5 -5
- data/lib/io_streams/gzip/reader.rb +1 -1
- data/lib/io_streams/gzip/writer.rb +1 -1
- data/lib/io_streams/io_streams.rb +47 -21
- data/lib/io_streams/line/reader.rb +2 -2
- data/lib/io_streams/line/writer.rb +1 -1
- data/lib/io_streams/path.rb +2 -2
- data/lib/io_streams/paths/file.rb +25 -11
- data/lib/io_streams/paths/http.rb +80 -7
- data/lib/io_streams/paths/matcher.rb +3 -3
- data/lib/io_streams/paths/s3.rb +22 -3
- data/lib/io_streams/paths/sftp.rb +9 -10
- data/lib/io_streams/pgp/reader.rb +25 -7
- data/lib/io_streams/pgp/writer.rb +95 -29
- data/lib/io_streams/pgp.rb +289 -87
- data/lib/io_streams/reader.rb +4 -4
- data/lib/io_streams/record/reader.rb +3 -4
- data/lib/io_streams/record/writer.rb +3 -4
- data/lib/io_streams/row/reader.rb +1 -1
- data/lib/io_streams/row/writer.rb +1 -1
- data/lib/io_streams/stream.rb +36 -30
- data/lib/io_streams/symmetric_encryption/reader.rb +2 -2
- data/lib/io_streams/symmetric_encryption/writer.rb +4 -4
- data/lib/io_streams/tabular/header.rb +18 -6
- data/lib/io_streams/tabular/parser/array.rb +0 -10
- data/lib/io_streams/tabular/parser/csv.rb +6 -38
- data/lib/io_streams/tabular/parser/fixed.rb +5 -5
- data/lib/io_streams/tabular/parser/psv.rb +0 -12
- data/lib/io_streams/tabular.rb +5 -10
- data/lib/io_streams/utils.rb +6 -8
- data/lib/io_streams/version.rb +1 -1
- data/lib/io_streams/writer.rb +6 -6
- data/lib/io_streams/xlsx/reader.rb +1 -1
- data/lib/io_streams/zip/writer.rb +22 -10
- data/lib/iostreams.rb +0 -1
- metadata +28 -113
- data/lib/io_streams/deprecated.rb +0 -216
- data/lib/io_streams/tabular/utility/csv_row.rb +0 -105
- data/test/builder_test.rb +0 -311
- data/test/bzip2_reader_test.rb +0 -27
- data/test/bzip2_writer_test.rb +0 -56
- data/test/deprecated_test.rb +0 -121
- data/test/encode_reader_test.rb +0 -51
- data/test/encode_writer_test.rb +0 -90
- data/test/files/embedded_lines_test.csv +0 -7
- data/test/files/multiple_files.zip +0 -0
- data/test/files/spreadsheet.xlsx +0 -0
- data/test/files/test.csv +0 -4
- data/test/files/test.json +0 -3
- data/test/files/test.psv +0 -4
- data/test/files/text file.txt +0 -3
- data/test/files/text.txt +0 -3
- data/test/files/text.txt.bz2 +0 -0
- data/test/files/text.txt.gz +0 -0
- data/test/files/text.txt.gz.zip +0 -0
- data/test/files/text.zip +0 -0
- data/test/files/text.zip.gz +0 -0
- data/test/files/unclosed_quote_large_test.csv +0 -1658
- data/test/files/unclosed_quote_test.csv +0 -4
- data/test/files/unclosed_quote_test2.csv +0 -3
- data/test/files/utf16_test.csv +0 -0
- data/test/gzip_reader_test.rb +0 -27
- data/test/gzip_writer_test.rb +0 -52
- data/test/io_streams_test.rb +0 -132
- data/test/line_reader_test.rb +0 -325
- data/test/line_writer_test.rb +0 -59
- data/test/minimal_file_reader.rb +0 -25
- data/test/path_test.rb +0 -55
- data/test/paths/file_test.rb +0 -202
- data/test/paths/http_test.rb +0 -34
- data/test/paths/matcher_test.rb +0 -120
- data/test/paths/s3_test.rb +0 -220
- data/test/paths/sftp_test.rb +0 -106
- data/test/pgp_reader_test.rb +0 -46
- data/test/pgp_test.rb +0 -254
- data/test/pgp_writer_test.rb +0 -130
- data/test/record_reader_test.rb +0 -60
- data/test/record_writer_test.rb +0 -82
- data/test/row_reader_test.rb +0 -35
- data/test/row_writer_test.rb +0 -56
- data/test/stream_test.rb +0 -574
- data/test/tabular_test.rb +0 -338
- data/test/test_helper.rb +0 -40
- data/test/utils_test.rb +0 -20
- data/test/xlsx_reader_test.rb +0 -37
- data/test/zip_reader_test.rb +0 -53
- data/test/zip_writer_test.rb +0 -48
data/test/paths/file_test.rb
DELETED
|
@@ -1,202 +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
|
-
expected = [file_path.to_s, file_path2.to_s]
|
|
50
|
-
actual = root.children("**/Test*.TXT").collect(&:to_s)
|
|
51
|
-
assert_equal expected, actual.sort
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it "find matches case-sensitive" do
|
|
55
|
-
skip "TODO"
|
|
56
|
-
expected = [file_path.to_s, file_path2.to_s]
|
|
57
|
-
actual = root.children("**/Test*.TXT", case_sensitive: true).collect(&:to_s)
|
|
58
|
-
refute_equal expected, actual.sort
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it "with no block returns enumerator" do
|
|
62
|
-
expected = [file_path.to_s, file_path2.to_s]
|
|
63
|
-
actual = root.each_child("**/*").first(100).collect(&:to_s)
|
|
64
|
-
assert_equal expected.sort, actual.sort
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
describe "#mkpath" do
|
|
69
|
-
it "makes path skipping file_name" do
|
|
70
|
-
new_path = directory.join("test_mkpath.xls").mkpath
|
|
71
|
-
assert ::File.exist?(directory.to_s)
|
|
72
|
-
refute ::File.exist?(new_path.to_s)
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
describe "#mkdir" do
|
|
77
|
-
it "makes entire path that does not have a file name" do
|
|
78
|
-
new_path = directory.join("more_path").mkdir
|
|
79
|
-
assert ::File.exist?(directory.to_s)
|
|
80
|
-
assert ::File.exist?(new_path.to_s)
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
describe "#exist?" do
|
|
85
|
-
it "true on existing file or directory" do
|
|
86
|
-
assert ::File.exist?(file_path.to_s)
|
|
87
|
-
assert ::File.exist?(directory.to_s)
|
|
88
|
-
|
|
89
|
-
assert directory.exist?
|
|
90
|
-
assert file_path.exist?
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
it "false when not found" do
|
|
94
|
-
non_existant_directory = directory.join("oh_no")
|
|
95
|
-
refute ::File.exist?(non_existant_directory.to_s)
|
|
96
|
-
|
|
97
|
-
non_existant_file_path = directory.join("abc.txt")
|
|
98
|
-
refute ::File.exist?(non_existant_file_path.to_s)
|
|
99
|
-
|
|
100
|
-
refute non_existant_directory.exist?
|
|
101
|
-
refute non_existant_file_path.exist?
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
describe "#size" do
|
|
106
|
-
it "of file" do
|
|
107
|
-
assert_equal data.size, file_path.size
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
describe "#realpath" do
|
|
112
|
-
it "already a real path" do
|
|
113
|
-
path = ::File.expand_path(__dir__, "../files/test.csv")
|
|
114
|
-
assert_equal path, IOStreams::Paths::File.new(path).realpath.to_s
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
it "removes .." do
|
|
118
|
-
path = ::File.join(__dir__, "../files/test.csv")
|
|
119
|
-
realpath = ::File.realpath(path)
|
|
120
|
-
assert_equal realpath, IOStreams::Paths::File.new(path).realpath.to_s
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
describe "#move_to" do
|
|
125
|
-
it "move_to existing file" do
|
|
126
|
-
IOStreams.temp_file("iostreams_move_test", ".txt") do |temp_file|
|
|
127
|
-
temp_file.write("Hello World")
|
|
128
|
-
begin
|
|
129
|
-
target = temp_file.directory.join("move_test.txt")
|
|
130
|
-
response = temp_file.move_to(target)
|
|
131
|
-
assert_equal target, response
|
|
132
|
-
assert target.exist?
|
|
133
|
-
refute temp_file.exist?
|
|
134
|
-
assert_equal "Hello World", response.read
|
|
135
|
-
assert_equal target.to_s, response.to_s
|
|
136
|
-
ensure
|
|
137
|
-
target&.delete
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
it "missing source file" do
|
|
143
|
-
IOStreams.temp_file("iostreams_move_test", ".txt") do |temp_file|
|
|
144
|
-
refute temp_file.exist?
|
|
145
|
-
target = temp_file.directory.join("move_test.txt")
|
|
146
|
-
assert_raises Errno::ENOENT do
|
|
147
|
-
temp_file.move_to(target)
|
|
148
|
-
end
|
|
149
|
-
refute target.exist?
|
|
150
|
-
refute temp_file.exist?
|
|
151
|
-
end
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
it "missing target directories" do
|
|
155
|
-
IOStreams.temp_file("iostreams_move_test", ".txt") do |temp_file|
|
|
156
|
-
temp_file.write("Hello World")
|
|
157
|
-
begin
|
|
158
|
-
target = temp_file.directory.join("a/b/c/move_test.txt")
|
|
159
|
-
response = temp_file.move_to(target)
|
|
160
|
-
assert_equal target, response
|
|
161
|
-
assert target.exist?
|
|
162
|
-
refute temp_file.exist?
|
|
163
|
-
assert_equal "Hello World", response.read
|
|
164
|
-
assert_equal target.to_s, response.to_s
|
|
165
|
-
ensure
|
|
166
|
-
temp_file.directory.join("a").delete_all
|
|
167
|
-
end
|
|
168
|
-
end
|
|
169
|
-
end
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
describe "#delete" do
|
|
173
|
-
it "deletes existing file" do
|
|
174
|
-
assert ::File.exist?(file_path.to_s)
|
|
175
|
-
file_path.delete
|
|
176
|
-
refute ::File.exist?(file_path.to_s)
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
it "ignores missing file" do
|
|
180
|
-
file_path.delete
|
|
181
|
-
file_path.delete
|
|
182
|
-
end
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
describe "reader" do
|
|
186
|
-
it "reads file" do
|
|
187
|
-
assert_equal data, file_path.read
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
describe "writer" do
|
|
192
|
-
it "creates file" do
|
|
193
|
-
new_file_path = directory.join("new.txt")
|
|
194
|
-
refute ::File.exist?(new_file_path.to_s)
|
|
195
|
-
new_file_path.writer { |io| io << data }
|
|
196
|
-
assert ::File.exist?(new_file_path.to_s)
|
|
197
|
-
assert_equal data.size, new_file_path.size
|
|
198
|
-
end
|
|
199
|
-
end
|
|
200
|
-
end
|
|
201
|
-
end
|
|
202
|
-
end
|
data/test/paths/http_test.rb
DELETED
|
@@ -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
|
data/test/paths/matcher_test.rb
DELETED
|
@@ -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
|
data/test/paths/s3_test.rb
DELETED
|
@@ -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
|
data/test/paths/sftp_test.rb
DELETED
|
@@ -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
|