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

(GH-2438) Don't warn that project content won't be loaded if there's no project content #2468

Merged
merged 1 commit into from
Dec 14, 2020
Merged
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
5 changes: 4 additions & 1 deletion lib/bolt/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,10 @@ def validate
raise Bolt::ValidationError, "The project '#{name}' will not be loaded. The project name conflicts "\
"with a built-in Bolt module of the same name."
end
else
elsif name.nil? &&
(File.directory?(plans_path) ||
File.directory?(@path + 'tasks') ||
File.directory?(@path + 'files'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we including the files/ directory in this check? I know tasks/ and plans/ make sense, since you can reference content in those directories from the CLI, but I don't think you can for files/ (unless I'm missing a command).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could reference a file from the project in a manifest being applied, for (very contrived) example:

bolt apply -e " file { '/tmp/foobar': content => file('myproject/service.conf'), ensure => present }"

Or more likely from a manifest file you specify with bolt apply.

I think we opted not to include manifests for the reason you said, that usually if you're consuming manifests it's probably in a plan (in which case you'd get the error). We could add manifests/ too to err on the side of zealously warning, in case people are consuming the project from a module on the modulepath or something.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really worried about it, and it's easy enough to add to the check later if needed. :) I was more just curious why files/ was included, and that example makes perfect sense!

message = "No project name is specified in bolt-project.yaml. Project-level content will not be available."
@logs << { warn: message }
end
Expand Down
23 changes: 23 additions & 0 deletions spec/bolt/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,29 @@
end
end

describe "with no name set" do
it "warns if content directories exist" do
Dir.mktmpdir(nil, Dir.pwd) do |tmpdir|
project_path = Pathname.new(tmpdir).expand_path + 'project'
allow(File).to receive(:directory?).and_call_original
allow(File).to receive(:directory?)
.with(project_path + 'plans').and_return(true)

FileUtils.mkdir_p(project_path)
project = Bolt::Project.create_project(project_path)
project.validate

expect(project.logs).to include({ warn: /No project name is specified in bolt-project.yaml/ })
end
end

it "does not warn when content directories don't exist" do
with_project do
expect(project.logs).not_to include({ warn: /No project name is specified in bolt-project.yaml/ })
end
end
end

describe "::find_boltdir" do
around(:each) do |example|
with_boltdir do
Expand Down
4 changes: 3 additions & 1 deletion spec/integration/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
require 'spec_helper'
require 'bolt_spec/config'
require 'bolt_spec/conn'
require 'bolt_spec/files'
require 'bolt_spec/integration'
require 'bolt_spec/project'

describe "When loading content", ssh: true do
include BoltSpec::Config
include BoltSpec::Conn
include BoltSpec::Files
include BoltSpec::Integration
include BoltSpec::Project

let(:local) { Bolt::Project.create_project(File.join(__dir__, '../fixtures/projects/local'), 'local') }
let(:local) { Bolt::Project.create_project(fixtures_path('projects', 'local'), 'local') }
let(:embedded) { fixture_path('projects/embedded') }
let(:target) { conn_uri('ssh') }
let(:config_flags) { %W[--no-host-key-check --password #{conn_info('ssh')[:password]}] }
Expand Down