From 9731e6c71d9ffbbcc55ea39d42889a2496812e2a Mon Sep 17 00:00:00 2001 From: bcmmbaga Date: Tue, 7 Jan 2025 11:42:01 +0300 Subject: [PATCH] fix tests Signed-off-by: bcmmbaga --- management/server/networks/routers/manager_test.go | 8 ++++---- .../server/networks/routers/types/router_test.go | 11 ++++++++++- management/server/route_test.go | 6 ++++++ management/server/store/sql_store_test.go | 2 +- management/server/types/account_test.go | 12 ++++++++++++ 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/management/server/networks/routers/manager_test.go b/management/server/networks/routers/manager_test.go index e650074cc17..47f5ad7e308 100644 --- a/management/server/networks/routers/manager_test.go +++ b/management/server/networks/routers/manager_test.go @@ -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) } @@ -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) } @@ -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) } @@ -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) } diff --git a/management/server/networks/routers/types/router_test.go b/management/server/networks/routers/types/router_test.go index 3335f7c895b..5801e3bfa05 100644 --- a/management/server/networks/routers/types/router_test.go +++ b/management/server/networks/routers/types/router_test.go @@ -11,6 +11,7 @@ func TestNewNetworkRouter(t *testing.T) { peerGroups []string masquerade bool metric int + enabled bool expectedError bool }{ // Valid cases @@ -22,6 +23,7 @@ func TestNewNetworkRouter(t *testing.T) { peerGroups: nil, masquerade: true, metric: 100, + enabled: true, expectedError: false, }, { @@ -32,6 +34,7 @@ func TestNewNetworkRouter(t *testing.T) { peerGroups: []string{"group-1", "group-2"}, masquerade: false, metric: 200, + enabled: false, expectedError: false, }, { @@ -42,6 +45,7 @@ func TestNewNetworkRouter(t *testing.T) { peerGroups: nil, masquerade: true, metric: 300, + enabled: true, expectedError: false, }, @@ -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") @@ -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) + } } }) } diff --git a/management/server/route_test.go b/management/server/route_test.go index 0a2ff6764bc..1c5c56f6069 100644 --- a/management/server/route_test.go +++ b/management/server/route_test.go @@ -2388,6 +2388,7 @@ func TestAccount_GetPeerNetworkResourceFirewallRules(t *testing.T) { PeerGroups: nil, Masquerade: false, Metric: 9999, + Enabled: true, }, { ID: "router2", @@ -2395,12 +2396,14 @@ func TestAccount_GetPeerNetworkResourceFirewallRules(t *testing.T) { PeerGroups: []string{"router1", "router2"}, Masquerade: false, Metric: 9999, + Enabled: true, }, { ID: "router3", NetworkID: "network3", Peer: "peerE", PeerGroups: []string{}, + Enabled: true, }, { ID: "router4", @@ -2408,6 +2411,7 @@ func TestAccount_GetPeerNetworkResourceFirewallRules(t *testing.T) { PeerGroups: []string{"router1"}, Masquerade: false, Metric: 9999, + Enabled: true, }, { ID: "router5", @@ -2415,6 +2419,7 @@ func TestAccount_GetPeerNetworkResourceFirewallRules(t *testing.T) { Peer: "peerL", Masquerade: false, Metric: 9999, + Enabled: true, }, { ID: "router6", @@ -2422,6 +2427,7 @@ func TestAccount_GetPeerNetworkResourceFirewallRules(t *testing.T) { Peer: "peerN", Masquerade: false, Metric: 9999, + Enabled: true, }, }, NetworkResources: []*resourceTypes.NetworkResource{ diff --git a/management/server/store/sql_store_test.go b/management/server/store/sql_store_test.go index a70ac61a1f9..5928b45baa7 100644 --- a/management/server/store/sql_store_test.go +++ b/management/server/store/sql_store_test.go @@ -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) diff --git a/management/server/types/account_test.go b/management/server/types/account_test.go index 389ab17f6c5..07bdd58a265 100644 --- a/management/server/types/account_test.go +++ b/management/server/types/account_test.go @@ -149,6 +149,7 @@ func setupTestAccount() *Account { PeerGroups: []string{}, Masquerade: false, Metric: 100, + Enabled: true, }, { ID: "router2ID", @@ -158,6 +159,7 @@ func setupTestAccount() *Account { PeerGroups: []string{}, Masquerade: false, Metric: 100, + Enabled: true, }, { ID: "router3ID", @@ -167,6 +169,7 @@ func setupTestAccount() *Account { PeerGroups: []string{}, Masquerade: false, Metric: 100, + Enabled: true, }, { ID: "router4ID", @@ -176,6 +179,7 @@ func setupTestAccount() *Account { PeerGroups: []string{"group1"}, Masquerade: false, Metric: 100, + Enabled: true, }, { ID: "router5ID", @@ -185,6 +189,7 @@ func setupTestAccount() *Account { PeerGroups: []string{"group2", "group3"}, Masquerade: false, Metric: 100, + Enabled: true, }, { ID: "router6ID", @@ -194,6 +199,7 @@ func setupTestAccount() *Account { PeerGroups: []string{"group4"}, Masquerade: false, Metric: 100, + Enabled: true, }, }, NetworkResources: []*resourceTypes.NetworkResource{ @@ -201,21 +207,25 @@ func setupTestAccount() *Account { 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{ @@ -476,6 +486,7 @@ func getBasicAccountsWithResource() *Account { PeerGroups: []string{}, Masquerade: false, Metric: 100, + Enabled: true, }, }, NetworkResources: []*resourceTypes.NetworkResource{ @@ -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{