Files
mstore/pkg/client/account_test.go
T
2026-02-12 14:51:16 +02:00

139 lines
2.9 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 client
import (
"context"
"fmt"
//"math/rand"
//"os"
//"path/filepath"
"sync"
"testing"
"time"
"mstore/app/server"
"github.com/stretchr/testify/require"
)
func TestAccountLife(t *testing.T) {
var srvport int64 = 10250
srvdir := t.TempDir()
srvaddr := fmt.Sprintf("foouser:foopass@127.0.0.1:%d", srvport)
srv, err := server.NewServer()
require.NoError(t, err)
{
err = srv.Configure()
require.NoError(t, err)
srv.SetDatadir(srvdir)
srv.SetLogdir(srvdir)
srv.SetRundir(srvdir)
srv.SetPort(srvport)
err = srv.Build()
require.NoError(t, err)
var svcWG sync.WaitGroup
errPipe := make(chan error, 5)
startFunc := func() {
err := srv.Service().Run()
errPipe <- err
svcWG.Done()
}
stopFunc := func() {
srv.Service().Stop()
svcWG.Wait()
err = <-errPipe
require.NoError(t, err)
}
defer stopFunc()
svcWG.Add(1)
go startFunc()
time.Sleep(1 * time.Second)
}
{
// ServiceHello
fmt.Printf("=== ServiceHello ===\n")
cli := NewClient()
ctx := context.Background()
helloRes, err := cli.ServiceHello(ctx, srvaddr+"/hello", 1*time.Second)
require.NoError(t, err)
require.True(t, helloRes)
}
username := "testuser"
password := "testpass"
var accountID string
{
// CreateAccount
fmt.Printf("=== CreateAccount ===\n")
cli := NewClient()
ctx := context.Background()
ctx, _ = context.WithTimeout(ctx, 1*time.Second)
accountID, err = cli.CreateAccount(ctx, srvaddr, username, password)
require.NoError(t, err)
}
{
// GetAccount
fmt.Printf("=== GetAccount ===\n")
cli := NewClient()
ctx := context.Background()
ctx, _ = context.WithTimeout(ctx, 1*time.Second)
_, err = cli.GetAccountByID(ctx, srvaddr, accountID)
require.NoError(t, err)
}
/*
{
// ListAccounts
fmt.Printf("=== ListAccounts ===\n")
cli := NewClient()
ctx := context.Background()
ctx, _ = context.WithTimeout(ctx, 1*time.Second)
files, err := cli.ListAccounts(ctx, srvaddr+"/")
require.NoError(t, err)
require.NotZero(t, len(files))
}
{
// DeleteAccount
fmt.Printf("=== DeleteAccount ===\n")
cli := NewClient()
ctx := context.Background()
ctx, _ = context.WithTimeout(ctx, 1*time.Second)
err = cli.DeleteAccount(ctx, srvaddr+"/foo.bin")
require.NoError(t, err)
}
{
// !AccountExists
fmt.Printf("=== AccountExists ===\n")
cli := NewClient()
ctx := context.Background()
ctx, _ = context.WithTimeout(ctx, 1*time.Second)
exists, _, err := cli.AccountInfo(ctx, srvaddr+"/foo.bin")
require.NoError(t, err)
require.False(t, exists)
}
*/
}