Skip to content

Commit

Permalink
lint a random file
Browse files Browse the repository at this point in the history
  • Loading branch information
osc-bot committed Oct 16, 2024
1 parent af498f3 commit 00eadab
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions nginx_stage/spec/generators/pun_config_generator_spec.rb
Original file line number Diff line number Diff line change
@@ -1,63 +1,64 @@
# frozen_string_literal: true

require 'spec_helper'
require 'nginx_stage'

describe NginxStage::PunConfigGenerator do
let(:test_user) { "spec" }
let(:test_user) { 'spec' }
let(:test_user_gid) { 1000 }

before(:each) {
before do
etc_stub = {
:gid => test_user_gid,
:gid => test_user_gid,
:name => test_user
}

allow(Etc).to receive(:getpwnam).with(test_user).and_return(Struct.new(*etc_stub.keys).new(*etc_stub.values))
allow(Etc).to receive(:getgrgid).with(test_user_gid).and_return(Struct.new(*etc_stub.keys).new(*etc_stub.values))
allow_any_instance_of(NginxStage::User).to receive(:get_groups).and_return([test_user])
}
end

it 'has the correct options' do
expect(NginxStage::PunConfigGenerator.options.keys).to eq([:user, :skip_nginx, :app_init_url, :pre_hook_root_cmd])
expect(described_class.options.keys).to eq([:user, :skip_nginx, :app_init_url, :pre_hook_root_cmd])
end

it 'requires the user option' do
expect { described_class.new }.to raise_error(NginxStage::MissingOption, "missing option: user")
expect { described_class.new }.to raise_error(NginxStage::MissingOption, 'missing option: user')
end


describe 'pre_hook_root_cmd' do

let(:generator){
let(:generator) do
described_class.new({
:user => test_user,
:pre_hook_root_cmd => '/opt/pre_hook'
})
}
:user => test_user,
:pre_hook_root_cmd => '/opt/pre_hook'
})
end

let(:hook){
let(:hook) do
generator.class.hooks[:exec_pre_hook]
}
end

it 'invokes the right root pre hook' do
allow(Open3).to receive(:capture3).with('/opt/pre_hook', '--user', test_user)
generator.instance_eval(&hook)
end

it 'logs exceptions from underlying script' do
allow(Open3).to receive(:capture3).with('/opt/pre_hook', '--user', test_user).and_raise(StandardError.new "this is a test")
allow(Open3).to receive(:capture3).with('/opt/pre_hook', '--user',
test_user).and_raise(StandardError.new('this is a test'))
allow_any_instance_of(Syslog::Logger).to receive(:error).with("/opt/pre_hook threw exception 'this is a test' for spec")
generator.instance_eval(&hook)
end

it 'logs non-zero exits from underlying script' do
allow(Open3).to receive(:capture3)
.with('/opt/pre_hook', '--user', test_user)
.and_return(["", "this is the test stderr message", double(:success? => false, :exitstatus => 3)])
.and_return(['', 'this is the test stderr message', double(:success? => false, :exitstatus => 3)])

allow_any_instance_of(Syslog::Logger).to receive(:error)
.with("/opt/pre_hook exited with 3 for user spec. stderr was 'this is the test stderr message'")

generator.instance_eval(&hook)
end
end
end
end

0 comments on commit 00eadab

Please sign in to comment.