Documentation
¶
Overview ¶
Package libdnstest provides testing utilities for libdns provider implementations.
These tests create, modify, and delete DNS records with names like "test-append", "test-set", "test-delete", and "test-lifecycle" to validate provider behavior.
For real DNS provider implementations, use dedicated test zones since the tests will modify DNS records. The example provider uses in-memory storage and is completely safe.
Tests run sequentially (not in parallel) to avoid conflicts when testing real DNS providers that interact with external services.
Usage ¶
suite := libdnstest.NewTestSuite(yourProvider, "example.com.") suite.RunTests(t)
Provider Without ZoneLister ¶
If your provider doesn't implement ZoneLister, use WrapNoZoneLister:
provider := YourProvider{...}
wrappedProvider := libdnstest.WrapNoZoneLister(provider)
suite := libdnstest.NewTestSuite(wrappedProvider, "example.com.")
suite.RunTests(t)
Custom Record Construction ¶
Since libdns.Record is an interface, different providers may return their own implementations that cannot be constructed using the standard libdns types. The TestSuite.AppendRecordFunc field allows you to provide a custom function to create Record instances for AppendRecords tests:
suite := libdnstest.NewTestSuite(yourProvider, "example.com.")
suite.AppendRecordFunc = func(record libdns.Record) libdns.Record {
// Return your provider's specific Record implementation
return yourProvider.NewRecord(record.RR())
}
For Set and Delete operations, the tests automatically retrieve existing records from the provider to ensure compatibility with provider-specific Record implementations.
Index ¶
- Variables
- type Provider
- type RecordProvider
- type TestSuite
- func (ts *TestSuite) AttemptZoneCleanup() error
- func (ts *TestSuite) RunTests(t *testing.T)
- func (ts *TestSuite) TestAppendRecords(t *testing.T)
- func (ts *TestSuite) TestDeleteRecords(t *testing.T)
- func (ts *TestSuite) TestGetRecords(t *testing.T)
- func (ts *TestSuite) TestListZones(t *testing.T)
- func (ts *TestSuite) TestSetRecords(t *testing.T)
Constants ¶
This section is empty.
Variables ¶
var ErrNotImplemented = errors.New("not implemented")
ErrNotImplemented is the sentinel error returned when a method is not implemented used for skipping ZoneLister tests
Functions ¶
This section is empty.
Types ¶
type Provider ¶
type Provider interface {
RecordProvider
libdns.ZoneLister
}
Provider represents a libdns provider implementation for testing.
func WrapNoZoneLister ¶
func WrapNoZoneLister(provider RecordProvider) Provider
WrapNoZoneLister wraps a provider that doesn't implement ZoneLister, adding a stub implementation that returns "not implemented" error. This allows providers without zone listing capability to work with the test suite.
type RecordProvider ¶
type RecordProvider interface {
libdns.RecordGetter
libdns.RecordAppender
libdns.RecordSetter
libdns.RecordDeleter
}
RecordProvider represents a provider that implements the core record management interfaces, but not ZoneLister.
type TestSuite ¶
type TestSuite struct {
Timeout time.Duration
// AppendRecordFunc is an optional function to create Record instances for AppendRecords tests.
// if nil, the tests will use the default libdns record types.
// the function receives a Record and should return a Record implementation.
AppendRecordFunc func(record libdns.Record) libdns.Record
// SkipRRTypes is a map of DNS record types to skip during testing.
// keys should be DNS record type strings like "MX", "SRV", "CAA", "NS", "SVCB", "HTTPS".
// if a type is present in the map with a true value, tests for that record type will be skipped.
// example: SkipRRTypes: map[string]bool{"MX": true, "SRV": true}
// "A", "CNAME", "TXT" record types are essential and could not be skipped
SkipRRTypes map[string]bool
// ExpectEmptyZone when true, verifies that the zone only contains default records (SOA, NS)
// after all tests complete. The test will fail if any test record types (A, AAAA, CNAME, TXT,
// MX, SRV, CAA, SVCB, HTTPS) remain. This is useful to confirm complete cleanup in test zones.
ExpectEmptyZone bool
// contains filtered or unexported fields
}
TestSuite contains all the configuration needed to run e2e tests.
func NewTestSuite ¶
NewTestSuite creates a new test suite for a libdns provider.
func (*TestSuite) AttemptZoneCleanup ¶
AttemptZoneCleanup deletes records with names starting with "test-" from the zone. This method is useful for cleaning up after test runs or preparing for fresh tests. Deletes all record types that match the test name pattern.
func (*TestSuite) TestAppendRecords ¶
TestAppendRecords tests the RecordAppender interface.
func (*TestSuite) TestDeleteRecords ¶
TestDeleteRecords tests the RecordDeleter interface.
func (*TestSuite) TestGetRecords ¶
TestGetRecords tests the RecordGetter interface.
func (*TestSuite) TestListZones ¶
TestListZones tests the ZoneLister interface.
func (*TestSuite) TestSetRecords ¶
TestSetRecords tests the RecordSetter interface. Tests that SetRecords only affects records with matching (name, type) pairs and leaves other records untouched.