'If a compression dictionary is passed to it, L{Name.encode} uses offset
information from it to encode its name with references to existing
labels in the stream instead of including another copy of them in the
output.  It also updates the compression dictionary with the location of
the name it writes to the stream.'

def test_encodeWithCompression(self):

    name = dns.Name('foo.example.com')
    compression = {'example.com': 23}
    previous = 'some    prefix    to    change    .tell()'
    stream = BytesIO()
    stream.write(previous)
    expected = (len(previous) + dns.Message.headerSize)
    name.encode(stream, compression)
    self.assertEqual('\x03foo\xc0\x17', stream.getvalue()[len(previous):])
    self.assertEqual({'example.com': 23, 'foo.example.com': expected}, compression)
