Sha256: 91f08b09b23ff5cabf7a6628b8176f636427bbb375805c117639b9b1436f6983

Contents?: true

Size: 991 Bytes

Versions: 10

Compression:

Stored size: 991 Bytes

Contents

class CollectionFactory
  PREFIX = "fog-test".freeze

  def initialize(subject, example)
    @subject = subject
    @example = example
    @resource_counter = 0
  end

  def cleanup(async = true)
    resources = @subject.all.select { |resource| resource.name.start_with? PREFIX }
    resources.each { |r| r.destroy(async) }
    resources.each { |r| Fog.wait_for { !@subject.all.map(&:identity).include? r.identity } }
  end

  def create
    @subject.create(params)
  end

  def get(identity)
    @subject.get(identity)
  end

  def resource_name(base = @example, prefix = PREFIX)
    index = @resource_counter += 1
    # In prefix, convert - to _ to make sure that it doesn't get stripped by the \W strip below.
    # Then, concatenate prefix, index, and base; strip all non-alphanumerics except _;
    # convert _ to -; downcase; truncate to 62 characters; delete trailing -
    [prefix.tr("-", "_"), index, base].join("_").gsub(/\W/, "").tr("_", "-").downcase[0..61].chomp("-")
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
fog-google-1.3.3 test/integration/factories/collection_factory.rb
fog-google-1.3.2 test/integration/factories/collection_factory.rb
fog-google-1.3.1 test/integration/factories/collection_factory.rb
fog-google-1.3.0 test/integration/factories/collection_factory.rb
fog-google-1.2.2 test/integration/factories/collection_factory.rb
fog-google-1.2.1 test/integration/factories/collection_factory.rb
fog-google-1.2.0 test/integration/factories/collection_factory.rb
fog-google-1.1.0 test/integration/factories/collection_factory.rb
fog-google-1.0.1 test/integration/factories/collection_factory.rb
fog-google-1.0.0 test/integration/factories/collection_factory.rb