65 lines
1.4 KiB
Go
65 lines
1.4 KiB
Go
/*
|
|
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
|
*
|
|
* This work is published and licensed under a Creative Commons
|
|
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
|
|
*
|
|
* Distribution of this work is permitted, but commercial use and
|
|
* modifications are strictly prohibited.
|
|
*/
|
|
package maindb
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"mstore/pkg/auxtool"
|
|
"mstore/pkg/descr"
|
|
"mstore/pkg/auxid"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestGrant(t *testing.T) {
|
|
var err error
|
|
|
|
dbDir := t.TempDir()
|
|
db := NewDatabase(dbDir)
|
|
|
|
err = db.OpenDatabase()
|
|
require.NoError(t, err)
|
|
|
|
err = db.InitDatabase()
|
|
require.NoError(t, err)
|
|
|
|
id := uuid.NewUUID()
|
|
accountID := uuid.NewUUID()
|
|
timenow := auxtool.TimeNow()
|
|
creator := uuid.NewUUID()
|
|
newGrant := &descr.Grant{
|
|
ID: id,
|
|
AccountID: accountID,
|
|
Right: "rigthFoo",
|
|
Pattern: `*`,
|
|
CreatedAt: timenow,
|
|
UpdatedAt: timenow,
|
|
CreatedBy: creator,
|
|
UpdatedBy: creator,
|
|
}
|
|
ctx, _ := context.WithTimeout(context.Background(), 1*time.Second)
|
|
|
|
err = db.InsertGrant(ctx, newGrant)
|
|
require.NoError(t, err)
|
|
|
|
files, err := db.ListGrantsByAccountID(ctx, accountID)
|
|
require.NoError(t, err)
|
|
require.Equal(t, len(files), 1)
|
|
require.Equal(t, files[0].ID, id)
|
|
require.Equal(t, files[0].AccountID, accountID)
|
|
require.Equal(t, files[0].CreatedBy, creator)
|
|
fmt.Println(files[0].CreatedBy)
|
|
|
|
}
|