Skip to content

Commit

Permalink
lint, update test
Browse files Browse the repository at this point in the history
  • Loading branch information
nobleess authored and mircea-pavel-anton committed Jan 17, 2025
1 parent 650d8cb commit f8ce333
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
23 changes: 17 additions & 6 deletions internal/mikrotik/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ func TestNewMikrotikClient(t *testing.T) {
SkipTLSVerify: true,
}

client, err := NewMikrotikClient(config)
defaults := &MikrotikDefaults{}

client, err := NewMikrotikClient(config, defaults)
if err != nil {
t.Fatalf("Expected no error, got %v", err)
}
Expand Down Expand Up @@ -103,6 +105,7 @@ func TestGetSystemInfo(t *testing.T) {
testCases := []struct {
name string
config MikrotikConnectionConfig
defaults MikrotikDefaults
expectedError bool
}{
{
Expand All @@ -113,6 +116,7 @@ func TestGetSystemInfo(t *testing.T) {
Password: mockPassword,
SkipTLSVerify: true,
},
defaults: MikrotikDefaults{},
expectedError: false,
},
{
Expand All @@ -123,6 +127,7 @@ func TestGetSystemInfo(t *testing.T) {
Password: "wrongpass",
SkipTLSVerify: true,
},
defaults: MikrotikDefaults{},
expectedError: true,
},
{
Expand All @@ -133,6 +138,7 @@ func TestGetSystemInfo(t *testing.T) {
Password: mockPassword,
SkipTLSVerify: true,
},
defaults: MikrotikDefaults{},
expectedError: true,
},
{
Expand All @@ -143,6 +149,7 @@ func TestGetSystemInfo(t *testing.T) {
Password: "wrongpass",
SkipTLSVerify: true,
},
defaults: MikrotikDefaults{},
expectedError: true,
},
{
Expand All @@ -153,6 +160,7 @@ func TestGetSystemInfo(t *testing.T) {
Password: "",
SkipTLSVerify: true,
},
defaults: MikrotikDefaults{},
expectedError: true,
},
}
Expand All @@ -161,8 +169,9 @@ func TestGetSystemInfo(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
config := &tc.config
defaults := &tc.defaults

client, err := NewMikrotikClient(config)
client, err := NewMikrotikClient(config, defaults)
if err != nil {
t.Fatalf("Failed to create client: %v", err)
}
Expand Down Expand Up @@ -396,8 +405,8 @@ func TestCreateDNSRecord(t *testing.T) {
Password: mockPassword,
SkipTLSVerify: true,
}

client, err := NewMikrotikClient(config)
defaults := &MikrotikDefaults{}
client, err := NewMikrotikClient(config, defaults)
if err != nil {
t.Fatalf("Failed to create client: %v", err)
}
Expand Down Expand Up @@ -610,7 +619,8 @@ func TestDeleteDNSRecord(t *testing.T) {
Password: mockPassword,
SkipTLSVerify: true,
}
client, err := NewMikrotikClient(config)
defaults := &MikrotikDefaults{}
client, err := NewMikrotikClient(config, defaults)
if err != nil {
t.Fatalf("Failed to create client: %v", err)
}
Expand Down Expand Up @@ -724,7 +734,8 @@ func TestGetAllDNSRecords(t *testing.T) {
Password: mockPassword,
SkipTLSVerify: true,
}
client, err := NewMikrotikClient(config)
defaults := &MikrotikDefaults{}
client, err := NewMikrotikClient(config, defaults)
if err != nil {
t.Fatalf("Failed to create client: %v", err)
}
Expand Down
1 change: 1 addition & 0 deletions internal/mikrotik/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mikrotik
import (
"context"
"fmt"

log "github.com/sirupsen/logrus"
"sigs.k8s.io/external-dns/endpoint"
"sigs.k8s.io/external-dns/plan"
Expand Down
22 changes: 17 additions & 5 deletions internal/mikrotik/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,24 @@ func TestContains(t *testing.T) {
}
}

func TestCleanupChanges(t *testing.T) {
func TestChanges(t *testing.T) {
mikrotikProvider := &MikrotikProvider{
client: &MikrotikApiClient{
&MikrotikDefaults{},
nil,
nil,
},
}

tests := []struct {
name string
provider *MikrotikProvider
inputChanges *plan.Changes
expectedChanges *plan.Changes
}{
{
name: "Multiple matching records - all should be cleaned up",
name: "Multiple matching records - all should be cleaned up",
provider: mikrotikProvider,
inputChanges: &plan.Changes{
UpdateOld: []*endpoint.Endpoint{
{
Expand Down Expand Up @@ -381,7 +391,8 @@ func TestCleanupChanges(t *testing.T) {
expectedChanges: &plan.Changes{},
},
{
name: "Some matching, some different - only partial cleanup",
name: "Some matching, some different - only partial cleanup",
provider: mikrotikProvider,
inputChanges: &plan.Changes{
UpdateOld: []*endpoint.Endpoint{
{
Expand Down Expand Up @@ -444,7 +455,8 @@ func TestCleanupChanges(t *testing.T) {
},
},
{
name: "Different comments across multiple records - no cleanup",
name: "Different comments across multiple records - no cleanup",
provider: mikrotikProvider,
inputChanges: &plan.Changes{
UpdateOld: []*endpoint.Endpoint{
{
Expand Down Expand Up @@ -520,7 +532,7 @@ func TestCleanupChanges(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
outputChanges := cleanupChanges(tt.inputChanges)
outputChanges := tt.provider.changes(tt.inputChanges)

if len(outputChanges.UpdateOld) != len(tt.expectedChanges.UpdateOld) {
t.Errorf("Expected UpdateOld length %d, got %d", len(tt.expectedChanges.UpdateOld), len(outputChanges.UpdateOld))
Expand Down

0 comments on commit f8ce333

Please sign in to comment.