Fix tests and examples.
Put all examples in the same file and cleanup the tests to use the new names.
This commit is contained in:
parent
11aaecf837
commit
b90da23741
|
@ -79,7 +79,7 @@ func (rd *APAIR) ParseTextSlice(txt []string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (rd *APAIR) WriteByteSlice(buf []byte) (int, error) {
|
||||
func (rd *APAIR) Pack(buf []byte) (int, error) {
|
||||
b := append([]byte(rd.addr[0]), []byte(rd.addr[1])...)
|
||||
n := copy(buf, b)
|
||||
if n != len(b) {
|
||||
|
@ -88,7 +88,7 @@ func (rd *APAIR) WriteByteSlice(buf []byte) (int, error) {
|
|||
return n, nil
|
||||
}
|
||||
|
||||
func (rd *APAIR) ParseByteSlice(buf []byte) (int, error) {
|
||||
func (rd *APAIR) Unpack(buf []byte) (int, error) {
|
||||
ln := net.IPv4len * 2
|
||||
if len(buf) != ln {
|
||||
return 0, errors.New("Invalid length of APAIR rdata")
|
||||
|
@ -104,7 +104,7 @@ func (rd *APAIR) ParseByteSlice(buf []byte) (int, error) {
|
|||
|
||||
func (rd *APAIR) PasteRdata(dest dns.PrivateRdata) error {
|
||||
cp := make([]byte, rd.RdataLen())
|
||||
_, err := rd.WriteByteSlice(cp)
|
||||
_, err := rd.Pack(cp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -120,8 +120,8 @@ func (rd *APAIR) RdataLen() int {
|
|||
}
|
||||
|
||||
func ExampleNewPrivateRR() {
|
||||
dns.NewPrivateRR("APAIR", TypeAPAIR, NewAPAIR)
|
||||
defer dns.DelPrivateRR(TypeAPAIR)
|
||||
dns.PrivateHandle("APAIR", TypeAPAIR, NewAPAIR)
|
||||
defer dns.PrivateHandleRemove(TypeAPAIR)
|
||||
|
||||
rr, err := dns.NewRR("miek.nl. APAIR (1.2.3.4 1.2.3.5)")
|
||||
if err != nil {
|
||||
|
|
|
@ -15,6 +15,7 @@ type PrivateRdata interface {
|
|||
// Pack is used when packing a private RR into a buffer.
|
||||
Pack([]byte) (int, error)
|
||||
// Unpack is used when unpacking a private RR from a buffer.
|
||||
// TODO(miek): diff. signature than Pack, see edns0.go for instance.
|
||||
Unpack([]byte) (int, error)
|
||||
PasteRdata(PrivateRdata) error
|
||||
// RdataLen returns the length in octets of the Rdata.
|
||||
|
|
|
@ -49,8 +49,8 @@ func (rd *ISBN) PasteRdata(dest dns.PrivateRdata) error {
|
|||
var testrecord = strings.Join([]string{"example.org.", "3600", "IN", "ISBN", "12-3 456789-0-123"}, "\t")
|
||||
|
||||
func TestPrivateText(t *testing.T) {
|
||||
dns.NewPrivateRR("ISBN", TypeISBN, NewISBN)
|
||||
defer dns.DelPrivateRR(TypeISBN)
|
||||
dns.PrivateHandle("ISBN", TypeISBN, NewISBN)
|
||||
defer dns.PrivateHandleRemove(TypeISBN)
|
||||
|
||||
rr, err := dns.NewRR(testrecord)
|
||||
if err != nil {
|
||||
|
@ -64,8 +64,8 @@ func TestPrivateText(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPrivateByteSlice(t *testing.T) {
|
||||
dns.NewPrivateRR("ISBN", TypeISBN, NewISBN)
|
||||
defer dns.DelPrivateRR(TypeISBN)
|
||||
dns.PrivateHandle("ISBN", TypeISBN, NewISBN)
|
||||
defer dns.PrivateHandleRemove(TypeISBN)
|
||||
|
||||
rr, err := dns.NewRR(testrecord)
|
||||
if err != nil {
|
||||
|
@ -113,7 +113,7 @@ func (rd *VERSION) ParseTextSlice(txt []string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (rd *VERSION) WriteByteSlice(buf []byte) (int, error) {
|
||||
func (rd *VERSION) Pack(buf []byte) (int, error) {
|
||||
b := []byte(rd.x)
|
||||
n := copy(buf, b)
|
||||
if n != len(b) {
|
||||
|
@ -122,7 +122,7 @@ func (rd *VERSION) WriteByteSlice(buf []byte) (int, error) {
|
|||
return n, nil
|
||||
}
|
||||
|
||||
func (rd *VERSION) ParseByteSlice(buf []byte) (int, error) {
|
||||
func (rd *VERSION) Unpack(buf []byte) (int, error) {
|
||||
rd.x = string(buf)
|
||||
return len(buf), nil
|
||||
}
|
||||
|
@ -154,10 +154,10 @@ www ISBN 1231-92110-16
|
|||
`
|
||||
|
||||
func TestPrivateZoneParser(t *testing.T) {
|
||||
dns.NewPrivateRR("ISBN", TypeISBN, NewISBN)
|
||||
dns.NewPrivateRR("VERSION", TypeVERSION, NewVersion)
|
||||
defer dns.DelPrivateRR(TypeISBN)
|
||||
defer dns.DelPrivateRR(TypeVERSION)
|
||||
dns.PrivateHandle("ISBN", TypeISBN, NewISBN)
|
||||
dns.PrivateHandle("VERSION", TypeVERSION, NewVersion)
|
||||
defer dns.PrivateHandleRemove(TypeISBN)
|
||||
defer dns.PrivateHandleRemove(TypeVERSION)
|
||||
|
||||
r := strings.NewReader(smallzone)
|
||||
for x := range dns.ParseZone(r, ".", "") {
|
||||
|
|
Loading…
Reference in New Issue