Class: Conify::ProvisionResponseTest

Inherits:
Test
  • Object
show all
Defined in:
lib/conify/test/provision_response_test.rb

Instance Attribute Summary

Attributes inherited from Test

#data

Instance Method Summary collapse

Methods inherited from Test

#api_requires?, #env, #initialize, #run, #test, #url

Methods included from Helpers

#allow_user_response, #ask_for_conflux_creds, #ask_for_password, #ask_for_password_on_windows, #camelize, #display, #echo_off, #echo_on, #error, #exclusive_deep_merge, #format_with_bang, #host, #host_url, #kensa_manifest_name, #kensa_manifest_path, #manifest_content, #manifest_filename, #manifest_path, #manually_added_methods, #open_url, #running_on_a_mac?, #running_on_windows?, #site_url, #to_table, #with_tty

Constructor Details

This class inherits a constructor from Conify::Test

Instance Method Details

#callObject



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
87
# File 'lib/conify/test/provision_response_test.rb', line 6

def call
  response = data[:provision_response]

  test 'contains an id' do
    response.is_a?(Hash) && response['id']
  end

  test 'id does not contain conflux_id' do
    if response['id'].to_s.include? data[:external_username].scan(/app(\d+)@/).flatten.first
      error 'id cannot include conflux_id'
    else
      true
    end
  end

  if response.has_key?('config')
    test 'is a hash' do
      response['config'].is_a?(Hash)
    end

    test 'all config keys were previously defined in the manifest' do
      response['config'].keys.each do |key|
        error "#{key} is not in the manifest" unless data['api']['config_vars'].include?(key)
      end
      true
    end

    test 'all keys in the manifest are present' do
      difference = data['api']['config_vars'] - response['config'].keys
      unless difference.empty?
        verb = (difference.size == 1) ? 'is' : 'are'
        error "Config(s) #{difference.join(', ')} #{verb} missing from the provision response"
      end
      true
    end

    test 'all config values are strings' do
      response['config'].each do |k, v|
        if v.is_a?(String)
          true
        else
          error "the key #{k} doesn't contain a string (#{v.inspect})"
        end
      end
    end

    test 'URL configs vars' do
      response['config'].each do |key, value|
        next unless key =~ /_URL$/
        begin
          uri = URI.parse(value)
          error "#{value} is not a valid URI - missing host" unless uri.host
          error "#{value} is not a valid URI - missing scheme" unless uri.scheme
          error "#{value} is not a valid URI - pointing to localhost" if env == 'production' && uri.host == 'localhost'
        rescue URI::Error
          error "#{value} is not a valid URI"
        end
      end
    end

    test 'log_drain_url is returned if required' do
      if !api_requires?('syslog_drain')
        true
      else
        drain_url = response['log_drain_url']

        if !drain_url || drain_url.empty?
          error 'must return a log_drain_url'
        else
          true
        end

        unless drain_url =~ /\A(https|syslog):\/\/[\S]+\Z/
          error 'must return a syslog_drain_url like syslog://log.example.com:9999'
        else
          true
        end
      end
    end

  end
end