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