diff --git a/.gitignore b/.gitignore index 7e1052c8..1e13116a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .byebug_history *.gem +coverage/* +.DS_Store \ No newline at end of file diff --git a/test/commands/registry_test.rb b/test/commands/registry_test.rb new file mode 100755 index 00000000..390f2208 --- /dev/null +++ b/test/commands/registry_test.rb @@ -0,0 +1,25 @@ +require "test_helper" +require "mrsk/configuration" +require "mrsk/commands/registry" + +class CommandsRegistryTest < ActiveSupport::TestCase + setup do + @config = { service: "app", + image: "dhh/app", + registry: { "username" => "dhh", + "password" => "secret", + "server" => "hub.docker.com" + }, + servers: [ "1.1.1.1" ] + } + @registry = Mrsk::Commands::Registry.new Mrsk::Configuration.new(@config) + end + + test "registry login" do + assert_equal [ :docker, :login, "hub.docker.com", "-u", "dhh", "-p", "secret" ], @registry.login + end + + test "registry logout" do + assert_equal [:docker, :logout, "hub.docker.com"], @registry.logout + end +end diff --git a/test/commands/traefik_test.rb b/test/commands/traefik_test.rb index 047f421f..8f204ea5 100644 --- a/test/commands/traefik_test.rb +++ b/test/commands/traefik_test.rb @@ -16,6 +16,61 @@ class CommandsTraefikTest < ActiveSupport::TestCase new_command.run end + test "traefik start" do + assert_equal \ + [:docker, :container, :start, 'traefik'], new_command.start + end + + test "traefik stop" do + assert_equal \ + [:docker, :container, :stop, 'traefik'], new_command.stop + end + + test "traefik info" do + assert_equal \ + [:docker, :ps, '--filter', 'name=traefik'], new_command.info + end + + test "traefik logs" do + assert_equal \ + [:docker, :logs, 'traefik', '-t', '2>&1'], new_command.logs + end + + test "traefik logs since 2h" do + assert_equal \ + [:docker, :logs, 'traefik', ' --since 2h', '-t', '2>&1'], new_command.logs(since: '2h') + end + + test "traefik logs last 10 lines" do + assert_equal \ + [:docker, :logs, 'traefik', ' -n 10', '-t', '2>&1'], new_command.logs(lines: 10) + end + + test "traefik logs with grep hello!" do + assert_equal \ + [:docker, :logs, 'traefik', '-t', '2>&1', "|", "grep 'hello!'"], new_command.logs(grep: 'hello!') + end + + test "traefik remove container" do + assert_equal \ + [:docker, :container, :prune, "-f", "--filter", "label=org.opencontainers.image.title=Traefik"], new_command.remove_container + end + + test "traefik remove image" do + assert_equal \ + [:docker, :image, :prune, "-a", "-f", "--filter", "label=org.opencontainers.image.title=Traefik"], new_command.remove_image + end + + test "traefik follow logs" do + assert_equal \ + "ssh -t root@1.1.1.1 'docker logs traefik -t -n 10 -f 2>&1'", new_command.follow_logs(host: @config[:servers].first) + end + + test "traefik follow logs with grep hello!" do + assert_equal \ + "ssh -t root@1.1.1.1 'docker logs traefik -t -n 10 -f 2>&1 | grep \"hello!\"'", new_command.follow_logs(host: @config[:servers].first, grep: 'hello!') + end + private def new_command Mrsk::Commands::Traefik.new(Mrsk::Configuration.new(@config, version: "123"))