diff options
Diffstat (limited to 'spec/uploaders/terraform/state_uploader_spec.rb')
-rw-r--r-- | spec/uploaders/terraform/state_uploader_spec.rb | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/spec/uploaders/terraform/state_uploader_spec.rb b/spec/uploaders/terraform/state_uploader_spec.rb index dadfdf6e93f..bd8e7fbc016 100644 --- a/spec/uploaders/terraform/state_uploader_spec.rb +++ b/spec/uploaders/terraform/state_uploader_spec.rb @@ -3,23 +3,45 @@ require 'spec_helper' RSpec.describe Terraform::StateUploader do - subject { terraform_state.file } + subject { state_version.file } - let(:terraform_state) { create(:terraform_state, :with_file) } + let(:state_version) { create(:terraform_state_version) } before do stub_terraform_state_object_storage end describe '#filename' do - it 'contains the UUID of the terraform state record' do - expect(subject.filename).to include(terraform_state.uuid) + it 'contains the version of the terraform state record' do + expect(subject.filename).to eq("#{state_version.version}.tfstate") + end + + context 'legacy state with versioning disabled' do + let(:state) { create(:terraform_state, versioning_enabled: false) } + let(:state_version) { create(:terraform_state_version, terraform_state: state) } + + it 'contains the UUID of the terraform state record' do + expect(subject.filename).to eq("#{state_version.uuid}.tfstate") + end end end describe '#store_dir' do - it 'contains the ID of the project' do - expect(subject.store_dir).to include(terraform_state.project_id.to_s) + it 'hashes the project ID and UUID' do + expect(Gitlab::HashedPath).to receive(:new) + .with(state_version.uuid, root_hash: state_version.project_id) + .and_return(:store_dir) + + expect(subject.store_dir).to eq(:store_dir) + end + + context 'legacy state with versioning disabled' do + let(:state) { create(:terraform_state, versioning_enabled: false) } + let(:state_version) { create(:terraform_state_version, terraform_state: state) } + + it 'contains the ID of the project' do + expect(subject.store_dir).to include(state_version.project_id.to_s) + end end end @@ -27,7 +49,7 @@ RSpec.describe Terraform::StateUploader do it 'creates a digest with a secret key and the project id' do expect(OpenSSL::HMAC) .to receive(:digest) - .with('SHA256', Gitlab::Application.secrets.db_key_base, terraform_state.project_id.to_s) + .with('SHA256', Gitlab::Application.secrets.db_key_base, state_version.project_id.to_s) .and_return('digest') expect(subject.key).to eq('digest') |