working commit

This commit is contained in:
2026-01-30 13:40:42 +02:00
parent 95aa086327
commit c4172ac1f8
5 changed files with 163 additions and 42 deletions
+24 -13
View File
@@ -44,7 +44,7 @@ func (srv *Server) Handler() *handler.Handler {
func (srv *Server) Configure() error {
var err error
srv.logg.Infof("Server configure")
srv.logg.Infof("Configuration server")
srv.conf = config.NewConfig()
if err != nil {
return err
@@ -54,6 +54,11 @@ func (srv *Server) Configure() error {
//srv.logg.Warningf("Error loading config file: %v", err)
//return err
}
err = srv.conf.ReadX509Cert()
if err != nil {
return err
}
err = srv.conf.ReadOptions()
if err != nil {
return err
@@ -83,7 +88,7 @@ func (srv *Server) Build() error {
}
}
// Database create
// Creating database
dbdir := srv.conf.Database.Basepath
srv.logg.Infof("Create database directory %s ", dbdir)
err = os.MkdirAll(dbdir, 0750)
@@ -104,19 +109,20 @@ func (srv *Server) Build() error {
}
srv.mdb = mdb
// Storage create
// Creating storage
srv.logg.Infof("Create storage directory")
datadir := srv.conf.Database.Basepath
err = os.MkdirAll(datadir, 0750)
if err != nil {
return err
}
srv.logg.Infof("Create storage")
srv.logg.Infof("Creating storage")
store := storage.NewStorage(datadir)
srv.stor = store
// Operator create
srv.logg.Infof("Create operator")
// Creating operator
srv.logg.Infof("Creating operator")
operatorParams := &operator.OperatorParams{
MainDB: srv.mdb,
Store: srv.stor,
@@ -125,8 +131,8 @@ func (srv *Server) Build() error {
if err != nil {
return err
}
// Handler create
srv.logg.Infof("Create handler")
// Creating handler
srv.logg.Infof("Creating handler")
handlerParams := &handler.HandlerParams{
Operator: srv.oper,
}
@@ -134,16 +140,20 @@ func (srv *Server) Build() error {
if err != nil {
return err
}
// Service create
// Creating service
serviceParams := &service.ServiceParams{
Handler: srv.hand,
Handler: srv.hand,
X509Cert: srv.conf.X509Cert,
X509Key: srv.conf.X509Key,
Address: srv.conf.Service.Address,
Portnum: srv.conf.Service.Port,
}
srv.logg.Infof("Create service")
srv.logg.Infof("Creating service")
srv.svc, err = service.NewService(serviceParams)
if err != nil {
return err
}
// Service build
// Building service
err = srv.svc.Build()
if err != nil {
return err
@@ -161,7 +171,6 @@ func (srv *Server) Run() error {
}
srv.logg.Infof("Server run as user %s", currUser.Username)
sigs := make(chan os.Signal, 1)
svcDone := make(chan error, 1)
// Service run
@@ -175,6 +184,8 @@ func (srv *Server) Run() error {
}
go startService(srv.svc, svcDone)
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
var signal os.Signal
+56
View File
@@ -0,0 +1,56 @@
package server
import (
"context"
"sync"
"testing"
"time"
"mstore/pkg/client"
"github.com/stretchr/testify/require"
)
func TestService(t *testing.T) {
srv, err := NewServer()
require.NoError(t, err)
{
err = srv.Configure()
require.NoError(t, err)
err = srv.Build()
require.NoError(t, err)
var svcWG sync.WaitGroup
errPipe := make(chan error, 5)
startFunc := func() {
err := srv.svc.Run()
errPipe <- err
svcWG.Done()
}
stopFunc := func() {
srv.svc.Stop()
svcWG.Wait()
err = <-errPipe
require.NoError(t, err)
}
defer stopFunc()
svcWG.Add(1)
go startFunc()
time.Sleep(1 * time.Second)
}
{
cli := client.NewClient()
ctx := context.Background()
ctx, _ = context.WithTimeout(ctx, 1*time.Second)
helloRes, err := cli.ServiceHello(ctx, "127.0.0.1:1025/hello")
require.NoError(t, err)
require.True(t, helloRes)
}
}