Skip to content

Commit

Permalink
improve structure
Browse files Browse the repository at this point in the history
  • Loading branch information
mircea-pavel-anton committed Oct 26, 2024
1 parent 70bece8 commit b710893
Showing 1 changed file with 133 additions and 68 deletions.
201 changes: 133 additions & 68 deletions internal/mikrotik/record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ func TestDNSRecordToExternalDNSEndpoint(t *testing.T) {
expected *endpoint.Endpoint
expectError bool
}{
// Basic Record Types
// ===============================================================
// A RECORD TEST CASES
// ===============================================================
{
name: "Valid A record",
record: &DNSRecord{
Expand All @@ -193,6 +195,43 @@ func TestDNSRecordToExternalDNSEndpoint(t *testing.T) {
},
expectError: false,
},
{
name: "Invalid A record (empty address)",
record: &DNSRecord{
Name: "invalid.example.com",
Type: "A",
Address: "",
TTL: "1h",
},
expected: nil,
expectError: true,
},
{
name: "Invalid A record (malformed address)",
record: &DNSRecord{
Name: "invalid.example.com",
Type: "A",
Address: "999.999.999.999",
TTL: "1h",
},
expected: nil,
expectError: true,
},
{
name: "Invalid A record (IPv6 address)",
record: &DNSRecord{
Name: "invalid.example.com",
Type: "A",
Address: "2001:db8::1",
TTL: "1h",
},
expected: nil,
expectError: true,
},

// ===============================================================
// AAAA RECORD TEST CASES
// ===============================================================
{
name: "Valid AAAA record",
record: &DNSRecord{
Expand All @@ -209,6 +248,43 @@ func TestDNSRecordToExternalDNSEndpoint(t *testing.T) {
},
expectError: false,
},
{
name: "Invalid AAAA record (empty address)",
record: &DNSRecord{
Name: "invalid.example.com",
Type: "AAAA",
Address: "",
TTL: "1h",
},
expected: nil,
expectError: true,
},
{
name: "Invalid AAAA record (IPv4 address)",
record: &DNSRecord{
Name: "invalid.example.com",
Type: "AAAA",
Address: "1.2.3.4",
TTL: "1h",
},
expected: nil,
expectError: true,
},
{
name: "Invalid AAAA record (malformed address)",
record: &DNSRecord{
Name: "invalid.example.com",
Type: "AAAA",
Address: "1200:0000:AB00:1234:0000:2552:7777:1313:3:31",
TTL: "1h",
},
expected: nil,
expectError: true,
},

// ===============================================================
// CNAME RECORD TEST CASES
// ===============================================================
{
name: "Valid CNAME record",
record: &DNSRecord{
Expand All @@ -225,6 +301,32 @@ func TestDNSRecordToExternalDNSEndpoint(t *testing.T) {
},
expectError: false,
},
{
name: "Invalid CNAME record (empty cname)",
record: &DNSRecord{
Name: "invalid.example.com",
Type: "CNAME",
CName: "",
TTL: "30m",
},
expected: nil,
expectError: true,
},
{
name: "Invalid CNAME record (malformed domain)",
record: &DNSRecord{
Name: "invalid.example.com",
Type: "CNAME",
CName: "sub......domain...here-",
TTL: "30m",
},
expected: nil,
expectError: true,
},

// ===============================================================
// TXT RECORD TEST CASES
// ===============================================================
{
name: "Valid TXT record",
record: &DNSRecord{
Expand All @@ -241,10 +343,23 @@ func TestDNSRecordToExternalDNSEndpoint(t *testing.T) {
},
expectError: false,
},
{
name: "Invalid TXT record (empty text)",
record: &DNSRecord{
Name: "invalid.example.com",
Type: "TXT",
Text: "",
TTL: "10m",
},
expected: nil,
expectError: true,
},

// Provider-specific stuff
// ===============================================================
// PROVIDER-SPECIFIC DATA TEST CASES
// ===============================================================
{
name: "Provider-specific properties",
name: "Valid Provider-specific properties",
record: &DNSRecord{
Name: "example.com",
Type: "TXT",
Expand All @@ -269,8 +384,11 @@ func TestDNSRecordToExternalDNSEndpoint(t *testing.T) {
},
expectError: false,
},
// TODO: invalid provider specific

// Edge Cases
// ===============================================================
// DEFAULT VALUES FOR UNSET FIELDS TEST CASES
// ===============================================================
{
name: "Empty Type (should default to 'A')",
record: &DNSRecord{
Expand Down Expand Up @@ -304,7 +422,9 @@ func TestDNSRecordToExternalDNSEndpoint(t *testing.T) {
expectError: false,
},

// Error Cases
// ===============================================================
// GENERIC ERROR CASES
// ===============================================================
{
name: "Invalid TTL in DNSRecord",
record: &DNSRecord{
Expand All @@ -317,77 +437,22 @@ func TestDNSRecordToExternalDNSEndpoint(t *testing.T) {
expectError: true,
},
{
name: "Unsupported record type",
record: &DNSRecord{
Name: "example.com",
Type: "FWD",
TTL: "1h",
},
expected: nil,
expectError: true,
},
{
name: "Invalid A record (empty address)",
record: &DNSRecord{
Name: "invalid.example.com",
Type: "A",
Address: "",
TTL: "1h",
},
expected: nil,
expectError: true,
},
{
name: "Invalid A record (malformed address)",
name: "Invalid TTL in DNSRecord",
record: &DNSRecord{
Name: "invalid.example.com",
Name: "example.com",
Type: "A",
Address: "2001:db8::1",
TTL: "1h",
},
expected: nil,
expectError: true,
},
{
name: "Invalid AAAA record (empty address)",
record: &DNSRecord{
Name: "invalid.example.com",
Type: "AAAA",
Address: "",
TTL: "1h",
},
expected: nil,
expectError: true,
},
{
name: "Invalid AAAA record (malformed address)",
record: &DNSRecord{
Name: "invalid.example.com",
Type: "AAAA",
Address: "1.2.3.4",
TTL: "1h",
},
expected: nil,
expectError: true,
},
{
name: "Invalid CNAME record (empty cname)",
record: &DNSRecord{
Name: "invalid.example.com",
Type: "CNAME",
CName: "",
TTL: "30m",
Address: "192.0.2.1",
TTL: "invalid",
},
expected: nil,
expectError: true,
},
{
name: "Invalid TXT record (empty text)",
name: "Unsupported record type",
record: &DNSRecord{
Name: "invalid.example.com",
Type: "TXT",
Text: "",
TTL: "10m",
Name: "example.com",
Type: "FWD",
TTL: "1h",
},
expected: nil,
expectError: true,
Expand Down

0 comments on commit b710893

Please sign in to comment.