forked from puppetlabs/bolt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(puppetlabsGH-1365) Move resolve_references functions to Bolt::Plugin
This commit moves the resolve_references functions from Bolt::Inventory::Group2 to Bolt::Plugin.
- Loading branch information
Showing
8 changed files
with
189 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
bolt-modules/boltlib/spec/fixtures/modules/test/tasks/references.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require 'json' | ||
|
||
values = { | ||
"value" => { | ||
"name" => "127.0.0.1" | ||
} | ||
} | ||
|
||
puts values.to_json |
56 changes: 54 additions & 2 deletions
56
bolt-modules/boltlib/spec/functions/resolve_references_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,61 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'bolt/plugin' | ||
|
||
describe 'resolve_references' do | ||
it 'resolves data' do | ||
# TODO | ||
include PuppetlabsSpec::Fixtures | ||
let(:boltdir) { Bolt::Boltdir.new('./spec/fixtures') } | ||
let(:config) { Bolt::Config.new(boltdir, {}) } | ||
let(:pal) { Bolt::PAL.new(config.modulepath, config.hiera_config, config.boltdir.resource_types) } | ||
let(:pdb_client) { Bolt::PuppetDB::Client.new({}) } | ||
let(:analytics) { Bolt::Analytics::NoopClient.new } | ||
let(:plugins) { Bolt::Plugin.setup(config, pal, pdb_client, analytics) } | ||
let(:inventory) { Bolt::Inventory.new({}, plugins: plugins) } | ||
let(:tasks_enabled) { true } | ||
|
||
let(:references) do | ||
{ | ||
"targets" => { | ||
"_plugin" => "task", | ||
"task" => "test::references" | ||
} | ||
} | ||
end | ||
|
||
let(:resolved) do | ||
{ | ||
"targets" => { | ||
"name" => "127.0.0.1" | ||
} | ||
} | ||
end | ||
|
||
around(:each) do |example| | ||
Puppet[:tasks] = tasks_enabled | ||
Puppet.override(bolt_inventory: inventory) do | ||
example.run | ||
end | ||
end | ||
|
||
context 'calls resolve_references' do | ||
it 'resolves all plugin references' do | ||
is_expected.to run.with_params(references).and_return(resolved) | ||
end | ||
|
||
it 'errors when called with incorrect plugin data' do | ||
references['targets']['_plugin'] = 'fake_plugin' | ||
is_expected.to run.with_params(references).and_raise_error(/Unknown plugin/) | ||
end | ||
end | ||
|
||
context 'without tasks enabled' do | ||
let(:tasks_enabled) { false } | ||
|
||
it 'fails and reports that resolve_references is not available' do | ||
is_expected.to run | ||
.with_params(references) | ||
.and_raise_error(/Plan language function 'resolve_references' cannot be used/) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.