# Path: lighthouse/haproxy/stanzas/peers.py
# class PeersStanza(Stanza):
#     """
#     Stanza subclass representing a "peers" stanza.
# 
#     This stanza lists "peer" haproxy instances in a cluster, so that each
#     instance can coordinate and share stick-table information.  Useful for
#     tracking cluster-wide stats.
#     """
# 
#     def __init__(self, cluster):
#         super(PeersStanza, self).__init__("peers")
#         self.header = "peers " + cluster.name
# 
#         self.add_lines([
#             "peer %s %s:%s" % (peer.name, peer.ip, peer.port)
#             for peer in set([node.peer for node in cluster.nodes if node.peer])
#         ])


    import unittest2 as unittest
    import unittest
from mock import Mock
from lighthouse.haproxy.stanzas.peers import PeersStanza
try:
except ImportError:




class PeersStanzaTests(unittest.TestCase):

    def test_peers(self):
        peer1 = Mock()
        peer1.name = "server1"
        peer1.ip = "192.168.0.13"
        peer1.port = "88"
        peer2 = Mock()
        peer2.name = "server2"
        peer2.ip = "192.168.0.22"
        peer2.port = "88"

        cluster = Mock()
        cluster.name = "a_cluster"
        cluster.nodes = [
            Mock(peer=peer1),
            Mock(peer=None),  # skipped
            Mock(peer=peer2),
            Mock(peer=peer1),  # duplicate, skipped
        ]


# Path: lighthouse/haproxy/stanzas/peers.py
# class PeersStanza(Stanza):
#     """
#     Stanza subclass representing a "peers" stanza.
# 
#     This stanza lists "peer" haproxy instances in a cluster, so that each
#     instance can coordinate and share stick-table information.  Useful for
#     tracking cluster-wide stats.
#     """
# 
#     def __init__(self, cluster):
#         super(PeersStanza, self).__init__("peers")
#         self.header = "peers " + cluster.name
# 
#         self.add_lines([
#             "peer %s %s:%s" % (peer.name, peer.ip, peer.port)
#             for peer in set([node.peer for node in cluster.nodes if node.peer])
#         ])


# Path: tests/haproxy/stanzas/peers_tests.py
    import unittest2 as unittest
    import unittest
from mock import Mock
from lighthouse.haproxy.stanzas.peers import PeersStanza

try:
except ImportError:




class PeersStanzaTests(unittest.TestCase):

    def test_peers(self):
        peer1 = Mock()
        peer1.name = "server1"
        peer1.ip = "192.168.0.13"
        peer1.port = "88"
        peer2 = Mock()
        peer2.name = "server2"
        peer2.ip = "192.168.0.22"
        peer2.port = "88"

        cluster = Mock()
        cluster.name = "a_cluster"
        cluster.nodes = [
            Mock(peer=peer1),
            Mock(peer=None),  # skipped
            Mock(peer=peer2),
            Mock(peer=peer1),  # duplicate, skipped
        ]


        stanza = PeersStanza(cluster)