Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 76 lines (63 sloc) 2.851 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
require 'spec_helper'

module RedisFailover
  describe CLI do
    describe '.parse' do
      it 'properly parses redis nodes' do
        opts = CLI.parse(['-n host1:1,host2:2,host3:3', '-z localhost:1111'])
        opts[:nodes].should == [
          {:host => 'host1', :port => '1'},
          {:host => 'host2', :port => '2'},
          {:host => 'host3', :port => '3'}
        ]
      end

      it 'properly parses ZooKeeper servers' do
        opts = CLI.parse(['-n host1:1,host2:2,host3:3', '-z localhost:1111'])
        opts[:zkservers].should == 'localhost:1111'
      end

      it 'properly parses a redis password' do
        opts = CLI.parse(['-n host:port', '-z localhost:1111', '-p redis_pass'])
        opts[:nodes].should == [{
          :host => 'host',
          :port => 'port',
          :password => 'redis_pass'
        }]
      end

      it 'properly parses max node failures' do
        opts = CLI.parse([
          '-n host:port',
          '-z localhost:1111',
          '-p redis_pass',
          '--max-failures',
          '1'])
        opts[:max_failures].should == 1
      end

      it 'properly parses a chroot' do
        opts = CLI.parse(['-n host:port', '-z localhost:1111', '--with-chroot', '/with/chroot/from/command/line'])
        opts[:nodes].should == [{
          :host => 'host',
          :port => 'port',
        }]

        opts[:chroot].should == '/with/chroot/from/command/line'
      end

      it 'properly parses the config file' do
        opts = CLI.parse(['-C', "#{File.dirname(__FILE__)}/support/config/single_environment.yml"])
        opts[:zkservers].should == 'zk01:2181,zk02:2181,zk03:2181'

        opts = CLI.parse(['-C', "#{File.dirname(__FILE__)}/support/config/multiple_environments.yml", '-E', 'development'])
        opts[:zkservers].should == 'localhost:2181'

        opts = CLI.parse(['-C', "#{File.dirname(__FILE__)}/support/config/multiple_environments.yml", '-E', 'staging'])
        opts[:zkservers].should == 'zk01:2181,zk02:2181,zk03:2181'
      end

      it 'properly parses the config file that include chroot' do
        opts = CLI.parse(['-C', "#{File.dirname(__FILE__)}/support/config/single_environment_with_chroot.yml"])
        opts[:zkservers].should == 'zk01:2181,zk02:2181,zk03:2181'
        opts[:chroot].should == '/with/chroot'

        opts = CLI.parse(['-C', "#{File.dirname(__FILE__)}/support/config/multiple_environments_with_chroot.yml", '-E', 'development'])
        opts[:zkservers].should == 'localhost:2181'
        opts[:chroot].should == '/with/chroot_development'

        opts = CLI.parse(['-C', "#{File.dirname(__FILE__)}/support/config/multiple_environments_with_chroot.yml", '-E', 'staging'])
        opts[:zkservers].should == 'zk01:2181,zk02:2181,zk03:2181'
        opts[:chroot].should == '/with/chroot_staging'
      end
    end
  end
end
Something went wrong with that request. Please try again.