File: test_shared.rb

package info (click to toggle)
ruby-fog-google 1.29.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,628 kB
  • sloc: ruby: 17,788; makefile: 4
file content (86 lines) | stat: -rw-r--r-- 2,476 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
require "helpers/test_helper"

class TestShared < Minitest::Test
  # Test class that includes Fog::Google::Shared
  class TestClient
    include Fog::Google::Shared
  end

  # Simple stub service class
  class ServiceStub
    attr_reader :universe_domain_called_with
    attr_accessor :client_options

    def initialize
      @universe_domain_called_with = []
      @client_options = Struct.new(:members, :test_option).new([:test_option], nil)
    end

    def universe_domain=(value)
      @universe_domain_called_with << value
    end
  end

  def setup
    @client = TestClient.new
    @service = ServiceStub.new
  end

  def test_apply_client_options_sets_universe_domain
    options = { universe_domain: "custom.universe.com" }
    
    @client.apply_client_options(@service, options)
    
    assert_equal ["custom.universe.com"], @service.universe_domain_called_with
  end

  def test_apply_client_options_does_not_set_universe_domain_when_nil
    options = {}
    
    @client.apply_client_options(@service, options)
    
    assert_empty @service.universe_domain_called_with
  end

  def test_apply_client_options_uses_env_variable
    ENV["GOOGLE_CLOUD_UNIVERSE_DOMAIN"] = "env.universe.com"
    options = {}
    
    @client.apply_client_options(@service, options)
    
    assert_equal ["env.universe.com"], @service.universe_domain_called_with
  ensure
    ENV.delete("GOOGLE_CLOUD_UNIVERSE_DOMAIN")
  end

  def test_apply_client_options_prefers_option_over_env
    ENV["GOOGLE_CLOUD_UNIVERSE_DOMAIN"] = "env.universe.com"
    options = { universe_domain: "option.universe.com" }
    
    @client.apply_client_options(@service, options)
    
    assert_equal ["option.universe.com"], @service.universe_domain_called_with
  ensure
    ENV.delete("GOOGLE_CLOUD_UNIVERSE_DOMAIN")
  end

  def test_apply_client_options_sets_google_client_options
    options = {
      universe_domain: "custom.universe.com",
      google_client_options: { test_option: "test_value" }
    }
    
    @client.apply_client_options(@service, options)
    
    assert_equal ["custom.universe.com"], @service.universe_domain_called_with
    assert_equal "test_value", @service.client_options.test_option
  end

  def test_apply_client_options_works_without_google_client_options
    options = { universe_domain: "custom.universe.com" }
    
    @client.apply_client_options(@service, options)
    
    assert_equal ["custom.universe.com"], @service.universe_domain_called_with
  end
end