Skip to content

Commit 061b580

Browse files
committed
fix(agent): wrap LinkSetMaster error and extend VXLAN stub tests
1 parent 6dd225d commit 061b580

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

internal/agent/network/vxlan.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ func (m *LinuxNetManager) attachToBridge(link netlink.Link, bridgeName string) e
6868
if link.Attrs().MasterIndex == bridge.Attrs().Index {
6969
return nil
7070
}
71-
return netlink.LinkSetMaster(link, bridge)
71+
if err := netlink.LinkSetMaster(link, bridge); err != nil {
72+
return fmt.Errorf("attach %s to bridge %s: %w", link.Attrs().Name, bridgeName, err)
73+
}
74+
return nil
7275
}
7376

7477
// SyncFDB reconciles the local FDB (forwarding database) on the VXLAN interface

internal/agent/network/vxlan_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package network_test
22

33
import (
44
"context"
5+
"errors"
56
"testing"
67

78
"github.com/syscode-labs/imp/internal/agent/network"
@@ -78,3 +79,19 @@ func TestStubNetManager_EnsureVXLAN_recordsBridgeName(t *testing.T) {
7879
t.Errorf("expected bridgeName impbr-xyz, got %q", stub.EnsureVXLANBridgeCalls[0])
7980
}
8081
}
82+
83+
func TestStubNetManager_EnsureVXLAN_emptyBridgeName(t *testing.T) {
84+
stub := &network.StubNetManager{}
85+
_ = stub.EnsureVXLAN(context.Background(), 42, "impvx-abc", "10.0.0.1", "")
86+
if stub.EnsureVXLANBridgeCalls[0] != "" {
87+
t.Errorf("expected empty bridgeName recorded, got %q", stub.EnsureVXLANBridgeCalls[0])
88+
}
89+
}
90+
91+
func TestStubNetManager_EnsureVXLAN_propagatesError(t *testing.T) {
92+
stub := &network.StubNetManager{EnsureVXLANErr: errors.New("boom")}
93+
err := stub.EnsureVXLAN(context.Background(), 42, "impvx-abc", "10.0.0.1", "impbr-xyz")
94+
if err == nil || err.Error() != "boom" {
95+
t.Errorf("expected error 'boom', got %v", err)
96+
}
97+
}

0 commit comments

Comments
 (0)