|  | 
|  | 1 | +# frozen_string_literal: true | 
|  | 2 | + | 
| 1 | 3 | # spec/templates/storage_cli_config_jsons_spec.rb | 
| 2 | 4 | require 'rspec' | 
| 3 |  | -require 'json' | 
|  | 5 | +require 'oj' | 
| 4 | 6 | require 'bosh/template/test' | 
| 5 | 7 | 
 | 
| 6 |  | -module Bosh::Template::Test | 
| 7 |  | -  RSpec.describe 'storage-cli JSON templates' do | 
| 8 |  | -    let(:release_path) { File.join(File.dirname(__FILE__), '../..') } | 
| 9 |  | -    let(:release) { ReleaseDir.new(release_path) } | 
| 10 |  | -    let(:job) { release.job('cloud_controller_ng') } | 
| 11 |  | -    let(:links) { {} } | 
| 12 |  | -    let(:props) do | 
| 13 |  | -      { | 
| 14 |  | -        'cc' => { | 
| 15 |  | -          'droplets'     => { 'connection_config' => {} }, | 
| 16 |  | -          'buildpacks'   => { 'connection_config' => {} }, | 
| 17 |  | -          'packages'     => { 'connection_config' => {} }, | 
| 18 |  | -          'resource_pool'=> { 'connection_config' => {} }, | 
| 19 |  | -        } | 
| 20 |  | -      } | 
| 21 |  | -    end | 
|  | 8 | +TEMPLATES = { | 
|  | 9 | +  droplets: ['config/storage_cli_config_droplets.json', %w[cc droplets connection_config]], | 
|  | 10 | +  buildpacks: ['config/storage_cli_config_buildpacks.json', %w[cc buildpacks connection_config]], | 
|  | 11 | +  packages: ['config/storage_cli_config_packages.json', %w[cc packages connection_config]], | 
|  | 12 | +  resource_pool: ['config/storage_cli_config_resource_pool.json', %w[cc resource_pool connection_config]] | 
|  | 13 | +}.freeze | 
| 22 | 14 | 
 | 
| 23 |  | -    TEMPLATES = { | 
| 24 |  | -      droplets:      ['config/storage_cli_config_droplets.json',      %w[cc droplets connection_config]], | 
| 25 |  | -      buildpacks:    ['config/storage_cli_config_buildpacks.json',    %w[cc buildpacks connection_config]], | 
| 26 |  | -      packages:      ['config/storage_cli_config_packages.json',      %w[cc packages connection_config]], | 
| 27 |  | -      resource_pool: ['config/storage_cli_config_resource_pool.json', %w[cc resource_pool connection_config]], | 
| 28 |  | -    }.freeze | 
|  | 15 | +module Bosh | 
|  | 16 | +  module Template | 
|  | 17 | +    module Test | 
|  | 18 | +      RSpec.describe 'storage-cli JSON templates' do | 
|  | 19 | +        let(:release_path) { File.join(File.dirname(__FILE__), '../..') } | 
|  | 20 | +        let(:release) { ReleaseDir.new(release_path) } | 
|  | 21 | +        let(:job) { release.job('cloud_controller_ng') } | 
|  | 22 | +        let(:links) { {} } | 
|  | 23 | +        let(:props) do | 
|  | 24 | +          { | 
|  | 25 | +            'cc' => { | 
|  | 26 | +              'droplets' => { 'connection_config' => {} }, | 
|  | 27 | +              'buildpacks' => { 'connection_config' => {} }, | 
|  | 28 | +              'packages' => { 'connection_config' => {} }, | 
|  | 29 | +              'resource_pool' => { 'connection_config' => {} } | 
|  | 30 | +            } | 
|  | 31 | +          } | 
|  | 32 | +        end | 
| 29 | 33 | 
 | 
| 30 |  | -    TEMPLATES.each do |scope, (template_path, keypath)| | 
| 31 |  | -      describe template_path do | 
| 32 |  | -        let(:template) { job.template(template_path) } | 
|  | 34 | +        TEMPLATES.each_value do |(template_path, keypath)| | 
|  | 35 | +          describe template_path do | 
|  | 36 | +            let(:template) { job.template(template_path) } | 
| 33 | 37 | 
 | 
| 34 |  | -        def set(props, keypath, value) | 
| 35 |  | -          h = props | 
| 36 |  | -          keypath[0..-2].each { |k| h = (h[k] ||= {}) } | 
| 37 |  | -          h[keypath.last] = value | 
| 38 |  | -        end | 
|  | 38 | +            def set(props, keypath, value) | 
|  | 39 | +              h = props | 
|  | 40 | +              keypath[0..-2].each { |k| h = (h[k] ||= {}) } | 
|  | 41 | +              h[keypath.last] = value | 
|  | 42 | +            end | 
| 39 | 43 | 
 | 
