|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe 'go::agent::instance' do |
| 4 | + |
| 5 | + context 'with required settings' do |
| 6 | + let(:pre_condition) { 'include ::go::agent' } |
| 7 | + let(:title) { 'gouser' } |
| 8 | + let(:params) do { |
| 9 | + :path => '/opt/go', |
| 10 | + :go_server_host => 'go.example.com', |
| 11 | + :go_server_port => '9999' |
| 12 | + } end |
| 13 | + it { should compile.with_all_deps } |
| 14 | + it { should contain_file('/opt/go/gouser') } |
| 15 | + it { should contain_user('gouser') } |
| 16 | + it { should contain_group('gouser') } |
| 17 | + it { should_not contain_file('/opt/go/gouser/config/autoregister.properties') } |
| 18 | + it { |
| 19 | + should contain_file('/etc/init.d/gouser').with_content(/USER="gouser"\n/) |
| 20 | + should contain_file('/etc/init.d/gouser').with_content(/INSTANCE_NAME="gouser"\n/) |
| 21 | + should contain_file('/etc/init.d/gouser').with_content(/PID_DIR="\/var\/run\/gouser"\n/) |
| 22 | + should contain_file('/etc/init.d/gouser').with_content(/PID_FILE="\/var\/run\/gouser\/go-agent.pid"\n/) |
| 23 | + } |
| 24 | + it { |
| 25 | + should contain_file('/etc/default/gouser').with_content(/export GO_SERVER=go.example.com\n/) |
| 26 | + should contain_file('/etc/default/gouser').with_content(/export GO_SERVER_PORT=9999\n/) |
| 27 | + should contain_file('/etc/default/gouser').with_content(/export JAVA_HOME=\/usr\n/) |
| 28 | + should contain_file('/etc/default/gouser').with_content(/export AGENT_WORK_DIR=\/opt\/go\/gouser\/go-agent\n/) |
| 29 | + should contain_file('/etc/default/gouser').with( |
| 30 | + :notify => 'Service[gouser]' |
| 31 | + ) |
| 32 | + } |
| 33 | + it { should contain_file('/usr/share/go-agent/gouser.sh') } |
| 34 | + it { should contain_service('gouser') } |
| 35 | + end |
| 36 | + |
| 37 | + context 'with memory settings' do |
| 38 | + let(:pre_condition) { 'include ::go::agent' } |
| 39 | + let(:title) { 'gouser' } |
| 40 | + let(:params) do { |
| 41 | + :path => '/opt/go', |
| 42 | + :go_server_host => 'go.example.com', |
| 43 | + :go_server_port => '9999', |
| 44 | + :agent_mem => '512m', |
| 45 | + :agent_max_mem => '1g' |
| 46 | + } end |
| 47 | + it { |
| 48 | + should contain_file('/etc/default/gouser').with_content(/export AGENT_MEM=512m\n/) |
| 49 | + should contain_file('/etc/default/gouser').with_content(/export AGENT_MAX_MEM=1g\n/) |
| 50 | + } |
| 51 | + end |
| 52 | + |
| 53 | + context 'with autoregister and settings' do |
| 54 | + let(:pre_condition) { 'include ::go::agent' } |
| 55 | + let(:title) { 'gouser' } |
| 56 | + let(:params) do { |
| 57 | + :path => '/opt/go', |
| 58 | + :go_server_host => 'go.example.com', |
| 59 | + :go_server_port => '9999', |
| 60 | + :autoregister => true, |
| 61 | + :autoregister_key => 'fookey', |
| 62 | + :autoregister_resources => ['resourceA', 'resourceB'] |
| 63 | + } end |
| 64 | + it { |
| 65 | + should contain_file('/opt/go/gouser/go-agent/autoregister.properties').with_content(/agent.auto.register.key=fookey\n/) |
| 66 | + should contain_file('/opt/go/gouser/go-agent/autoregister.properties').with_content(/agent.auto.register.resources=resourceA,resourceB\n/) |
| 67 | + should_not contain_file('/opt/go/gouser/go-agent/autoregister.properties').with_content(/agent.auto.register.environments=/) |
| 68 | + } |
| 69 | + end |
| 70 | + |
| 71 | + context 'autoregister with no autoregister_key setting' do |
| 72 | + let(:pre_condition) { 'include ::go::agent' } |
| 73 | + let(:title) { 'gouser' } |
| 74 | + let(:params) do { |
| 75 | + :path => '/opt/go', |
| 76 | + :go_server_host => 'go.example.com', |
| 77 | + :go_server_port => '9999', |
| 78 | + :autoregister => true, |
| 79 | + :autoregister_resources => ['resourceA', 'resourceB'] |
| 80 | + } end |
| 81 | + it { |
| 82 | + expect { should compile }.to raise_error() |
| 83 | + } |
| 84 | + end |
| 85 | + |
| 86 | + context 'autoregister with no autoregister_resources setting' do |
| 87 | + let(:pre_condition) { 'include ::go::agent' } |
| 88 | + let(:title) { 'gouser' } |
| 89 | + let(:params) do { |
| 90 | + :path => '/opt/go', |
| 91 | + :go_server_host => 'go.example.com', |
| 92 | + :go_server_port => '9999', |
| 93 | + :autoregister => true, |
| 94 | + :autoregister_key => 'fookey' |
| 95 | + } end |
| 96 | + it { |
| 97 | + expect { should compile }.to raise_error() |
| 98 | + } |
| 99 | + end |
| 100 | + |
| 101 | +end |
0 commit comments