diff --git a/test/test_cli.rb b/test/test_cli.rb index 0db3ffa..c3466e8 100644 --- a/test/test_cli.rb +++ b/test/test_cli.rb @@ -12,39 +12,78 @@ class TestConfig < Test::Unit::TestCase FileUtils.rm_rf("#{Dir.home}/.config/mpw") FileUtils.rm_rf("#{Dir.home}/.gnupg") - output = `echo "#{@password}\n#{@password}" | mpw config --init test@example.com` + output = %x(echo "#{@password}\n#{@password}" | mpw config --init test@example.com) assert_match('The config file has been created', output) assert_match('Your GPG key has been created ;-)', output) end def test_01_add_item - host = 'example.com' + host = 'example.com' + port = 1234 + proto = 'http' + user = 'root' + comment = 'the super website' + group = 'Bank' - output = `echo #{@password} | mpw add --host #{host} -r` + output = %x( + echo #{@password} | mpw add \ + --host #{host} \ + --port #{port} \ + --protocol #{proto} \ + --user #{user} \ + --comment '#{comment}' \ + --group #{group} \ + --random) + puts output assert_match('Item has been added!', output) - - output = `echo #{@password} | mpw list` - assert_match(host, output) + + output = %x(echo #{@password} | mpw list) + puts output + assert_match(%r{#{proto}://.+#{host}.+:#{port}}, output) + assert_match(user, output) + assert_match(comment, output) + assert_match(group, output) end def test_02_update_item - host_old = 'example.com' - host_new = 'example2.com' + host_old = 'example.com' + host_new = 'example2.com' + port_new = 4321 + proto_new = 'ssh' + user_new = 'tortue' + comment_new = 'my account' + group_new = 'Assurance' - output = `echo #{@password} | mpw update -p #{host_old} --host #{host_new}` + output = %x( + echo #{@password} | mpw update \ + -p #{host_old} \ + --host #{host_new} \ + --port #{port_new} \ + --protocol #{proto_new} \ + --user #{user_new} \ + --comment '#{comment_new}' \ + --new-group #{group_new} + ) + puts output assert_match('Item has been updated!', output) - - output = `echo #{@password} | mpw list` - assert_match(host_new, output) + + output = %x(echo #{@password} | mpw list) + puts output + assert_match(%r{#{proto_new}://.+#{host_new}.+:#{port_new}}, output) + assert_match(user_new, output) + assert_match(comment_new, output) + assert_match(group_new, output) end def test_03_delete_item host = 'example2.com' - output = `echo "#{@password}\ny" | mpw delete -p #{host}` + output = %x(echo "#{@password}\ny" | mpw delete -p #{host}) + puts output assert_match('The item has been removed!', output) - - output = `echo #{@password} | mpw list` + + output = %x(echo #{@password} | mpw list) + puts output assert_no_match(/#{host}/, output) end end