Method: Conify::ManifestTest#call

Defined in:
lib/conify/test/manifest_test.rb

#callObject



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

def call
  test 'id key exists' do
    data.has_key?('id')
  end

  test 'id is a string' do
    data['id'].is_a?(String)
  end

  test 'id is not blank' do
    !data['id'].empty?
  end

  test 'api key exists' do
    data.has_key?('api')
  end

  test 'api is a hash' do
    data['api'].is_a?(Hash)
  end

  test 'api contains password' do
    data['api'].has_key?('password') && data['api']['password'] != ''
  end

  test 'api contains sso_salt' do
    data['api'].has_key?('sso_salt') && data['api']['sso_salt'] != ''
  end

  test 'api contains test url' do
    data['api'].has_key?('test')
  end

  test 'api contains production url' do
    data['api'].has_key?('production')
  end

  if data['api']['production'].is_a?(Hash)
    test 'production url uses SSL' do
      data['api']['production']['base_url'] =~ /^https:/
    end

    test 'sso url uses SSL' do
      data['api']['production']['sso_url'] =~ /^https:/
    end
  else
    test 'production url uses SSL' do
      data['api']['production'] =~ /^https:/
    end
  end

  if data['api'].has_key?('config_vars')
    test 'contains config_vars array' do
      data['api']['config_vars'].is_a?(Array)
    end

    test 'all config vars are uppercase strings' do
      data['api']['config_vars'].each do |k, v|
        if k =~ /^[A-Z][0-9A-Z_]+$/
          true
        else
          error "#{k.inspect} is not a valid ENV key"
        end
      end
    end

    test 'all config vars are prefixed with the addon id' do
      data['api']['config_vars'].each do |k|
        prefix = data['id'].upcase.gsub('-', '_')

        if k =~ /^#{prefix}_/
          true
        else
          error "#{k} is not a valid ENV key - must be prefixed with #{prefix}_"
        end
      end
    end
  end

end