fix group tests

Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
This commit is contained in:
bcmmbaga
2024-10-18 10:48:28 +03:00
parent a82b5ce80e
commit 97dbdd7940
3 changed files with 10 additions and 3 deletions

View File

@@ -13,6 +13,7 @@ import (
"time"
"github.com/golang-jwt/jwt"
"github.com/rs/xid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
@@ -1187,9 +1188,12 @@ func TestAccountManager_NetworkUpdates(t *testing.T) {
}
policy := Policy{
Enabled: true,
ID: xid.New().String(),
AccountID: account.Id,
Enabled: true,
Rules: []*PolicyRule{
{
ID: xid.New().String(),
Enabled: true,
Sources: []string{"group-id"},
Destinations: []string{"group-id"},
@@ -1294,7 +1298,7 @@ func TestAccountManager_NetworkUpdates(t *testing.T) {
// clean policy is pre requirement for delete group
_ = manager.DeletePolicy(context.Background(), account.Id, policy.ID, userID)
if err := manager.DeleteGroup(context.Background(), account.Id, "", group.ID); err != nil {
if err := manager.DeleteGroup(context.Background(), account.Id, userID, group.ID); err != nil {
t.Errorf("delete group: %v", err)
return
}

View File

@@ -254,7 +254,7 @@ func (am *DefaultAccountManager) DeleteGroup(ctx context.Context, accountID, use
return fmt.Errorf(errNetworkSerialIncrementFmt, err)
}
if err = transaction.DeleteGroup(ctx, LockingStrengthUpdate, groupID, accountID); err != nil {
if err = transaction.DeleteGroup(ctx, LockingStrengthUpdate, accountID, groupID); err != nil {
return fmt.Errorf("failed to delete group: %w", err)
}
return nil

View File

@@ -1245,6 +1245,9 @@ func (s *SqlStore) GetGroupByID(ctx context.Context, lockStrength LockingStrengt
result := s.db.WithContext(ctx).Clauses(clause.Locking{Strength: string(lockStrength)}).
First(&group, accountAndIDQueryCondition, accountID, groupID)
if err := result.Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, status.Errorf(status.NotFound, "group not found")
}
log.WithContext(ctx).Errorf("failed to get group from the store: %s", err)
return nil, status.Errorf(status.Internal, "failed to get group from store")
}