Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pascal-fischer committed Dec 17, 2024
1 parent 22cbbf8 commit 40ab041
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 37 deletions.
27 changes: 27 additions & 0 deletions management/server/groups/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ type managerImpl struct {
permissionsManager permissions.Manager
}

type mockManager struct {
}

func NewManager(store store.Store, permissionsManager permissions.Manager) Manager {
return &managerImpl{
store: store,
Expand Down Expand Up @@ -112,3 +115,27 @@ func ToGroupsInfo(groups map[string]*types.Group, id string) []api.GroupMinimum
}
return groupsInfo
}

func (m *mockManager) GetAllGroups(ctx context.Context, accountID, userID string) (map[string]*types.Group, error) {
return nil, nil

Check failure on line 120 in management/server/groups/manager.go

View workflow job for this annotation

GitHub Actions / lint (macos-latest)

return both a `nil` error and an invalid value: use a sentinel error instead (nilnil)

Check failure on line 120 in management/server/groups/manager.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

return both a `nil` error and an invalid value: use a sentinel error instead (nilnil)
}

func (m *mockManager) GetResourceGroupsInTransaction(ctx context.Context, transaction store.Store, lockingStrength store.LockingStrength, accountID, resourceID string) ([]*types.Group, error) {
return nil, nil
}

func (m *mockManager) AddResourceToGroup(ctx context.Context, accountID, userID, groupID string, resourceID *types.Resource) error {
return nil
}

func (m *mockManager) AddResourceToGroupInTransaction(ctx context.Context, transaction store.Store, accountID, groupID string, resourceID *types.Resource) error {
return nil
}

func (m *mockManager) RemoveResourceFromGroupInTransaction(ctx context.Context, transaction store.Store, accountID, groupID, resourceID string) error {
return nil
}

