iostreams 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/Rakefile +7 -7
- data/lib/io_streams/builder.rb +4 -3
- data/lib/io_streams/bzip2/reader.rb +1 -1
- data/lib/io_streams/bzip2/writer.rb +1 -1
- data/lib/io_streams/deprecated.rb +2 -3
- data/lib/io_streams/encode/reader.rb +5 -8
- data/lib/io_streams/encode/writer.rb +1 -1
- data/lib/io_streams/io_streams.rb +5 -2
- data/lib/io_streams/line/reader.rb +2 -1
- data/lib/io_streams/path.rb +4 -4
- data/lib/io_streams/paths/http.rb +8 -10
- data/lib/io_streams/paths/matcher.rb +10 -11
- data/lib/io_streams/paths/s3.rb +6 -6
- data/lib/io_streams/paths/sftp.rb +38 -23
- data/lib/io_streams/pgp.rb +45 -35
- data/lib/io_streams/pgp/reader.rb +4 -6
- data/lib/io_streams/pgp/writer.rb +1 -2
- data/lib/io_streams/reader.rb +2 -2
- data/lib/io_streams/record/writer.rb +2 -4
- data/lib/io_streams/row/writer.rb +3 -5
- data/lib/io_streams/stream.rb +6 -6
- data/lib/io_streams/symmetric_encryption/reader.rb +1 -3
- data/lib/io_streams/symmetric_encryption/writer.rb +2 -6
- data/lib/io_streams/tabular.rb +12 -10
- data/lib/io_streams/tabular/header.rb +4 -4
- data/lib/io_streams/tabular/parser/array.rb +2 -4
- data/lib/io_streams/tabular/parser/csv.rb +3 -5
- data/lib/io_streams/tabular/parser/fixed.rb +4 -3
- data/lib/io_streams/tabular/parser/hash.rb +2 -4
- data/lib/io_streams/tabular/parser/json.rb +2 -4
- data/lib/io_streams/tabular/parser/psv.rb +5 -7
- data/lib/io_streams/tabular/utility/csv_row.rb +9 -17
- data/lib/io_streams/utils.rb +3 -3
- data/lib/io_streams/utils/reliable_http.rb +98 -0
- data/lib/io_streams/version.rb +1 -1
- data/lib/io_streams/writer.rb +1 -1
- data/lib/io_streams/xlsx/reader.rb +5 -5
- data/lib/io_streams/zip/reader.rb +1 -1
- data/lib/io_streams/zip/writer.rb +2 -2
- data/lib/iostreams.rb +34 -34
- data/test/builder_test.rb +74 -74
- data/test/bzip2_reader_test.rb +8 -13
- data/test/bzip2_writer_test.rb +8 -9
- data/test/deprecated_test.rb +25 -29
- data/test/encode_reader_test.rb +14 -18
- data/test/encode_writer_test.rb +29 -30
- data/test/gzip_reader_test.rb +8 -13
- data/test/gzip_writer_test.rb +10 -11
- data/test/io_streams_test.rb +35 -35
- data/test/line_reader_test.rb +35 -39
- data/test/line_writer_test.rb +8 -9
- data/test/minimal_file_reader.rb +1 -1
- data/test/path_test.rb +24 -24
- data/test/paths/file_test.rb +42 -42
- data/test/paths/http_test.rb +5 -5
- data/test/paths/matcher_test.rb +11 -12
- data/test/paths/s3_test.rb +44 -46
- data/test/paths/sftp_test.rb +18 -18
- data/test/pgp_reader_test.rb +13 -15
- data/test/pgp_test.rb +43 -44
- data/test/pgp_writer_test.rb +27 -28
- data/test/record_reader_test.rb +9 -10
- data/test/record_writer_test.rb +10 -11
- data/test/row_reader_test.rb +5 -6
- data/test/row_writer_test.rb +7 -8
- data/test/stream_test.rb +60 -62
- data/test/tabular_test.rb +111 -111
- data/test/test_helper.rb +22 -22
- data/test/utils_test.rb +7 -7
- data/test/xlsx_reader_test.rb +12 -12
- data/test/zip_reader_test.rb +14 -21
- data/test/zip_writer_test.rb +10 -10
- metadata +4 -3
data/test/line_writer_test.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "test_helper"
|
2
2
|
|
3
3
|
class DelimitedWriterTest < Minitest::Test
|
4
4
|
describe IOStreams::Line::Writer do
|
5
5
|
let :file_name do
|
6
|
-
File.join(File.dirname(__FILE__),
|
6
|
+
File.join(File.dirname(__FILE__), "files", "text.txt")
|
7
7
|
end
|
8
8
|
|
9
9
|
let :raw do
|
@@ -14,9 +14,9 @@ class DelimitedWriterTest < Minitest::Test
|
|
14
14
|
raw.lines.map(&:strip)
|
15
15
|
end
|
16
16
|
|
17
|
-
describe
|
18
|
-
it
|
19
|
-
temp_file = Tempfile.new(
|
17
|
+
describe "#<<" do
|
18
|
+
it "file" do
|
19
|
+
temp_file = Tempfile.new("rocket_job")
|
20
20
|
file_name = temp_file.to_path
|
21
21
|
IOStreams::Line::Writer.file(file_name) do |io|
|
22
22
|
lines.each { |line| io << line }
|
@@ -25,7 +25,7 @@ class DelimitedWriterTest < Minitest::Test
|
|
25
25
|
assert_equal raw, result
|
26
26
|
end
|
27
27
|
|
28
|
-
it
|
28
|
+
it "stream" do
|
29
29
|
io_string = StringIO.new
|
30
30
|
IOStreams::Line::Writer.stream(io_string) do |io|
|
31
31
|
lines.each { |line| io << line }
|
@@ -34,8 +34,8 @@ class DelimitedWriterTest < Minitest::Test
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
describe
|
38
|
-
it
|
37
|
+
describe ".write" do
|
38
|
+
it "returns byte count" do
|
39
39
|
io_string = StringIO.new
|
40
40
|
count = 0
|
41
41
|
IOStreams::Line::Writer.stream(io_string) do |io|
|
@@ -45,6 +45,5 @@ class DelimitedWriterTest < Minitest::Test
|
|
45
45
|
assert_equal raw.size, count
|
46
46
|
end
|
47
47
|
end
|
48
|
-
|
49
48
|
end
|
50
49
|
end
|
data/test/minimal_file_reader.rb
CHANGED
data/test/path_test.rb
CHANGED
@@ -1,53 +1,53 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "test_helper"
|
2
2
|
|
3
3
|
module IOStreams
|
4
4
|
class PathTest < Minitest::Test
|
5
5
|
describe IOStreams::Path do
|
6
|
-
describe
|
7
|
-
let(:path) { IOStreams::Path.new(
|
6
|
+
describe ".join" do
|
7
|
+
let(:path) { IOStreams::Path.new("some_path") }
|
8
8
|
|
9
|
-
it
|
9
|
+
it "returns self when no elements" do
|
10
10
|
assert_equal path.object_id, path.join.object_id
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
14
|
-
assert_equal ::File.join(
|
13
|
+
it "adds element to path" do
|
14
|
+
assert_equal ::File.join("some_path", "test"), path.join("test").to_s
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
18
|
-
assert_equal ::File.join(
|
17
|
+
it "adds paths to root" do
|
18
|
+
assert_equal ::File.join("some_path", "test", "second", "third"), path.join("test", "second", "third").to_s
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
22
|
-
assert_equal ::File.join(
|
21
|
+
it "returns path and filename" do
|
22
|
+
assert_equal ::File.join("some_path", "file.xls"), path.join("file.xls").to_s
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
26
|
-
assert_equal ::File.join(
|
25
|
+
it "adds elements to path" do
|
26
|
+
assert_equal ::File.join("some_path", "test", "second", "third", "file.xls"), path.join("test", "second", "third", "file.xls").to_s
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
30
|
-
assert_equal ::File.join(
|
29
|
+
it "return path as sent in when full path" do
|
30
|
+
assert_equal ::File.join("some_path", "test", "second", "third", "file.xls"), path.join("some_path", "test", "second", "third", "file.xls").to_s
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
describe
|
35
|
-
it
|
36
|
-
assert_equal true, IOStreams::Path.new(
|
34
|
+
describe "#absolute?" do
|
35
|
+
it "true on absolute" do
|
36
|
+
assert_equal true, IOStreams::Path.new("/a/b/c/d").absolute?
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
40
|
-
assert_equal false, IOStreams::Path.new(
|
39
|
+
it "false when not absolute" do
|
40
|
+
assert_equal false, IOStreams::Path.new("a/b/c/d").absolute?
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
describe
|
45
|
-
it
|
46
|
-
assert_equal true, IOStreams::Path.new(
|
44
|
+
describe "#relatve?" do
|
45
|
+
it "true on relative" do
|
46
|
+
assert_equal true, IOStreams::Path.new("a/b/c/d").relative?
|
47
47
|
end
|
48
48
|
|
49
|
-
it
|
50
|
-
assert_equal false, IOStreams::Path.new(
|
49
|
+
it "false on absolute" do
|
50
|
+
assert_equal false, IOStreams::Path.new("/a/b/c/d").relative?
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
data/test/paths/file_test.rb
CHANGED
@@ -1,48 +1,48 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "../test_helper"
|
2
2
|
|
3
3
|
module Paths
|
4
4
|
class FileTest < Minitest::Test
|
5
5
|
describe IOStreams::Paths::File do
|
6
6
|
let(:root) { IOStreams::Paths::File.new("/tmp/iostreams").delete_all }
|
7
|
-
let(:directory) { root.join(
|
7
|
+
let(:directory) { root.join("/some_test_dir") }
|
8
8
|
let(:data) { "Hello World" }
|
9
9
|
let(:file_path) do
|
10
|
-
path = root.join(
|
10
|
+
path = root.join("some_test_dir/test_file.txt")
|
11
11
|
path.writer { |io| io << data }
|
12
12
|
path
|
13
13
|
end
|
14
14
|
let(:file_path2) do
|
15
|
-
path = root.join(
|
15
|
+
path = root.join("some_test_dir/test_file2.txt")
|
16
16
|
path.writer { |io| io << "Hello World2" }
|
17
17
|
path
|
18
18
|
end
|
19
19
|
|
20
|
-
describe
|
21
|
-
it
|
20
|
+
describe "#each_child" do
|
21
|
+
it "iterates an empty path" do
|
22
22
|
none = nil
|
23
|
-
directory.join(
|
23
|
+
directory.join("does_not_exist").mkdir.each_child { |path| none = path }
|
24
24
|
assert_nil none
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
27
|
+
it "iterates a non-existant path" do
|
28
28
|
none = nil
|
29
|
-
directory.join(
|
29
|
+
directory.join("does_not_exist").each_child { |path| none = path }
|
30
30
|
assert_nil none
|
31
31
|
end
|
32
32
|
|
33
|
-
it
|
33
|
+
it "find all files" do
|
34
34
|
expected = [file_path.to_s, file_path2.to_s]
|
35
35
|
actual = root.children("**/*").collect(&:to_s)
|
36
36
|
assert_equal expected.sort, actual.sort
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
39
|
+
it "find matches case-insensitive" do
|
40
40
|
expected = [file_path.to_s, file_path2.to_s]
|
41
41
|
actual = root.children("**/Test*.TXT").collect(&:to_s)
|
42
42
|
assert_equal expected, actual.sort
|
43
43
|
end
|
44
44
|
|
45
|
-
it
|
45
|
+
it "find matches case-sensitive" do
|
46
46
|
skip "TODO"
|
47
47
|
expected = [file_path.to_s, file_path2.to_s]
|
48
48
|
actual = root.children("**/Test*.TXT", case_sensitive: true).collect(&:to_s)
|
@@ -50,24 +50,24 @@ module Paths
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
describe
|
54
|
-
it
|
55
|
-
new_path = directory.join(
|
53
|
+
describe "#mkpath" do
|
54
|
+
it "makes path skipping file_name" do
|
55
|
+
new_path = directory.join("test_mkpath.xls").mkpath
|
56
56
|
assert ::File.exist?(directory.to_s)
|
57
57
|
refute ::File.exist?(new_path.to_s)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
describe
|
62
|
-
it
|
63
|
-
new_path = directory.join(
|
61
|
+
describe "#mkdir" do
|
62
|
+
it "makes entire path that does not have a file name" do
|
63
|
+
new_path = directory.join("more_path").mkdir
|
64
64
|
assert ::File.exist?(directory.to_s)
|
65
65
|
assert ::File.exist?(new_path.to_s)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
describe
|
70
|
-
it
|
69
|
+
describe "#exist?" do
|
70
|
+
it "true on existing file or directory" do
|
71
71
|
assert ::File.exist?(file_path.to_s)
|
72
72
|
assert ::File.exist?(directory.to_s)
|
73
73
|
|
@@ -75,8 +75,8 @@ module Paths
|
|
75
75
|
assert file_path.exist?
|
76
76
|
end
|
77
77
|
|
78
|
-
it
|
79
|
-
non_existant_directory = directory.join(
|
78
|
+
it "false when not found" do
|
79
|
+
non_existant_directory = directory.join("oh_no")
|
80
80
|
refute ::File.exist?(non_existant_directory.to_s)
|
81
81
|
|
82
82
|
non_existant_file_path = directory.join("abc.txt")
|
@@ -87,31 +87,31 @@ module Paths
|
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
|
-
describe
|
91
|
-
it
|
90
|
+
describe "#size" do
|
91
|
+
it "of file" do
|
92
92
|
assert_equal data.size, file_path.size
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
describe
|
97
|
-
it
|
98
|
-
path = ::File.expand_path(__dir__,
|
96
|
+
describe "#realpath" do
|
97
|
+
it "already a real path" do
|
98
|
+
path = ::File.expand_path(__dir__, "../files/test.csv")
|
99
99
|
assert_equal path, IOStreams::Paths::File.new(path).realpath.to_s
|
100
100
|
end
|
101
101
|
|
102
|
-
it
|
103
|
-
path = ::File.join(__dir__,
|
102
|
+
it "removes .." do
|
103
|
+
path = ::File.join(__dir__, "../files/test.csv")
|
104
104
|
realpath = ::File.realpath(path)
|
105
105
|
assert_equal realpath, IOStreams::Paths::File.new(path).realpath.to_s
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
-
describe
|
110
|
-
it
|
109
|
+
describe "#move_to" do
|
110
|
+
it "move_to existing file" do
|
111
111
|
IOStreams.temp_file("iostreams_move_test", ".txt") do |temp_file|
|
112
112
|
temp_file.write("Hello World")
|
113
113
|
begin
|
114
|
-
target
|
114
|
+
target = temp_file.directory.join("move_test.txt")
|
115
115
|
response = temp_file.move_to(target)
|
116
116
|
assert_equal target, response
|
117
117
|
assert target.exist?
|
@@ -124,7 +124,7 @@ module Paths
|
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
|
-
it
|
127
|
+
it "missing source file" do
|
128
128
|
IOStreams.temp_file("iostreams_move_test", ".txt") do |temp_file|
|
129
129
|
begin
|
130
130
|
refute temp_file.exist?
|
@@ -138,11 +138,11 @@ module Paths
|
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
141
|
-
it
|
141
|
+
it "missing target directories" do
|
142
142
|
IOStreams.temp_file("iostreams_move_test", ".txt") do |temp_file|
|
143
143
|
temp_file.write("Hello World")
|
144
144
|
begin
|
145
|
-
target
|
145
|
+
target = temp_file.directory.join("a/b/c/move_test.txt")
|
146
146
|
response = temp_file.move_to(target)
|
147
147
|
assert_equal target, response
|
148
148
|
assert target.exist?
|
@@ -156,27 +156,27 @@ module Paths
|
|
156
156
|
end
|
157
157
|
end
|
158
158
|
|
159
|
-
describe
|
160
|
-
it
|
159
|
+
describe "#delete" do
|
160
|
+
it "deletes existing file" do
|
161
161
|
assert ::File.exist?(file_path.to_s)
|
162
162
|
file_path.delete
|
163
163
|
refute ::File.exist?(file_path.to_s)
|
164
164
|
end
|
165
165
|
|
166
|
-
it
|
166
|
+
it "ignores missing file" do
|
167
167
|
file_path.delete
|
168
168
|
file_path.delete
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
172
|
-
describe
|
173
|
-
it
|
172
|
+
describe "reader" do
|
173
|
+
it "reads file" do
|
174
174
|
assert_equal data, file_path.reader(&:read)
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
178
|
-
describe
|
179
|
-
it
|
178
|
+
describe "writer" do
|
179
|
+
it "creates file" do
|
180
180
|
new_file_path = directory.join("new.txt")
|
181
181
|
refute ::File.exist?(new_file_path.to_s)
|
182
182
|
new_file_path.writer { |io| io << data }
|
data/test/paths/http_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "../test_helper"
|
2
2
|
|
3
3
|
module Paths
|
4
4
|
class HTTPTest < Minitest::Test
|
@@ -11,18 +11,18 @@ module Paths
|
|
11
11
|
"https://example.com/index.html?count=10"
|
12
12
|
end
|
13
13
|
|
14
|
-
describe
|
15
|
-
it
|
14
|
+
describe ".open" do
|
15
|
+
it "reads http" do
|
16
16
|
result = IOStreams::Paths::HTTP.new(url).read
|
17
17
|
assert_includes result, "<html>"
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
20
|
+
it "reads https" do
|
21
21
|
result = IOStreams::Paths::HTTP.new(ssl_url).read
|
22
22
|
assert_includes result, "<html>"
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
25
|
+
it "does not support streams" do
|
26
26
|
assert_raises URI::InvalidURIError do
|
27
27
|
io = StringIO.new
|
28
28
|
IOStreams::Paths::HTTP.new(io)
|
data/test/paths/matcher_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "../test_helper"
|
2
2
|
|
3
3
|
module Paths
|
4
4
|
class MatcherTest < Minitest::Test
|
@@ -49,13 +49,13 @@ module Paths
|
|
49
49
|
case_sensitive: true
|
50
50
|
},
|
51
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}
|
52
|
+
{path: "/path/work", pattern: "*", expected_path: "/path/work", expected_pattern: "*", recursive: false}
|
53
53
|
]
|
54
54
|
end
|
55
55
|
# , case_sensitive: false, hidden: false
|
56
56
|
|
57
|
-
describe
|
58
|
-
it
|
57
|
+
describe "#recursive?" do
|
58
|
+
it "identifies recursive paths correctly" do
|
59
59
|
cases.each do |test_case|
|
60
60
|
path = IOStreams.path(test_case[:path])
|
61
61
|
matcher = IOStreams::Paths::Matcher.new(path, test_case[:pattern])
|
@@ -65,7 +65,7 @@ module Paths
|
|
65
65
|
end
|
66
66
|
|
67
67
|
describe "#path?" do
|
68
|
-
it
|
68
|
+
it "optimizes path correctly" do
|
69
69
|
cases.each do |test_case|
|
70
70
|
path = IOStreams.path(test_case[:path])
|
71
71
|
matcher = IOStreams::Paths::Matcher.new(path, test_case[:pattern])
|
@@ -75,7 +75,7 @@ module Paths
|
|
75
75
|
end
|
76
76
|
|
77
77
|
describe "#pattern" do
|
78
|
-
it
|
78
|
+
it "optimizes pattern correctly" do
|
79
79
|
cases.each do |test_case|
|
80
80
|
path = IOStreams.path(test_case[:path])
|
81
81
|
matcher = IOStreams::Paths::Matcher.new(path, test_case[:pattern])
|
@@ -89,7 +89,7 @@ module Paths
|
|
89
89
|
end
|
90
90
|
|
91
91
|
describe "#match?" do
|
92
|
-
it
|
92
|
+
it "matches" do
|
93
93
|
cases.each do |test_case|
|
94
94
|
path = IOStreams.path(test_case[:path])
|
95
95
|
case_sensitive = test_case.fetch(:case_sensitive, false)
|
@@ -102,20 +102,19 @@ module Paths
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
-
it
|
106
|
-
cases.
|
105
|
+
it "should not match" do
|
106
|
+
cases.each_with_index do |test_case, index|
|
107
107
|
path = IOStreams.path(test_case[:path])
|
108
|
-
case_sensitive = test_case.
|
108
|
+
case_sensitive = test_case.key?(:case_sensitive) ? test_case[:case_sensitive] : false
|
109
109
|
matcher = IOStreams::Paths::Matcher.new(path, test_case[:pattern], case_sensitive: case_sensitive)
|
110
110
|
next unless test_case[:not_matches]
|
111
111
|
|
112
112
|
test_case[:not_matches].each do |file_name|
|
113
|
-
refute matcher.match?(file_name), test_case
|
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
114
|
end
|
115
115
|
end
|
116
116
|
end
|
117
117
|
end
|
118
|
-
|
119
118
|
end
|
120
119
|
end
|
121
120
|
end
|
data/test/paths/s3_test.rb
CHANGED
@@ -1,16 +1,14 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "../test_helper"
|
2
2
|
|
3
3
|
module Paths
|
4
4
|
class S3Test < Minitest::Test
|
5
5
|
describe IOStreams::Paths::S3 do
|
6
6
|
before do
|
7
|
-
unless ENV[
|
8
|
-
skip "Supply 'S3_BUCKET_NAME' environment variable with S3 bucket name to test S3 paths"
|
9
|
-
end
|
7
|
+
skip "Supply 'S3_BUCKET_NAME' environment variable with S3 bucket name to test S3 paths" unless ENV["S3_BUCKET_NAME"]
|
10
8
|
end
|
11
9
|
|
12
10
|
let :file_name do
|
13
|
-
File.join(File.dirname(__FILE__),
|
11
|
+
File.join(File.dirname(__FILE__), "..", "files", "text file.txt")
|
14
12
|
end
|
15
13
|
|
16
14
|
let :raw do
|
@@ -20,98 +18,98 @@ module Paths
|
|
20
18
|
let(:root_path) { IOStreams::Paths::S3.new("s3://#{ENV['S3_BUCKET_NAME']}/iostreams_test") }
|
21
19
|
|
22
20
|
let :existing_path do
|
23
|
-
path = root_path.join(
|
21
|
+
path = root_path.join("test.txt")
|
24
22
|
path.write(raw) unless path.exist?
|
25
23
|
path
|
26
24
|
end
|
27
25
|
|
28
26
|
let :missing_path do
|
29
|
-
root_path.join(
|
27
|
+
root_path.join("unknown.txt")
|
30
28
|
end
|
31
29
|
|
32
30
|
let :write_path do
|
33
|
-
root_path.join(
|
31
|
+
root_path.join("writer_test.txt").delete
|
34
32
|
end
|
35
33
|
|
36
|
-
describe
|
37
|
-
it
|
34
|
+
describe "#delete" do
|
35
|
+
it "existing file" do
|
38
36
|
assert existing_path.delete.is_a?(IOStreams::Paths::S3)
|
39
37
|
end
|
40
38
|
|
41
|
-
it
|
39
|
+
it "missing file" do
|
42
40
|
assert missing_path.delete.is_a?(IOStreams::Paths::S3)
|
43
41
|
end
|
44
42
|
end
|
45
43
|
|
46
|
-
describe
|
47
|
-
it
|
44
|
+
describe "#exist?" do
|
45
|
+
it "existing file" do
|
48
46
|
assert existing_path.exist?
|
49
47
|
end
|
50
48
|
|
51
|
-
it
|
49
|
+
it "missing file" do
|
52
50
|
refute missing_path.exist?
|
53
51
|
end
|
54
52
|
end
|
55
53
|
|
56
|
-
describe
|
57
|
-
it
|
54
|
+
describe "#mkpath" do
|
55
|
+
it "returns self for non-existant path" do
|
58
56
|
assert existing_path.mkpath.is_a?(IOStreams::Paths::S3)
|
59
57
|
end
|
60
58
|
|
61
|
-
it
|
59
|
+
it "checks for lack of existence" do
|
62
60
|
assert missing_path.mkpath.is_a?(IOStreams::Paths::S3)
|
63
61
|
end
|
64
62
|
end
|
65
63
|
|
66
|
-
describe
|
67
|
-
it
|
64
|
+
describe "#mkdir" do
|
65
|
+
it "returns self for non-existant path" do
|
68
66
|
assert existing_path.mkdir.is_a?(IOStreams::Paths::S3)
|
69
67
|
end
|
70
68
|
|
71
|
-
it
|
69
|
+
it "checks for lack of existence" do
|
72
70
|
assert missing_path.mkdir.is_a?(IOStreams::Paths::S3)
|
73
71
|
end
|
74
72
|
end
|
75
73
|
|
76
|
-
describe
|
77
|
-
it
|
78
|
-
assert_equal raw, existing_path.reader
|
74
|
+
describe "#reader" do
|
75
|
+
it "reads" do
|
76
|
+
assert_equal raw, existing_path.reader(&:read)
|
79
77
|
end
|
80
78
|
end
|
81
79
|
|
82
|
-
describe
|
83
|
-
it
|
80
|
+
describe "#size" do
|
81
|
+
it "existing file" do
|
84
82
|
assert_equal raw.size, existing_path.size
|
85
83
|
end
|
86
84
|
|
87
|
-
it
|
85
|
+
it "missing file" do
|
88
86
|
assert_nil missing_path.size
|
89
87
|
end
|
90
88
|
end
|
91
89
|
|
92
|
-
describe
|
93
|
-
it
|
90
|
+
describe "#writer" do
|
91
|
+
it "writes" do
|
94
92
|
assert_equal raw.size, write_path.writer { |io| io.write(raw) }
|
95
93
|
assert write_path.exist?
|
96
94
|
assert_equal raw, write_path.read
|
97
95
|
end
|
98
96
|
end
|
99
97
|
|
100
|
-
describe
|
101
|
-
it
|
98
|
+
describe "#each_line" do
|
99
|
+
it "reads line by line" do
|
102
100
|
lines = []
|
103
|
-
existing_path.each(:line) {|line| lines << line}
|
101
|
+
existing_path.each(:line) { |line| lines << line }
|
104
102
|
assert_equal raw.lines.collect(&:chomp), lines
|
105
103
|
end
|
106
104
|
end
|
107
105
|
|
108
|
-
describe
|
106
|
+
describe "#each_child" do
|
109
107
|
# TODO: case_sensitive: false, directories: false, hidden: false
|
110
108
|
let(:abd_file_names) { %w[abd/test1.txt abd/test5.file abd/extra/file.csv] }
|
111
109
|
let(:files_for_test) { abd_file_names + %w[xyz/test2.csv xyz/another.csv] }
|
112
110
|
|
113
111
|
let :each_root do
|
114
|
-
root_path.join(
|
112
|
+
root_path.join("each_child_test")
|
115
113
|
end
|
116
114
|
|
117
115
|
let :multiple_paths do
|
@@ -122,37 +120,37 @@ module Paths
|
|
122
120
|
multiple_paths.each { |path| path.write(raw) unless path.exist? }
|
123
121
|
end
|
124
122
|
|
125
|
-
it
|
123
|
+
it "existing file returns just the file itself" do
|
126
124
|
# Glorified exists call
|
127
125
|
existing_path
|
128
126
|
assert_equal root_path.join("test.txt").to_s, root_path.children("test.txt").first.to_s
|
129
127
|
end
|
130
128
|
|
131
|
-
it
|
129
|
+
it "missing file does nothing" do
|
132
130
|
# Glorified exists call
|
133
131
|
assert_equal [], missing_path.children("readme").collect(&:to_s)
|
134
132
|
end
|
135
133
|
|
136
|
-
it
|
134
|
+
it "returns all the children" do
|
137
135
|
write_raw_data
|
138
136
|
assert_equal multiple_paths.collect(&:to_s).sort, each_root.children("**/*").collect(&:to_s).sort
|
139
137
|
end
|
140
138
|
|
141
|
-
it
|
139
|
+
it "returns all the children under a sub-dir" do
|
142
140
|
write_raw_data
|
143
141
|
expected = abd_file_names.collect { |file_name| each_root.join(file_name) }
|
144
142
|
assert_equal expected.collect(&:to_s).sort, each_root.children("abd/*").collect(&:to_s).sort
|
145
143
|
end
|
146
144
|
|
147
|
-
it
|
145
|
+
it "missing path" do
|
148
146
|
count = 0
|
149
147
|
missing_path.each_child { |_| count += 1 }
|
150
148
|
assert_equal 0, count
|
151
149
|
end
|
152
150
|
|
153
151
|
# Test is here since all the test artifacts have been created already in S3.
|
154
|
-
describe
|
155
|
-
it
|
152
|
+
describe "IOStreams.each_child" do
|
153
|
+
it "returns all the children" do
|
156
154
|
write_raw_data
|
157
155
|
children = []
|
158
156
|
IOStreams.each_child(each_root.join("**/*").to_s) { |child| children << child }
|
@@ -161,8 +159,8 @@ module Paths
|
|
161
159
|
end
|
162
160
|
end
|
163
161
|
|
164
|
-
describe
|
165
|
-
it
|
162
|
+
describe "#move_to" do
|
163
|
+
it "moves existing file" do
|
166
164
|
source = root_path.join("move_test_source.txt")
|
167
165
|
begin
|
168
166
|
source.write("Hello World")
|
@@ -179,7 +177,7 @@ module Paths
|
|
179
177
|
end
|
180
178
|
end
|
181
179
|
|
182
|
-
it
|
180
|
+
it "missing source file" do
|
183
181
|
source = root_path.join("move_test_source.txt")
|
184
182
|
refute source.exist?
|
185
183
|
begin
|
@@ -194,7 +192,7 @@ module Paths
|
|
194
192
|
end
|
195
193
|
end
|
196
194
|
|
197
|
-
it
|
195
|
+
it "missing target directories" do
|
198
196
|
source = root_path.join("move_test_source.txt")
|
199
197
|
begin
|
200
198
|
source.write("Hello World")
|
@@ -212,8 +210,8 @@ module Paths
|
|
212
210
|
end
|
213
211
|
end
|
214
212
|
|
215
|
-
describe
|
216
|
-
it
|
213
|
+
describe "#partial_files_visible?" do
|
214
|
+
it "visible only after upload" do
|
217
215
|
refute root_path.partial_files_visible?
|
218
216
|
end
|
219
217
|
end
|