| 40 |  | -        it 'renders and normalizes put_timeout_in_seconds to "41" when blank' do | 
| 41 |  | -          set(props, keypath, { | 
| 42 |  | -            'provider' => 'AzureRM', | 
| 43 |  | -            'azure_storage_account_name' => 'acc', | 
| 44 |  | -            'azure_storage_access_key'   => 'key', | 
| 45 |  | -            'container_name'             => 'cont', | 
| 46 |  | -            'put_timeout_in_seconds'     => '' | 
| 47 |  | -          }) | 
|  | 44 | +            it 'renders and normalizes put_timeout_in_seconds to "41" when blank' do | 
|  | 45 | +              set(props, keypath, { | 
|  | 46 | +                    'provider' => 'AzureRM', | 
|  | 47 | +                    'azure_storage_account_name' => 'acc', | 
|  | 48 | +                    'azure_storage_access_key' => 'key', | 
|  | 49 | +                    'container_name' => 'cont', | 
|  | 50 | +                    'put_timeout_in_seconds' => '' | 
|  | 51 | +                  }) | 
| 48 | 52 | 
 | 
| 49 |  | -          json = JSON.parse(template.render(props, consumes: links)) | 
| 50 |  | -          expect(json).to include( | 
| 51 |  | -                            'provider'               => 'AzureRM', | 
| 52 |  | -                            'account_name'           => 'acc', | 
| 53 |  | -                            'account_key'            => 'key', | 
| 54 |  | -                            'container_name'         => 'cont', | 
| 55 |  | -                            'put_timeout_in_seconds' => '41' | 
| 56 |  | -                          ) | 
| 57 |  | -        end | 
|  | 53 | +              json = Oj.parse(template.render(props, consumes: links)) | 
|  | 54 | +              expect(json).to include( | 
|  | 55 | +                'provider' => 'AzureRM', | 
|  | 56 | +                'account_name' => 'acc', | 
|  | 57 | +                'account_key' => 'key', | 
|  | 58 | +                'container_name' => 'cont', | 
|  | 59 | +                'put_timeout_in_seconds' => '41' | 
|  | 60 | +              ) | 
|  | 61 | +            end | 
| 58 | 62 | 
 | 
| 59 |  | -        it 'keeps existing put_timeout_in_seconds when provided' do | 
| 60 |  | -          set(props, keypath, { | 
| 61 |  | -            'provider' => 'AzureRM', | 
| 62 |  | -            'azure_storage_account_name' => 'acc', | 
| 63 |  | -            'azure_storage_access_key'   => 'key', | 
| 64 |  | -            'container_name'             => 'cont', | 
| 65 |  | -            'put_timeout_in_seconds'     => '7' | 
| 66 |  | -          }) | 
|  | 63 | +            it 'keeps existing put_timeout_in_seconds when provided' do | 
|  | 64 | +              set(props, keypath, { | 
|  | 65 | +                    'provider' => 'AzureRM', | 
|  | 66 | +                    'azure_storage_account_name' => 'acc', | 
|  | 67 | +                    'azure_storage_access_key' => 'key', | 
|  | 68 | +                    'container_name' => 'cont', | 
|  | 69 | +                    'put_timeout_in_seconds' => '7' | 
|  | 70 | +                  }) | 
| 67 | 71 | 
 | 
| 68 |  | -          json = JSON.parse(template.render(props, consumes: links)) | 
| 69 |  | -          expect(json['put_timeout_in_seconds']).to eq('7') | 
| 70 |  | -        end | 
|  | 72 | +              json = Oj.parse(template.render(props, consumes: links)) | 
|  | 73 | +              expect(json['put_timeout_in_seconds']).to eq('7') | 
|  | 74 | +            end | 
| 71 | 75 | 
 | 
| 72 |  | -        it 'renders {} for non-Azure providers' do | 
| 73 |  | -          set(props, keypath, { 'provider' => 'S3' }) | 
| 74 |  | -          json = JSON.parse(template.render(props, consumes: links)) | 
| 75 |  | -          expect(json).to eq({}) | 
|  | 76 | +            it 'renders {} for non-Azure providers' do | 
|  | 77 | +              set(props, keypath, { 'provider' => 'S3' }) | 
|  | 78 | +              json = Oj.parse(template.render(props, consumes: links)) | 
|  | 79 | +              expect(json).to eq({}) | 
|  | 80 | +            end | 
|  | 81 | +          end | 
| 76 | 82 |         end | 
| 77 | 83 |       end | 
| 78 | 84 |     end | 
|  | 
0 commit comments