From 4897658a6237a41bd4715a7414bea953e536e6bf Mon Sep 17 00:00:00 2001 From: Charles Greene Date: Mon, 10 Jul 2017 15:44:32 -0300 Subject: [PATCH] Update tests --- test/roku_builder/test_config.rb | 32 +++++++++++++++ test/roku_builder/test_options.rb | 65 ++++++++++++++++++++++++++----- 2 files changed, 88 insertions(+), 9 deletions(-) diff --git a/test/roku_builder/test_config.rb b/test/roku_builder/test_config.rb index db1159d..d997179 100644 --- a/test/roku_builder/test_config.rb +++ b/test/roku_builder/test_config.rb @@ -119,6 +119,38 @@ def test_config_configure_edit_params File.delete(target_config) if File.exist?(target_config) end + def test_config_configure_edit_params_project + target_config = File.join(test_files_path(ConfigTest), "configure_test.json") + options = build_options({ + config: target_config, + configure: true, + edit_params: "directory:/test/dir" + }) + File.delete(target_config) if File.exist?(target_config) + refute File.exist?(target_config) + config = Config.new(options: options) + config.configure + assert File.exist?(target_config) + assert_equal "/test/dir", config.raw[:projects][config.raw[:projects][:default]][:directory] + File.delete(target_config) if File.exist?(target_config) + end + + def test_config_configure_edit_params_stage + target_config = File.join(test_files_path(ConfigTest), "configure_test.json") + options = build_options({ + config: target_config, + configure: true, + edit_params: "branch:test" + }) + File.delete(target_config) if File.exist?(target_config) + refute File.exist?(target_config) + config = Config.new(options: options) + config.configure + assert File.exist?(target_config) + assert_equal "test", config.raw[:projects][config.raw[:projects][:default]][:stages][:production][:branch] + File.delete(target_config) if File.exist?(target_config) + end + def test_config_configure_edit_params_default target_config = File.join(test_files_path(ConfigTest), "configure_test.json") options = build_options({ diff --git a/test/roku_builder/test_options.rb b/test/roku_builder/test_options.rb index 2f41ee6..d97b4b5 100644 --- a/test/roku_builder/test_options.rb +++ b/test/roku_builder/test_options.rb @@ -5,7 +5,8 @@ module RokuBuilder class OptionsTest < Minitest::Test def setup - RokuBuilder.class_variable_set(:@@plugins, []) + RokuBuilder.setup_plugins + register_plugins(Core) Logger.set_testing end def teardown @@ -36,8 +37,10 @@ def test_options_parse parser.expect(:banner=, nil, [String]) parser.expect(:parse!, nil) OptionParser.stub(:new, parser) do - options.stub(:validate_parser, nil) do - options_hash = options.send(:parse) + options.stub(:add_plugin_options, nil) do + options.stub(:validate_parser, nil) do + options_hash = options.send(:parse) + end end end parser.verify @@ -50,12 +53,14 @@ def test_options_parse_validate_options_good parser.expect(:banner=, nil, [String]) parser.expect(:parse!, nil) OptionParser.stub(:new, parser) do - options.send(:parse) + options.stub(:add_plugin_options, nil) do + options.send(:parse) + end end parser.verify Array.class_eval { remove_method :each_option } end - def test_options_parse_validate_options_bad + def test_options_parse_validate_options_bad_short Array.class_eval { alias_method :each_option, :each } parser = Minitest::Mock.new() options = Options.allocate @@ -64,13 +69,32 @@ def test_options_parse_validate_options_bad OptionParser.stub(:new, parser) do assert_raises(ImplementationError) do - options.send(:parse) + options.stub(:add_plugin_options, nil) do + options.send(:parse) + end end end parser.verify Array.class_eval { remove_method :each_option } end - def build_stack(good = true) + def test_options_parse_validate_options_bad_long + Array.class_eval { alias_method :each_option, :each } + parser = Minitest::Mock.new() + options = Options.allocate + parser.expect(:banner=, nil, [String]) + parser.expect(:instance_variable_get, build_stack(true, false), [:@stack]) + + OptionParser.stub(:new, parser) do + options.stub(:add_plugin_options, nil) do + assert_raises(ImplementationError) do + options.send(:parse) + end + end + end + parser.verify + Array.class_eval { remove_method :each_option } + end + def build_stack(shortgood = true, longgood = true) optionsA = Minitest::Mock.new() optionsB = Minitest::Mock.new() list = [optionsA, optionsB] @@ -78,11 +102,14 @@ def build_stack(good = true) 3.times do optionsA.expect(:short, [ "a" ]) optionsA.expect(:long, [ "aOption" ]) - if good + if shortgood optionsB.expect(:short, [ "b" ]) - optionsB.expect(:long, ["bOption" ]) else optionsB.expect(:short, [ "a" ]) + end + if longgood + optionsB.expect(:long, ["bOption" ]) + else optionsB.expect(:long, [ "aOption" ]) end end @@ -103,6 +130,15 @@ def test_options_validate_no_commands build_options(options) end end + def test_options_validate_source + options = Options.allocate + options.stub(:source_command?, true) do + assert_raises InvalidOptions do + options.send(:initialize, {options: {validate: true}}) + options.validate + end + end + end def test_options_validate_extra_sources_sideload options = { validate: true, @@ -123,6 +159,17 @@ def test_options_validate_extra_sources_package build_options(options) end end + def test_options_validate_depricated + options = Options.allocate + logger = Minitest::Mock.new() + logger.expect(:warn, nil, ["Depricated"]) + Logger.class_variable_set(:@@instance, logger) + options.stub(:depricated_options, {validate: "Depricated"}) do + options.send(:initialize, {options: {validate: true}}) + options.validate + end + logger.verify + end def test_options_exclude_command options = build_options({ validate:true,