summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2016-04-12 10:25:25 -0700
committerelijah <elijah@riseup.net>2016-04-12 10:25:25 -0700
commit50980798983c9cf9b4d562a2a9279ef3ab3d25fc (patch)
tree2b7e2e6fcb9cca269c11bb77152eece3be7c6acf
parent298ae98021443dabe98e6855436f24ad8ad12a99 (diff)
move template() from manager to environment. closes #8026
-rw-r--r--lib/leap_cli/config/environment.rb13
-rw-r--r--lib/leap_cli/config/manager.rb16
-rw-r--r--test/test_helper.rb9
-rw-r--r--test/unit/command_line_test.rb7
4 files changed, 32 insertions, 13 deletions
diff --git a/lib/leap_cli/config/environment.rb b/lib/leap_cli/config/environment.rb
index 3f0b3f3..df4b56c 100644
--- a/lib/leap_cli/config/environment.rb
+++ b/lib/leap_cli/config/environment.rb
@@ -100,6 +100,19 @@ module LeapCli; module Config
end
end
+ #
+ # Loads a json template file as a Hash (used only when creating a new node .json
+ # file for the first time).
+ #
+ def template(template)
+ path = Path.named_path([:template_config, template], Path.provider_base)
+ if File.exists?(path)
+ return load_json(path, Config::Object)
+ else
+ return nil
+ end
+ end
+
private
def load_all_json(pattern, object_class, options={})
diff --git a/lib/leap_cli/config/manager.rb b/lib/leap_cli/config/manager.rb
index 4ad8b71..ecc59f3 100644
--- a/lib/leap_cli/config/manager.rb
+++ b/lib/leap_cli/config/manager.rb
@@ -71,6 +71,9 @@ module LeapCli
def common; env(default_environment).common; end
def secrets; env(default_environment).secrets; end
def nodes; env(default_environment).nodes; end
+ def template(*args)
+ self.env.template(*args)
+ end
def default_environment
LeapCli.leapfile.environment
@@ -280,19 +283,6 @@ module LeapCli
@connections ||= ConnectionList.new
end
- #
- # Loads a json template file as a Hash (used only when creating a new node .json
- # file for the first time).
- #
- def template(template)
- path = Path.named_path([:template_config, template], Path.provider_base)
- if File.exists?(path)
- return load_json(path, Config::Object)
- else
- return nil
- end
- end
-
##
## PRIVATE
##
diff --git a/test/test_helper.rb b/test/test_helper.rb
index b9a2c9e..f7ec6d9 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -4,6 +4,7 @@ require 'bundler/setup'
require 'minitest/autorun'
require 'leap_cli'
require 'gli'
+require 'fileutils'
DEBUG = true
@@ -49,6 +50,14 @@ class Minitest::Test
"#{base_path}/test/provider"
end
+ def cleanup_files(*args)
+ Dir.chdir(test_provider_path) do
+ args.each do |file|
+ FileUtils.rm_r(file) if File.exist?(file)
+ end
+ end
+ end
+
def with_multiple_rubies(&block)
if ENV["RUBY"]
ENV["RUBY"].split(',').each do |ruby|
diff --git a/test/unit/command_line_test.rb b/test/unit/command_line_test.rb
index 2aaf1c1..12f8e2c 100644
--- a/test/unit/command_line_test.rb
+++ b/test/unit/command_line_test.rb
@@ -17,4 +17,11 @@ class CommandLineTest < Minitest::Test
end
end
+ def test_add_node
+ output = leap_bin("node add banana tags:production services:openvpn ip_address:1.1.1.1")
+ cleanup_files('nodes/banana.json', 'files/nodes/banana')
+ assert_match /created nodes\/banana\.json/, output
+ assert_match /created files\/nodes\//, output
+ end
+
end