Sha256: 9b0e5fbc505050f643f2e9fe7615dfa880a66715472f6d8a652943e0c021b1e1

Contents?: true

Size: 1.4 KB

Versions: 42

Compression:

Stored size: 1.4 KB

Contents

# Shortcut for Fog::Compute[:digitalocean]
def service
  Fog::Compute[:digitalocean]
end

def fog_test_server_attributes
  # Hard coding numbers because requests from tests are sometimes failing.
  # TODO: Mock properly instead
  image = service.images.find { |i| i.name == 'Ubuntu 13.10 x64' }
  image_id = image.nil? ? 1505447 : image.id
  region = service.regions.find { |r| r.name == 'New York 1' }
  region_id = region.nil? ? 4 : region.id
  flavor = service.flavors.find { |r| r.name == '512MB' }
  flavor_id = flavor.nil? ? 66 : flavor.id

  {
    :image_id  => image_id,
    :region_id => region_id,
    :flavor_id => flavor_id
  }
end

def fog_server_name
  "fog-server-test"
end

# Create a long lived server for the tests
def fog_test_server
  server = service.servers.find { |s| s.name == fog_server_name }
  unless server
    server = service.servers.create({
      :name => fog_server_name
    }.merge(fog_test_server_attributes))
    server.wait_for { ready? }
  end
  server
end

# Destroy the long lived server
def fog_test_server_destroy
  server = service.servers.find { |s| s.name == fog_server_name }
  server.destroy if server
end

at_exit do
  unless Fog.mocking? || Fog.credentials[:digitalocean_api_key].nil?
    server = service.servers.find { |s| s.name == fog_server_name }
    if server
      server.wait_for(120) do
        reload rescue nil; ready?
      end
    end
    fog_test_server_destroy
  end
end

Version data entries

42 entries across 40 versions & 7 rubygems

Version Path
fog-digitalocean-0.4.0 tests/digitalocean/helper.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/fog-digitalocean-0.3.0/tests/digitalocean/helper.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/fog-digitalocean-0.3.0/tests/digitalocean/helper.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/fog-digitalocean-0.3.0/tests/digitalocean/helper.rb
fog-digitalocean-0.3.0 tests/digitalocean/helper.rb
fog-digitalocean-0.2.0 tests/digitalocean/helper.rb
fog-digitalocean-0.1.0 tests/digitalocean/helper.rb
fog-1.38.0 tests/digitalocean/helper.rb
fog-1.37.0 tests/digitalocean/helper.rb
fog-1.36.0 tests/digitalocean/helper.rb
fog-1.35.0 tests/digitalocean/helper.rb
fog-2.0.0.pre.0 tests/digitalocean/helper.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/fog-1.32.0/tests/digitalocean/helper.rb
fog-1.34.0 tests/digitalocean/helper.rb
fog-1.33.0 tests/digitalocean/helper.rb
fog-1.32.0 tests/digitalocean/helper.rb
fog-1.31.0 tests/digitalocean/helper.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/fog-1.22.1/tests/digitalocean/helper.rb
fog-1.30.0 tests/digitalocean/helper.rb
fog-1.29.0 tests/digitalocean/helper.rb