Skip to content

Commit 9c6c53e

Browse files
committed
Use fog_spec_helper for blobstore specs needing clean state
Move Fog mock reset from global spec_helper to opt-in fog_spec_helper. This prevents fog reset from running for all specs, which caused conflicts with migration specs that stub Config.get differently. The fog_spec_helper now: - Uses metadata-based hook (:fog_isolation) that only runs for tagged specs - Resets Fog mocks and recreates buckets before each tagged test - Avoids interfering with specs that mock Config differently 24 blobstore-related specs are tagged with :fog_isolation metadata.
1 parent 35ae07f commit 9c6c53e

25 files changed

Lines changed: 69 additions & 48 deletions

spec/fog_spec_helper.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Use this helper for specs that need Fog/blobstore functionality with
2+
# a clean state between tests (upload, download, delete operations).
3+
#
4+
# This helper resets Fog mocks and recreates buckets before each test.
5+
#
6+
# For specs that don't need blobstore isolation, use spec_helper instead.
7+
8+
require 'spec_helper'
9+
10+
RSpec.configure do |config|
11+
config.before(:each, :fog_isolation) do
12+
Fog::Mock.reset
13+
14+
if Fog.mock?
15+
CloudController::DependencyLocator.instance.droplet_blobstore.ensure_bucket_exists
16+
CloudController::DependencyLocator.instance.package_blobstore.ensure_bucket_exists
17+
CloudController::DependencyLocator.instance.global_app_bits_cache.ensure_bucket_exists
18+
CloudController::DependencyLocator.instance.buildpack_blobstore.ensure_bucket_exists
19+
end
20+
end
21+
end

spec/unit/controllers/runtime/buildpack_bits_controller_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
require 'spec_helper'
1+
require 'fog_spec_helper'
22

33
## NOTICE: Prefer request specs over controller specs as per ADR #0003 ##
44

55
module VCAP::CloudController
6-
RSpec.describe VCAP::CloudController::BuildpackBitsController do
6+
RSpec.describe VCAP::CloudController::BuildpackBitsController, :fog_isolation do
77
let(:user) { make_user }
88
let(:filename) { 'file.zip' }
99
let(:sha_valid_zip) { Digester.new(algorithm: OpenSSL::Digest::SHA256).digest_file(valid_zip) }

spec/unit/controllers/runtime/buildpacks_controller_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
require 'spec_helper'
1+
require 'fog_spec_helper'
22

33
## NOTICE: Prefer request specs over controller specs as per ADR #0003 ##
44

55
module VCAP::CloudController
6-
RSpec.describe VCAP::CloudController::BuildpacksController do
6+
RSpec.describe VCAP::CloudController::BuildpacksController, :fog_isolation do
77
def ordered_buildpacks
88
Buildpack.order(:position).map { |bp| [bp.name, bp.position] }
99
end

spec/unit/controllers/runtime/stagings_controller_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'spec_helper'
1+
require 'fog_spec_helper'
22

33
## NOTICE: Prefer request specs over controller specs as per ADR #0003 ##
44

@@ -164,7 +164,7 @@ module VCAP::CloudController
164164
end
165165
end
166166

167-
RSpec.describe StagingsController do
167+
RSpec.describe StagingsController, :fog_isolation do
168168
let(:timeout_in_seconds) { 120 }
169169
let(:cc_addr) { '1.2.3.4' }
170170
let(:cc_port) { 5678 }

spec/unit/jobs/runtime/blobstore_delete_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
require 'spec_helper'
1+
require 'fog_spec_helper'
22

33
module VCAP::CloudController
44
module Jobs::Runtime
5-
RSpec.describe BlobstoreDelete, job_context: :worker do
5+
RSpec.describe BlobstoreDelete, :fog_isolation, job_context: :worker do
66
let(:key) { 'key' }
77
subject(:job) do
88
BlobstoreDelete.new(key, :droplet_blobstore)

spec/unit/jobs/runtime/blobstore_upload_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
require 'spec_helper'
1+
require 'fog_spec_helper'
22

33
module VCAP::CloudController
44
module Jobs::Runtime
5-
RSpec.describe BlobstoreUpload, job_context: :worker do
5+
RSpec.describe BlobstoreUpload, :fog_isolation, job_context: :worker do
66
let(:local_file) { Tempfile.new('tmpfile') }
77
let(:blobstore_key) { 'key' }
88
let(:blobstore_name) { :droplet_blobstore }

spec/unit/jobs/runtime/buildpack_cache_cleanup_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
require 'spec_helper'
1+
require 'fog_spec_helper'
22

33
module VCAP::CloudController
44
module Jobs::Runtime
5-
RSpec.describe BuildpackCacheCleanup, job_context: :worker do
5+
RSpec.describe BuildpackCacheCleanup, :fog_isolation, job_context: :worker do
66
let(:cc_addr) { '1.2.3.4' }
77
let(:cc_port) { 5678 }
88
let(:orphan_key) { 'orphan-key' }

spec/unit/jobs/v3/buildpack_cache_cleanup_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
require 'spec_helper'
1+
require 'fog_spec_helper'
22

33
module VCAP::CloudController
44
module Jobs::V3
5-
RSpec.describe BuildpackCacheCleanup, job_context: :worker do
5+
RSpec.describe BuildpackCacheCleanup, :fog_isolation, job_context: :worker do
66
let(:cc_addr) { '1.2.3.4' }
77
let(:cc_port) { 5678 }
88
let(:orphan_key) { 'orphan-key' }

spec/unit/jobs/v3/buildpack_cache_delete_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
require 'spec_helper'
1+
require 'fog_spec_helper'
22
require 'jobs/v3/buildpack_cache_delete'
33

44
module VCAP::CloudController
55
module Jobs::V3
6-
RSpec.describe BuildpackCacheDelete, job_context: :worker do
6+
RSpec.describe BuildpackCacheDelete, :fog_isolation, job_context: :worker do
77
let(:app_guid) { 'some-guid' }
88
let(:local_dir) { Dir.mktmpdir }
99
let!(:blobstore) do

spec/unit/jobs/v3/buildpack_cache_upload_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
require 'spec_helper'
1+
require 'fog_spec_helper'
22

33
module VCAP::CloudController
44
module Jobs::V3
5-
RSpec.describe BuildpackCacheUpload, job_context: :api do
5+
RSpec.describe BuildpackCacheUpload, :fog_isolation, job_context: :api do
66
subject(:job) { BuildpackCacheUpload.new(local_path: local_file.path, app_guid: app.guid, stack_name: 'some-stack') }
77

88
let(:app) { AppModel.make(:buildpack) }

0 commit comments

Comments
 (0)