func NewManagerMock() Manager {
return &mockManager{}
}
31 changes: 21 additions & 10 deletions management/server/networks/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/netbirdio/netbird/management/server/groups"
"github.com/netbirdio/netbird/management/server/mock_server"
"github.com/netbirdio/netbird/management/server/networks/resources"
"github.com/netbirdio/netbird/management/server/networks/types"
Expand All @@ -25,7 +26,8 @@ func Test_GetAllNetworksReturnsNetworks(t *testing.T) {
t.Cleanup(cleanUp)
am := mock_server.MockAccountManager{}
permissionsManager := permissions.NewManagerMock()
resourcesManager := resources.NewManager(s, permissionsManager, &am)
groupsManager := groups.NewManagerMock()
resourcesManager := resources.NewManager(s, permissionsManager, groupsManager, &am)
manager := NewManager(s, permissionsManager, resourcesManager)

networks, err := manager.GetAllNetworks(ctx, accountID, userID)
Expand All @@ -46,7 +48,8 @@ func Test_GetAllNetworksReturnsPermissionDenied(t *testing.T) {
t.Cleanup(cleanUp)
am := mock_server.MockAccountManager{}
permissionsManager := permissions.NewManagerMock()
resourcesManager := resources.NewManager(s, permissionsManager, &am)
groupsManager := groups.NewManagerMock()
resourcesManager := resources.NewManager(s, permissionsManager, groupsManager, &am)
manager := NewManager(s, permissionsManager, resourcesManager)

networks, err := manager.GetAllNetworks(ctx, accountID, userID)
Expand All @@ -67,7 +70,8 @@ func Test_GetNetworkReturnsNetwork(t *testing.T) {
t.Cleanup(cleanUp)
am := mock_server.MockAccountManager{}
permissionsManager := permissions.NewManagerMock()
resourcesManager := resources.NewManager(s, permissionsManager, &am)
groupsManager := groups.NewManagerMock()
resourcesManager := resources.NewManager(s, permissionsManager, groupsManager, &am)
manager := NewManager(s, permissionsManager, resourcesManager)

networks, err := manager.GetNetwork(ctx, accountID, userID, networkID)
Expand All @@ -88,7 +92,8 @@ func Test_GetNetworkReturnsPermissionDenied(t *testing.T) {
t.Cleanup(cleanUp)
am := mock_server.MockAccountManager{}
permissionsManager := permissions.NewManagerMock()
resourcesManager := resources.NewManager(s, permissionsManager, &am)
groupsManager := groups.NewManagerMock()
resourcesManager := resources.NewManager(s, permissionsManager, groupsManager, &am)
manager := NewManager(s, permissionsManager, resourcesManager)

network, err := manager.GetNetwork(ctx, accountID, userID, networkID)
Expand All @@ -111,7 +116,8 @@ func Test_CreateNetworkSuccessfully(t *testing.T) {
t.Cleanup(cleanUp)
am := mock_server.MockAccountManager{}
permissionsManager := permissions.NewManagerMock()
resourcesManager := resources.NewManager(s, permissionsManager, &am)
groupsManager := groups.NewManagerMock()
resourcesManager := resources.NewManager(s, permissionsManager, groupsManager, &am)
manager := NewManager(s, permissionsManager, resourcesManager)

createdNetwork, err := manager.CreateNetwork(ctx, userID, network)
Expand All @@ -134,7 +140,8 @@ func Test_CreateNetworkFailsWithPermissionDenied(t *testing.T) {
t.Cleanup(cleanUp)
am := mock_server.MockAccountManager{}
permissionsManager := permissions.NewManagerMock()
resourcesManager := resources.NewManager(s, permissionsManager, &am)
groupsManager := groups.NewManagerMock()
resourcesManager := resources.NewManager(s, permissionsManager, groupsManager, &am)
manager := NewManager(s, permissionsManager, resourcesManager)

createdNetwork, err := manager.CreateNetwork(ctx, userID, network)
Expand All @@ -155,7 +162,8 @@ func Test_DeleteNetworkSuccessfully(t *testing.T) {
t.Cleanup(cleanUp)
am := mock_server.MockAccountManager{}
permissionsManager := permissions.NewManagerMock()
resourcesManager := resources.NewManager(s, permissionsManager, &am)
groupsManager := groups.NewManagerMock()
resourcesManager := resources.NewManager(s, permissionsManager, groupsManager, &am)
manager := NewManager(s, permissionsManager, resourcesManager)

err = manager.DeleteNetwork(ctx, accountID, userID, networkID)
Expand All @@ -175,7 +183,8 @@ func Test_DeleteNetworkFailsWithPermissionDenied(t *testing.T) {
t.Cleanup(cleanUp)
am := mock_server.MockAccountManager{}
permissionsManager := permissions.NewManagerMock()
resourcesManager := resources.NewManager(s, permissionsManager, &am)
groupsManager := groups.NewManagerMock()
resourcesManager := resources.NewManager(s, permissionsManager, groupsManager, &am)
manager := NewManager(s, permissionsManager, resourcesManager)

err = manager.DeleteNetwork(ctx, accountID, userID, networkID)
Expand All @@ -198,7 +207,8 @@ func Test_UpdateNetworkSuccessfully(t *testing.T) {
t.Cleanup(cleanUp)
am := mock_server.MockAccountManager{}
permissionsManager := permissions.NewManagerMock()
resourcesManager := resources.NewManager(s, permissionsManager, &am)
groupsManager := groups.NewManagerMock()
resourcesManager := resources.NewManager(s, permissionsManager, groupsManager, &am)
manager := NewManager(s, permissionsManager, resourcesManager)

updatedNetwork, err := manager.UpdateNetwork(ctx, userID, network)
Expand All @@ -223,7 +233,8 @@ func Test_UpdateNetworkFailsWithPermissionDenied(t *testing.T) {

am := mock_server.MockAccountManager{}
permissionsManager := permissions.NewManagerMock()
resourcesManager := resources.NewManager(s, permissionsManager, &am)
groupsManager := groups.NewManagerMock()
resourcesManager := resources.NewManager(s, permissionsManager, groupsManager, &am)
manager := NewManager(s, permissionsManager, resourcesManager)

updatedNetwork, err := manager.UpdateNetwork(ctx, userID, network)
Expand Down
Loading

0 comments on commit 40ab041

Please sign in to comment.