Skip to content

Commit

Permalink
Merge pull request #34 from tumugi/add-json-export-test
Browse files Browse the repository at this point in the history
Add JSON export test
  • Loading branch information
hakobera committed Jun 20, 2016
2 parents 0bd3b66 + 0239710 commit 7afc89a
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion test/plugin/task/bigquery_export_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Tumugi::Plugin::BigqueryExportTaskTest < Test::Unit::TestCase
assert_equal('tumugi-plugin-bigquery', task.job_project_id)
assert_equal('samples', task.dataset_id)
assert_equal('shakespeare', task.table_id)
assert_equal('CSV', task.destination_format)
assert_equal('GZIP', task.compression)
assert_equal(120, task.wait)
assert_equal(10000, task.page_size)
Expand Down Expand Up @@ -71,7 +72,7 @@ def output
end
end

test "export to local file" do
test "export CSV to local file" do
task = @klass.new
task.instance_eval do
def output
Expand Down Expand Up @@ -99,6 +100,31 @@ def output
end
end

test "export JSON to local file" do
@klass.param_set :destination_format, 'NEWLINE_DELIMITED_JSON'
task = @klass.new
task.instance_eval do
def output
Tumugi::Plugin::LocalFileTarget.new('tmp/export.json')
end
end
output = task.output
task.run
output.open("r") do |f|
count = 0
in_row = ''
while s = f.gets
json = JSON.parse(s)
count += 1
if json["word"] == "in"
in_row = s
end
end
assert_equal(164656, count)
assert_equal("#{JSON.generate({"word" => "in", "word_count" => "255", "corpus" => "kinghenryviii", "corpus_date" => "1612"})}\n", in_row)
end
end

test "raise error if output is not FileSystemTarget" do
task = @klass.new
task.instance_eval do
Expand Down

0 comments on commit 7afc89a

Please sign in to comment.