Sha256: aeeaecf359cbf0e64e47c36dfea31d9bed5b4bba33671a2dcc7e69370c28292d

Contents?: true

Size: 1.56 KB

Versions: 23

Compression:

Stored size: 1.56 KB

Contents

class TestYaoResource < Test::Unit::TestCase
  include AuthStub

  def setup
    initialize_test_client!
  end

  def teardown
    reset_test_client!
  end

  private

  # Yao::Resources::* のテストで Yao.default.pool の設定を都度都度 記述しなくていいよういするヘルパー
  # endpoint の URL がマチマチだとテストを記述するのが面倒なので example.com で統一している
  def initialize_test_client!
    auth_url = "http://example.com:12345"
    username = "yao"
    tenant   = "default"
    password = "password"

    stub_auth_request(auth_url, username, password, tenant)

    Yao.config.set :auth_url, auth_url
    Yao::Auth.new(tenant_name: tenant, username: username, password: password)

    client = Yao::Client.gen_client("https://example.com:12345")
    Yao.default_client.admin_pool["identity"] = client
    Yao.default_client.pool["network"]        = client
    Yao.default_client.pool["compute"]        = client
    Yao.default_client.pool["metering"]       = client
    Yao.default_client.pool["volumev3"]       = client
  end

  # 他のテストで副作用を出さないように Yao::Client.default_client, Yao::Conig を nil でリセットしておきます
  def reset_test_client!
    Yao::Client.default_client = nil

    Yao::Config::HOOK_RENEW_CLIENT_KEYS.each do |key|
      Yao.configure do
        set key, nil
      end
    end

    # https://github.com/bblimke/webmock/wiki/Clear-stubs-and-request-history
    # 他のテストに作用しないように stub_request を reset する
    WebMock.reset!
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
yao-0.21.0 test/support/test_yao_resource.rb
yao-0.20.0 test/support/test_yao_resource.rb
yao-0.19.0 test/support/test_yao_resource.rb
yao-0.18.0 test/support/test_yao_resource.rb
yao-0.17.0 test/support/test_yao_resource.rb
yao-0.16.0 test/support/test_yao_resource.rb
yao-0.15.0 test/support/test_yao_resource.rb
yao-0.14.0 test/support/test_yao_resource.rb
yao-0.13.4 test/support/test_yao_resource.rb
yao-0.13.3 test/support/test_yao_resource.rb
yao-0.13.2 test/support/test_yao_resource.rb
yao-0.13.1 test/support/test_yao_resource.rb
yao-0.13.0 test/support/test_yao_resource.rb
yao-0.12.0 test/support/test_yao_resource.rb
yao-0.11.3 test/support/test_yao_resource.rb
yao-0.11.2 test/support/test_yao_resource.rb
yao-0.11.1 test/support/test_yao_resource.rb
yao-0.11.0 test/support/test_yao_resource.rb
yao-0.10.1 test/support/test_yao_resource.rb
yao-0.10.0 test/support/test_yao_resource.rb