diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /spec/migrations/20200929052138_create_initial_versions_for_pre_versioning_terraform_states_spec.rb | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'spec/migrations/20200929052138_create_initial_versions_for_pre_versioning_terraform_states_spec.rb')
-rw-r--r-- | spec/migrations/20200929052138_create_initial_versions_for_pre_versioning_terraform_states_spec.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/migrations/20200929052138_create_initial_versions_for_pre_versioning_terraform_states_spec.rb b/spec/migrations/20200929052138_create_initial_versions_for_pre_versioning_terraform_states_spec.rb new file mode 100644 index 00000000000..1a618712b32 --- /dev/null +++ b/spec/migrations/20200929052138_create_initial_versions_for_pre_versioning_terraform_states_spec.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20200929052138_create_initial_versions_for_pre_versioning_terraform_states.rb') + +RSpec.describe CreateInitialVersionsForPreVersioningTerraformStates do + let(:namespace) { table(:namespaces).create!(name: 'terraform', path: 'terraform') } + let(:project) { table(:projects).create!(id: 1, namespace_id: namespace.id) } + let(:terraform_state_versions) { table(:terraform_state_versions) } + + def create_state!(project, versioning_enabled:) + table(:terraform_states).create!( + project_id: project.id, + uuid: 'uuid', + file_store: 2, + file: 'state.tfstate', + versioning_enabled: versioning_enabled + ) + end + + describe '#up' do + context 'for a state that is already versioned' do + let!(:terraform_state) { create_state!(project, versioning_enabled: true) } + + it 'does not insert a version record' do + expect { migrate! }.not_to change { terraform_state_versions.count } + end + end + + context 'for a state that is not yet versioned' do + let!(:terraform_state) { create_state!(project, versioning_enabled: false) } + + it 'creates a version using the current state data' do + expect { migrate! }.to change { terraform_state_versions.count }.by(1) + + migrated_version = terraform_state_versions.last + expect(migrated_version.terraform_state_id).to eq(terraform_state.id) + expect(migrated_version.version).to be_zero + expect(migrated_version.file_store).to eq(terraform_state.file_store) + expect(migrated_version.file).to eq(terraform_state.file) + expect(migrated_version.created_at).to be_present + expect(migrated_version.updated_at).to be_present + end + end + end +end |