test/cli_test.rb in pups-1.1.1 vs test/cli_test.rb in pups-1.2.0

- old
+ new

@@ -1,49 +1,49 @@ # frozen_string_literal: true -require 'test_helper' -require 'tempfile' -require 'stringio' +require "test_helper" +require "tempfile" +require "stringio" module Pups - class CliTest < MiniTest::Test + class CliTest < ::Minitest::Test def test_cli_option_parsing_stdin - options = Cli.parse_args(['--stdin']) + options = Cli.parse_args(["--stdin"]) assert_equal(true, options[:stdin]) end def test_cli_option_parsing_none options = Cli.parse_args([]) assert_nil(options[:stdin]) end def test_cli_read_config_from_file # for testing output - f = Tempfile.new('test_output') + f = Tempfile.new("test_output") f.close # for testing input - cf = Tempfile.new('test_config') + cf = Tempfile.new("test_config") cf.puts <<~YAML params: run: #{f.path} run: - exec: echo hello world >> #{f.path} YAML cf.close Cli.run([cf.path]) - assert_equal('hello world', File.read(f.path).strip) + assert_equal("hello world", File.read(f.path).strip) end def test_cli_ignore_config_element # for testing output - f = Tempfile.new('test_output') + f = Tempfile.new("test_output") f.close # for testing input - cf = Tempfile.new('test_config') + cf = Tempfile.new("test_config") cf.puts <<~YAML env: MY_IGNORED_VAR: a_word params: a_param_var: another_word @@ -51,11 +51,11 @@ - exec: echo repeating $MY_IGNORED_VAR and also $a_param_var >> #{f.path} YAML cf.close Cli.run(["--ignore", "env,params", cf.path]) - assert_equal('repeating and also', File.read(f.path).strip) + assert_equal("repeating and also", File.read(f.path).strip) end def test_cli_gen_docker_run_args_ignores_other_config # When generating the docker run arguments it should ignore other template configuration # like 'run' directives. @@ -109,9 +109,60 @@ expected << "--link postgres:postgres --link foo:bar" expected << "--label monitor=true --label app_name=my_app_discourse" expected.sort! assert_equal("", File.read(f.path).strip) - assert_output(expected.join(" ")) { Cli.run(["--gen-docker-run-args", cf.path]) } + assert_output(expected.join(" ")) do + Cli.run(["--gen-docker-run-args", cf.path]) + end + end + + def test_cli_tags + # for testing output + f = Tempfile.new("test_output") + f.close + + # for testing input + cf = Tempfile.new("test_config") + cf.puts <<~YAML + run: + - exec: + tag: '1' + cmd: echo 1 >> #{f.path} + - exec: + tag: '2' + cmd: echo 2 >> #{f.path} + - exec: + tag: '3' + cmd: echo 3 >> #{f.path} + YAML + cf.close + + Cli.run(["--tags", "1,3", cf.path]) + assert_equal("1\n3", File.read(f.path).strip) + end + def test_cli_skip_tags + # for testing output + f = Tempfile.new("test_output") + f.close + + # for testing input + cf = Tempfile.new("test_config") + cf.puts <<~YAML + run: + - exec: + tag: '1' + cmd: echo 1 >> #{f.path} + - exec: + tag: '2' + cmd: echo 2 >> #{f.path} + - exec: + tag: '3' + cmd: echo 3 >> #{f.path} + YAML + cf.close + + Cli.run(["--skip-tags", "1,3", cf.path]) + assert_equal("2", File.read(f.path).strip) end end end