Welcome to mirror list, hosted at ThFree Co, Russian Federation.

import_export_equivalence_spec.rb « import_export « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 18f2e8f80d7b81f26a967c0b36faf2a309a7458b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# frozen_string_literal: true

require 'spec_helper'

# Verifies that given an exported project meta-data tree, when importing this
# tree and then exporting it again, we should obtain the initial tree.
#
# This equivalence only works up to a certain extent, for instance we need
# to ignore:
#
# - row IDs and foreign key IDs
# - some timestamps
# - randomly generated fields like tokens
#
# as these are expected to change between import/export cycles.
RSpec.describe Gitlab::ImportExport do
  include ImportExport::CommonUtil
  include ConfigurationHelper
  include ImportExport::ProjectTreeExpectations

  let(:json_fixture) { 'complex' }

  before do
    stub_feature_flags(project_export_as_ndjson: false)
  end

  it 'yields the initial tree when importing and exporting it again' do
    project = create(:project, creator: create(:user, :admin))

    # We first generate a test fixture dynamically from a seed-fixture, so as to
    # account for any fields in the initial fixture that are missing and set to
    # defaults during import (ideally we should have realistic test fixtures
    # that "honestly" represent exports)
    expect(
      restore_then_save_project(
        project,
        import_path: seed_fixture_path,
        export_path: test_fixture_path)
    ).to be true
    # Import, then export again from the generated fixture. Any residual changes
    # in the JSON will count towards comparison i.e. test failures.
    expect(
      restore_then_save_project(
        project,
        import_path: test_fixture_path,
        export_path: test_tmp_path)
    ).to be true

    imported_json = Gitlab::Json.parse(File.read("#{test_fixture_path}/project.json"))
    exported_json = Gitlab::Json.parse(File.read("#{test_tmp_path}/project.json"))

    assert_relations_match(imported_json, exported_json)
  end

  private

  def seed_fixture_path
    "#{fixtures_path}/#{json_fixture}"
  end

  def test_fixture_path
    "#{test_tmp_path}/#{json_fixture}"
  end
end