|
78 | 78 | expect(description.arbiters).to be_empty
|
79 | 79 | end
|
80 | 80 | end
|
| 81 | + |
| 82 | + context 'when the addresses are not lowercase' do |
| 83 | + |
| 84 | + let(:config) do |
| 85 | + replica.merge( |
| 86 | + { |
| 87 | + 'arbiters' => [ |
| 88 | + 'SERVER:27017' |
| 89 | + ], |
| 90 | + } |
| 91 | + ) |
| 92 | + end |
| 93 | + |
| 94 | + let(:description) do |
| 95 | + described_class.new(address, config) |
| 96 | + end |
| 97 | + |
| 98 | + it 'normalizes the addresses to lowercase' do |
| 99 | + expect(description.arbiters).to eq(['server:27017']) |
| 100 | + end |
| 101 | + end |
81 | 102 | end
|
82 | 103 |
|
83 | 104 | describe '#ghost?' do
|
|
143 | 164 | it 'returns all the hosts in the replica set' do
|
144 | 165 | expect(description.hosts).to eq([ '127.0.0.1:27018', '127.0.0.1:27019' ])
|
145 | 166 | end
|
| 167 | + |
| 168 | + context 'when the addresses are not lowercase' do |
| 169 | + |
| 170 | + let(:config) do |
| 171 | + replica.merge( |
| 172 | + { |
| 173 | + 'hosts' => [ |
| 174 | + 'SERVER:27017' |
| 175 | + ], |
| 176 | + } |
| 177 | + ) |
| 178 | + end |
| 179 | + |
| 180 | + let(:description) do |
| 181 | + described_class.new(address, config) |
| 182 | + end |
| 183 | + |
| 184 | + it 'normalizes the addresses to lowercase' do |
| 185 | + expect(description.hosts).to eq(['server:27017']) |
| 186 | + end |
| 187 | + end |
146 | 188 | end
|
147 | 189 |
|
148 | 190 | describe '#max_bson_object_size' do
|
|
334 | 376 | expect(description.passives).to be_empty
|
335 | 377 | end
|
336 | 378 | end
|
| 379 | + |
| 380 | + context 'when the addresses are not lowercase' do |
| 381 | + |
| 382 | + let(:config) do |
| 383 | + replica.merge( |
| 384 | + { |
| 385 | + 'passives' => [ |
| 386 | + 'SERVER:27017' |
| 387 | + ], |
| 388 | + } |
| 389 | + ) |
| 390 | + end |
| 391 | + |
| 392 | + let(:description) do |
| 393 | + described_class.new(address, config) |
| 394 | + end |
| 395 | + |
| 396 | + it 'normalizes the addresses to lowercase' do |
| 397 | + expect(description.passives).to eq(['server:27017']) |
| 398 | + end |
| 399 | + |
| 400 | + it 'normalizes the addresses to lowercase' do |
| 401 | + |
| 402 | + end |
| 403 | + end |
337 | 404 | end
|
338 | 405 |
|
339 | 406 | describe '#primary?' do
|
|
507 | 574 | end
|
508 | 575 | end
|
509 | 576 | end
|
| 577 | + |
| 578 | + describe '#is_server?' do |
| 579 | + |
| 580 | + let(:listeners) do |
| 581 | + Mongo::Event::Listeners.new |
| 582 | + end |
| 583 | + |
| 584 | + let(:server) do |
| 585 | + Mongo::Server.new(address, listeners) |
| 586 | + end |
| 587 | + |
| 588 | + let(:description) do |
| 589 | + described_class.new(address, {}) |
| 590 | + end |
| 591 | + |
| 592 | + context 'when the server address matches the description address' do |
| 593 | + |
| 594 | + it 'returns true' do |
| 595 | + expect(description.is_server?(server)).to be(true) |
| 596 | + end |
| 597 | + end |
| 598 | + |
| 599 | + context 'when the server address does not match the description address' do |
| 600 | + |
| 601 | + let(:other_address) do |
| 602 | + Mongo::Address.new('127.0.0.1:27020') |
| 603 | + end |
| 604 | + |
| 605 | + let(:server) do |
| 606 | + Mongo::Server.new(other_address, listeners) |
| 607 | + end |
| 608 | + |
| 609 | + it 'returns false' do |
| 610 | + expect(description.is_server?(server)).to be(false) |
| 611 | + end |
| 612 | + end |
| 613 | + end |
| 614 | + |
| 615 | + describe '#lists_server?' do |
| 616 | + |
| 617 | + let(:description) do |
| 618 | + described_class.new(address, replica) |
| 619 | + end |
| 620 | + |
| 621 | + let(:server_address) do |
| 622 | + Mongo::Address.new('127.0.0.1:27018') |
| 623 | + end |
| 624 | + |
| 625 | + let(:listeners) do |
| 626 | + Mongo::Event::Listeners.new |
| 627 | + end |
| 628 | + |
| 629 | + let(:server) do |
| 630 | + Mongo::Server.new(server_address, listeners) |
| 631 | + end |
| 632 | + |
| 633 | + context 'when the server is included in the description hosts list' do |
| 634 | + |
| 635 | + it 'returns true' do |
| 636 | + expect(description.lists_server?(server)).to be(true) |
| 637 | + end |
| 638 | + end |
| 639 | + |
| 640 | + context 'when the server is not included in the description hosts list' do |
| 641 | + |
| 642 | + let(:server_address) do |
| 643 | + Mongo::Address.new('127.0.0.1:27017') |
| 644 | + end |
| 645 | + |
| 646 | + it 'returns false' do |
| 647 | + expect(description.lists_server?(server)).to be(false) |
| 648 | + end |
| 649 | + end |
| 650 | + end |
| 651 | + |
| 652 | + describe '#replica_set_member?' do |
| 653 | + |
| 654 | + context 'when the description is from a mongos' do |
| 655 | + |
| 656 | + let(:config) do |
| 657 | + { 'msg' => 'isdbgrid', 'ismaster' => true } |
| 658 | + end |
| 659 | + |
| 660 | + let(:description) do |
| 661 | + described_class.new(address, config) |
| 662 | + end |
| 663 | + |
| 664 | + it 'returns false' do |
| 665 | + expect(description.replica_set_member?).to be(false) |
| 666 | + end |
| 667 | + end |
| 668 | + |
| 669 | + context 'when the description is from a standalone' do |
| 670 | + |
| 671 | + let(:description) do |
| 672 | + described_class.new(address, { 'ismaster' => true, 'ok' => 1 }) |
| 673 | + end |
| 674 | + |
| 675 | + it 'returns false' do |
| 676 | + expect(description.replica_set_member?).to be(false) |
| 677 | + end |
| 678 | + end |
| 679 | + |
| 680 | + context 'when the description is from a replica set member' do |
| 681 | + |
| 682 | + let(:description) do |
| 683 | + described_class.new(address, replica) |
| 684 | + end |
| 685 | + |
| 686 | + it 'returns true' do |
| 687 | + expect(description.replica_set_member?).to be(true) |
| 688 | + end |
| 689 | + end |
| 690 | + end |
| 691 | + |
| 692 | + describe '#==' do |
| 693 | + |
| 694 | + context 'when the classes do not match' do |
| 695 | + |
| 696 | + let(:description) do |
| 697 | + described_class.new(address, replica) |
| 698 | + end |
| 699 | + |
| 700 | + it 'returns false' do |
| 701 | + expect(description == Array.new).to be(false) |
| 702 | + end |
| 703 | + end |
| 704 | + |
| 705 | + context 'when the configs match' do |
| 706 | + |
| 707 | + let(:description) do |
| 708 | + described_class.new(address, replica) |
| 709 | + end |
| 710 | + |
| 711 | + let(:other) do |
| 712 | + described_class.new(address, replica) |
| 713 | + end |
| 714 | + |
| 715 | + it 'returns true' do |
| 716 | + expect(description == other).to be(true) |
| 717 | + end |
| 718 | + end |
| 719 | + |
| 720 | + context 'when the configs do not match' do |
| 721 | + |
| 722 | + let(:description) do |
| 723 | + described_class.new(address, replica) |
| 724 | + end |
| 725 | + |
| 726 | + let(:other) do |
| 727 | + described_class.new(address, { 'ismaster' => true, 'ok' => 1 }) |
| 728 | + end |
| 729 | + |
| 730 | + it 'returns false' do |
| 731 | + expect(description == other).to be(false) |
| 732 | + end |
| 733 | + end |
| 734 | + end |
510 | 735 | end
|
0 commit comments