Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: bcmmbaga <[email protected]>
  • Loading branch information
bcmmbaga committed Jan 7, 2025
1 parent 063784c commit 9731e6c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
8 changes: 4 additions & 4 deletions management/server/networks/routers/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func Test_GetRouterReturnsPermissionDenied(t *testing.T) {
func Test_CreateRouterSuccessfully(t *testing.T) {
ctx := context.Background()
userID := "allowedUser"
router, err := types.NewNetworkRouter("testAccountId", "testNetworkId", "testPeerId", []string{}, false, 9999)
router, err := types.NewNetworkRouter("testAccountId", "testNetworkId", "testPeerId", []string{}, false, 9999, true)
if err != nil {
require.NoError(t, err)
}
Expand All @@ -127,7 +127,7 @@ func Test_CreateRouterSuccessfully(t *testing.T) {
func Test_CreateRouterFailsWithPermissionDenied(t *testing.T) {
ctx := context.Background()
userID := "invalidUser"
router, err := types.NewNetworkRouter("testAccountId", "testNetworkId", "testPeerId", []string{}, false, 9999)
router, err := types.NewNetworkRouter("testAccountId", "testNetworkId", "testPeerId", []string{}, false, 9999, true)
if err != nil {
require.NoError(t, err)
}
Expand Down Expand Up @@ -191,7 +191,7 @@ func Test_DeleteRouterFailsWithPermissionDenied(t *testing.T) {
func Test_UpdateRouterSuccessfully(t *testing.T) {
ctx := context.Background()
userID := "allowedUser"
router, err := types.NewNetworkRouter("testAccountId", "testNetworkId", "testPeerId", []string{}, false, 1)
router, err := types.NewNetworkRouter("testAccountId", "testNetworkId", "testPeerId", []string{}, false, 1, true)
if err != nil {
require.NoError(t, err)
}
Expand All @@ -213,7 +213,7 @@ func Test_UpdateRouterSuccessfully(t *testing.T) {
func Test_UpdateRouterFailsWithPermissionDenied(t *testing.T) {
ctx := context.Background()
userID := "invalidUser"
router, err := types.NewNetworkRouter("testAccountId", "testNetworkId", "testPeerId", []string{}, false, 1)
router, err := types.NewNetworkRouter("testAccountId", "testNetworkId", "testPeerId", []string{}, false, 1, true)
if err != nil {
require.NoError(t, err)
}
Expand Down
11 changes: 10 additions & 1 deletion management/server/networks/routers/types/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func TestNewNetworkRouter(t *testing.T) {
peerGroups []string
masquerade bool
metric int
enabled bool
expectedError bool
}{
// Valid cases
Expand All @@ -22,6 +23,7 @@ func TestNewNetworkRouter(t *testing.T) {
peerGroups: nil,
masquerade: true,
metric: 100,
enabled: true,
expectedError: false,
},
{
Expand All @@ -32,6 +34,7 @@ func TestNewNetworkRouter(t *testing.T) {
peerGroups: []string{"group-1", "group-2"},
masquerade: false,
metric: 200,
enabled: false,
expectedError: false,
},
{
Expand All @@ -42,6 +45,7 @@ func TestNewNetworkRouter(t *testing.T) {
peerGroups: nil,
masquerade: true,
metric: 300,
enabled: true,
expectedError: false,
},

Expand All @@ -54,13 +58,14 @@ func TestNewNetworkRouter(t *testing.T) {
peerGroups: []string{"group-3"},
masquerade: false,
metric: 400,
enabled: false,
expectedError: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
router, err := NewNetworkRouter(tt.accountID, tt.networkID, tt.peer, tt.peerGroups, tt.masquerade, tt.metric)
router, err := NewNetworkRouter(tt.accountID, tt.networkID, tt.peer, tt.peerGroups, tt.masquerade, tt.metric, tt.enabled)

if tt.expectedError && err == nil {
t.Fatalf("Expected an error, got nil")
Expand Down Expand Up @@ -94,6 +99,10 @@ func TestNewNetworkRouter(t *testing.T) {
if router.Metric != tt.metric {
t.Errorf("Expected Metric %d, got %d", tt.metric, router.Metric)
}

if router.Enabled != tt.enabled {
t.Errorf("Expected Enabled %v, got %v", tt.enabled, router.Enabled)
}
}
})
}
Expand Down
6 changes: 6 additions & 0 deletions management/server/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2388,40 +2388,46 @@ func TestAccount_GetPeerNetworkResourceFirewallRules(t *testing.T) {
PeerGroups: nil,
Masquerade: false,
Metric: 9999,
Enabled: true,
},
{
ID: "router2",
NetworkID: "network2",
PeerGroups: []string{"router1", "router2"},
Masquerade: false,
Metric: 9999,
Enabled: true,
},
{
ID: "router3",
NetworkID: "network3",
Peer: "peerE",
PeerGroups: []string{},
Enabled: true,
},
{
ID: "router4",
NetworkID: "network4",
PeerGroups: []string{"router1"},
Masquerade: false,
Metric: 9999,
Enabled: true,
},
{
ID: "router5",
NetworkID: "network5",
Peer: "peerL",
Masquerade: false,
Metric: 9999,
Enabled: true,
},
{
ID: "router6",
NetworkID: "network6",
Peer: "peerN",
Masquerade: false,
Metric: 9999,
Enabled: true,
},
},
NetworkResources: []*resourceTypes.NetworkResource{
Expand Down
2 changes: 1 addition & 1 deletion management/server/store/sql_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2377,7 +2377,7 @@ func TestSqlStore_SaveNetworkRouter(t *testing.T) {
accountID := "bf1c8084-ba50-4ce7-9439-34653001fc3b"
networkID := "ct286bi7qv930dsrrug0"

netRouter, err := routerTypes.NewNetworkRouter(accountID, networkID, "", []string{"net-router-grp"}, true, 0)
netRouter, err := routerTypes.NewNetworkRouter(accountID, networkID, "", []string{"net-router-grp"}, true, 0, true)
require.NoError(t, err)

err = store.SaveNetworkRouter(context.Background(), LockingStrengthUpdate, netRouter)
Expand Down
12 changes: 12 additions & 0 deletions management/server/types/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func setupTestAccount() *Account {
PeerGroups: []string{},
Masquerade: false,
Metric: 100,
Enabled: true,
},
{
ID: "router2ID",
Expand All @@ -158,6 +159,7 @@ func setupTestAccount() *Account {
PeerGroups: []string{},
Masquerade: false,
Metric: 100,
Enabled: true,
},
{
ID: "router3ID",
Expand All @@ -167,6 +169,7 @@ func setupTestAccount() *Account {
PeerGroups: []string{},
Masquerade: false,
Metric: 100,
Enabled: true,
},
{
ID: "router4ID",
Expand All @@ -176,6 +179,7 @@ func setupTestAccount() *Account {
PeerGroups: []string{"group1"},
Masquerade: false,
Metric: 100,
Enabled: true,
},
{
ID: "router5ID",
Expand All @@ -185,6 +189,7 @@ func setupTestAccount() *Account {
PeerGroups: []string{"group2", "group3"},
Masquerade: false,
Metric: 100,
Enabled: true,
},
{
ID: "router6ID",
Expand All @@ -194,28 +199,33 @@ func setupTestAccount() *Account {
PeerGroups: []string{"group4"},
Masquerade: false,
Metric: 100,
Enabled: true,
},
},
NetworkResources: []*resourceTypes.NetworkResource{
{
ID: "resource1ID",
AccountID: "accountID",
NetworkID: "network1ID",
Enabled: true,
},
{
ID: "resource2ID",
AccountID: "accountID",
NetworkID: "network2ID",
Enabled: true,
},
{
ID: "resource3ID",
AccountID: "accountID",
NetworkID: "network1ID",
Enabled: true,
},
{
ID: "resource4ID",
AccountID: "accountID",
NetworkID: "network1ID",
Enabled: true,
},
},
Policies: []*Policy{
Expand Down Expand Up @@ -476,6 +486,7 @@ func getBasicAccountsWithResource() *Account {
PeerGroups: []string{},
Masquerade: false,
Metric: 100,
Enabled: true,
},
},
NetworkResources: []*resourceTypes.NetworkResource{
Expand All @@ -486,6 +497,7 @@ func getBasicAccountsWithResource() *Account {
Address: "10.10.10.0/24",
Prefix: netip.MustParsePrefix("10.10.10.0/24"),
Type: resourceTypes.NetworkResourceType("subnet"),
Enabled: true,
},
},
Policies: []*Policy{
Expand Down

0 comments on commit 9731e6c

Please sign in to comment.