Merge pull request #812 from pmcmaw/Update_localization_tests
[puppet-modules/puppetlabs-apt.git] / spec / acceptance / locales_spec.rb
1 require 'spec_helper_acceptance'
2 require 'beaker/i18n_helper'
3
4 PUPPETLABS_GPG_KEY_LONG_ID     = '7F438280EF8D349F'.freeze
5 PUPPETLABS_LONG_FINGERPRINT    = '123456781274D2C8A956789A456789A456789A9A'.freeze
6
7 id_doesnt_match_fingerprint_pp = <<-MANIFEST
8   apt_key { '#{PUPPETLABS_LONG_FINGERPRINT}':
9     ensure => 'present',
10     content => '123456781274D2C8A956789A456789A456789A9B',
11   }
12 MANIFEST
13
14 location_not_specified_fail_pp = <<-MANIFEST
15   apt::source { 'puppetlabs':
16     ensure => 'present',
17     repos    => 'main',
18     key      => {
19       id     => '6F6B15509CF8E59E6E469F327F438280EF8D349F',
20       server => 'hkps.pool.sks-keyservers.net',
21     },
22   }
23 MANIFEST
24
25 no_content_param = <<-MANIFEST
26   apt_conf {
27     ensure => 'present',
28   }
29 MANIFEST
30
31 invalid_ensure = <<-MANIFEST
32   apt_key { '#{PUPPETLABS_LONG_FINGERPRINT}':
33     ensure => 'bourbon',
34   }
35 MANIFEST
36
37 describe 'localization', if: (fact('osfamily') == 'Debian' || fact('osfamily') == 'RedHat') && (Gem::Version.new(puppet_version) >= Gem::Version.new('4.10.5')) do
38   before :all do
39     hosts.each do |host|
40       on(host, "sed -i \"96i FastGettext.locale='ja'\" /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet.rb")
41       change_locale_on(host, 'ja_JP.utf-8')
42     end
43   end
44
45   describe 'ruby translations' do
46     it 'fails with interpolated string' do
47       apply_manifest(id_doesnt_match_fingerprint_pp, expect_failures: true) do |r|
48         expect(r.stderr).to match(%r{を設定できませんでした: マニフェスト123456781274D2C8A956789A456789A456789A9Aに含まれるidと、content/sourceのフィンガープリントが一致しません。idに間違いがないか、content/sourceが正当であるかを確認してください})
49       end
50     end
51     it 'fails with simple string' do
52       apply_manifest(location_not_specified_fail_pp, expect_failures: true) do |r|
53         expect(r.stderr).to match(%r{の検証中にエラーが生じました。Evaluation Error: a Function Callの検証中にエラーが生じました。場所を指定せずにソースエントリを作成することはできません})
54       end
55     end
56   end
57
58   describe 'puppet translations' do
59     it 'fails with interpolated string' do
60       apply_manifest(invalid_ensure, expect_failures: true) do |r|
61         expect(r.stderr).to match(%r{失敗しました: 無効な値\"bourbon\" 有効な値は})
62       end
63     end
64     it 'fails with simple string' do
65       apply_manifest(no_content_param, expect_failures: true) do |r|
66         expect(r.stderr).to match(%r{この表現は無効です。タイトルなしの'apt_conf'リソースの宣言を試みましたか?})
67       end
68     end
69   end
70
71   after :all do
72     hosts.each do |host|
73       on(host, 'sed -i "96d" /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet.rb')
74       change_locale_on(host, 'en_US')
75     end
76   end
77 end