Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(maint) Fix expect_upload for module relative paths outside files #3238

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/bolt_spec/plans/mock_executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ def module_file_id(file)
path = Pathname.new(file)
relative = path.relative_path_from(Pathname.new(modpath.first))
segments = relative.to_path.split('/')
([segments[0]] + segments[2..-1]).join('/')
if segments[1] == 'files'
([segments[0]] + segments[2..-1]).join('/')
else
segments.join('/')
end
end

def run_command(targets, command, options = {}, _position = [])
Expand Down
1 change: 1 addition & 0 deletions spec/bolt_spec/plan_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ def expect_action
with_tempfile_containing('prep', '') do |file|
@source = file.path
allow_upload(@source).with_targets(targets)
expect_upload('plans/resources/bar').with_destination('/o')
example.run
end
end
Expand Down
16 changes: 16 additions & 0 deletions spec/bolt_spec/plans/mock_executor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,20 @@

expect(missing_methods.empty?).to be(true), message
end

context '#module_file_id' do
let(:executor) { BoltSpec::Plans::MockExecutor.new('/some/path/to/modules') }

it 'returns nil if path is outside of modulepath' do
expect(executor.module_file_id('/some/other/path')).to be_nil
end

it 'handles module relative paths relative to module/files returning module/path excluding the files dir' do
expect(executor.module_file_id('/some/path/to/modules/amodule/files/dingo')).to eq('amodule/dingo')
end

it 'handles module relative paths outside of module/files' do
expect(executor.module_file_id('/some/path/to/modules/amodule/files/../other/dingo')).to eq('amodule/other/dingo')
end
end
end
1 change: 1 addition & 0 deletions spec/fixtures/bolt_spec/plans/plans/upload.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plan plans::upload(TargetSpec $nodes, String $source) {
upload_file($source, '/b', $nodes)
upload_file('plans/files/../resources/bar', '/o', $nodes)
return upload_file('plans/script', '/d', $nodes)
}
1 change: 1 addition & 0 deletions spec/fixtures/bolt_spec/plans/resources/bar
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some other file outside of files/.
Loading