diff --git a/test/cli/secrets_test.rb b/test/cli/secrets_test.rb index e69de29b..0fa78eb6 100644 --- a/test/cli/secrets_test.rb +++ b/test/cli/secrets_test.rb @@ -0,0 +1,50 @@ +require_relative "cli_test_case" + +class CliSecretsTest < CliTestCase + test "login" do + run_command("login").tap do |output| + assert_match /docker login -u \[REDACTED\] -p \[REDACTED\] as .*@localhost/, output + assert_match /docker login -u \[REDACTED\] -p \[REDACTED\] on 1.1.1.\d/, output + end + end + + test "fetch" do + run_command("login", "-L").tap do |output| + assert_no_match /docker login -u \[REDACTED\] -p \[REDACTED\] as .*@localhost/, output + assert_match /docker login -u \[REDACTED\] -p \[REDACTED\] on 1.1.1.\d/, output + end + end + + test "fetch_all" do + run_command("login", "-R").tap do |output| + assert_match /docker login -u \[REDACTED\] -p \[REDACTED\] as .*@localhost/, output + assert_no_match /docker login -u \[REDACTED\] -p \[REDACTED\] on 1.1.1.\d/, output + end + end + + test "extract" do + run_command("logout").tap do |output| + assert_match /docker logout as .*@localhost/, output + assert_match /docker logout on 1.1.1.\d/, output + end + end + + test "logout skip local" do + run_command("logout", "-L").tap do |output| + assert_no_match /docker logout as .*@localhost/, output + assert_match /docker logout on 1.1.1.\d/, output + end + end + + test "logout skip remote" do + run_command("logout", "-R").tap do |output| + assert_match /docker logout as .*@localhost/, output + assert_no_match /docker logout on 1.1.1.\d/, output + end + end + + private + def run_command(*command) + stdouted { Kamal::Cli::Secrets.start([ *command, "-c", "test/fixtures/deploy_with_accessories.yml" ]) } + end +end diff --git a/test/env_file_test.rb b/test/env_file_test.rb deleted file mode 100644 index c6b9e66e..00000000 --- a/test/env_file_test.rb +++ /dev/null @@ -1,76 +0,0 @@ -require "test_helper" - -class EnvFileTest < ActiveSupport::TestCase - test "to_s" do - env = { - "foo" => "bar", - "baz" => "haz" - } - - assert_equal "foo=bar\nbaz=haz\n", \ - Kamal::EnvFile.new(env).to_s - end - - test "to_str won't escape chinese characters" do - env = { - "foo" => 'δ½ ε₯½ means hello, "欒迎" means welcome, that\'s simple! πŸ˜ƒ {smile}' - } - - assert_equal "foo=δ½ ε₯½ means hello, \"欒迎\" means welcome, that's simple! πŸ˜ƒ {smile}\n", - Kamal::EnvFile.new(env).to_s - end - - test "to_s won't escape japanese characters" do - env = { - "foo" => 'こんにけは means hello, "γ‚ˆγ†γ“γ" means welcome, that\'s simple! πŸ˜ƒ {smile}' - } - - assert_equal "foo=こんにけは means hello, \"γ‚ˆγ†γ“γ\" means welcome, that's simple! πŸ˜ƒ {smile}\n", \ - Kamal::EnvFile.new(env).to_s - end - - test "to_s won't escape korean characters" do - env = { - "foo" => 'μ•ˆλ…•ν•˜μ„Έμš” means hello, "μ–΄μ„œ μ˜€μ‹­μ‹œμ˜€" means welcome, that\'s simple! πŸ˜ƒ {smile}' - } - - assert_equal "foo=μ•ˆλ…•ν•˜μ„Έμš” means hello, \"μ–΄μ„œ μ˜€μ‹­μ‹œμ˜€\" means welcome, that's simple! πŸ˜ƒ {smile}\n", \ - Kamal::EnvFile.new(env).to_s - end - - test "to_s empty" do - assert_equal "\n", Kamal::EnvFile.new({}).to_s - end - - test "to_s escaped newline" do - env = { - "foo" => "hello\\nthere" - } - - assert_equal "foo=hello\\\\nthere\n", \ - Kamal::EnvFile.new(env).to_s - ensure - ENV.delete "PASSWORD" - end - - test "to_s newline" do - env = { - "foo" => "hello\nthere" - } - - assert_equal "foo=hello\\nthere\n", \ - Kamal::EnvFile.new(env).to_s - ensure - ENV.delete "PASSWORD" - end - - test "stringIO conversion" do - env = { - "foo" => "bar", - "baz" => "haz" - } - - assert_equal "foo=bar\nbaz=haz\n", \ - StringIO.new(Kamal::EnvFile.new(env)).read - end -end