summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/import_export/json/ndjson_writer_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-06 12:10:44 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-06 12:10:44 +0000
commitba174c982f40d71a87fd511b091753807174f7e7 (patch)
treeb89d55c715288f2c2f76724c1b7ff4a6ebf90154 /spec/lib/gitlab/import_export/json/ndjson_writer_spec.rb
parenteaea945e0355826c58c3dcf887496ea91064f85c (diff)
downloadgitlab-ce-ba174c982f40d71a87fd511b091753807174f7e7.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/import_export/json/ndjson_writer_spec.rb')
-rw-r--r--spec/lib/gitlab/import_export/json/ndjson_writer_spec.rb63
1 files changed, 63 insertions, 0 deletions
diff --git a/spec/lib/gitlab/import_export/json/ndjson_writer_spec.rb b/spec/lib/gitlab/import_export/json/ndjson_writer_spec.rb
new file mode 100644
index 00000000000..bae3672474c
--- /dev/null
+++ b/spec/lib/gitlab/import_export/json/ndjson_writer_spec.rb
@@ -0,0 +1,63 @@
+# frozen_string_literal: true
+
+require "spec_helper"
+
+describe Gitlab::ImportExport::JSON::NdjsonWriter do
+ include ImportExport::CommonUtil
+
+ let(:path) { "#{Dir.tmpdir}/ndjson_writer_spec/tree" }
+ let(:exportable_path) { 'projects' }
+
+ subject { described_class.new(path) }
+
+ after do
+ FileUtils.rm_rf(path)
+ end
+
+ describe "#write_attributes" do
+ it "writes correct json to root" do
+ expected_hash = { "key" => "value_1", "key_1" => "value_2" }
+ subject.write_attributes(exportable_path, expected_hash)
+
+ expect(consume_attributes(path, exportable_path)).to eq(expected_hash)
+ end
+ end
+
+ describe "#write_relation" do
+ context "when single relation is serialized" do
+ it "appends json in correct file " do
+ relation = "relation"
+ value = { "key" => "value_1", "key_1" => "value_1" }
+ subject.write_relation(exportable_path, relation, value)
+
+ expect(consume_relations(path, exportable_path, relation)).to eq([value])
+ end
+ end
+
+ context "when single relation is already serialized" do
+ it "raise exception" do
+ values = [{ "key" => "value_1", "key_1" => "value_1" }, { "key" => "value_2", "key_1" => "value_2" }]
+ relation = "relation"
+ file_path = File.join(path, exportable_path, "#{relation}.ndjson")
+ subject.write_relation(exportable_path, relation, values[0])
+
+ expect {subject.write_relation(exportable_path, relation, values[1])}.to raise_exception("The #{file_path} already exist")
+ end
+ end
+ end
+
+ describe "#write_relation_array" do
+ it "writes json in correct files" do
+ values = [{ "key" => "value_1", "key_1" => "value_1" }, { "key" => "value_2", "key_1" => "value_2" }]
+ relations = %w(relation1 relation2)
+ relations.each do |relation|
+ subject.write_relation_array(exportable_path, relation, values.to_enum)
+ end
+ subject.close
+
+ relations.each do |relation|
+ expect(consume_relations(path, exportable_path, relation)).to eq(values)
+ end
+ end
+ end
+end