working commit

This commit is contained in:
2026-01-30 18:37:35 +02:00
parent c4172ac1f8
commit 57f9775280
2 changed files with 196 additions and 229 deletions
+21 -4
View File
@@ -1,16 +1,12 @@
package server package server
import ( import (
//"io/ioutil"
"os" "os"
"os/signal" "os/signal"
"os/user" "os/user"
//"os/user"
"path/filepath" "path/filepath"
"strconv" "strconv"
//"sync"
"syscall" "syscall"
//"time"
"mstore/app/config" "mstore/app/config"
"mstore/app/handler" "mstore/app/handler"
@@ -42,6 +38,27 @@ func (srv *Server) Handler() *handler.Handler {
return srv.hand return srv.hand
} }
func (srv *Server) Service() *service.Service {
return srv.svc
}
func (srv *Server) SetLogdir(dir string) {
srv.conf.Logpath = dir
}
func (srv *Server) SetRundir(dir string) {
srv.conf.Runpath = dir
}
func (srv *Server) SetDatadir(dir string) {
srv.conf.Database.Basepath = dir
srv.conf.Storage.Basepath = dir
}
func (srv *Server) SetPort(port int64) {
srv.conf.Service.Port = port
}
func (srv *Server) Configure() error { func (srv *Server) Configure() error {
var err error var err error
srv.logg.Infof("Configuration server") srv.logg.Infof("Configuration server")
+20 -70
View File
@@ -16,46 +16,27 @@ import (
"mstore/app/server" "mstore/app/server"
) )
func TestFileLife(t *testing.T) { func TestFileOperations(t *testing.T) {
var tester FileTester
tester.MakeServer(t)
tester.TestServiceHello(t)
tester.TestPutFile(t)
tester.TestFileExists(t)
tester.TestGetFile(t)
tester.TestDeleteFile(t)
tester.TestFileNotExists(t)
}
type FileTester struct {
srv *server.Server
}
func (tester *FileTester) MakeServer(t *testing.T) {
var err error var err error
fmt.Printf("=== MakeServer ===\n") fmt.Printf("=== MakeServer ===\n")
srv, err := server.NewServer() srv, err := server.NewServer()
require.NoError(t, err) require.NoError(t, err)
{
err = srv.Configure() err = srv.Configure()
require.NoError(t, err) require.NoError(t, err)
tmpdir := t.TempDir()
srv.SetDatadir(tmpdir)
srv.SetLogdir(tmpdir)
srv.SetRundir(tmpdir)
err = srv.Build() err = srv.Build()
require.NoError(t, err) require.NoError(t, err)
}
tester.srv = srv {
}
func (tester *FileTester) TestPutFile(t *testing.T) {
var err error
fmt.Printf("=== PutFile ===\n") fmt.Printf("=== PutFile ===\n")
srv := tester.srv
require.NotNil(t, srv)
reqPath := `/v3/api/file/foo/bare` reqPath := `/v3/api/file/foo/bare`
routePath := `/v3/api/file/{filepath}` routePath := `/v3/api/file/{filepath}`
@@ -90,16 +71,10 @@ func (tester *FileTester) TestPutFile(t *testing.T) {
bodyBytes, err := io.ReadAll(bodyReader) bodyBytes, err := io.ReadAll(bodyReader)
fmt.Printf("Response body: %s\n", string(bodyBytes)) fmt.Printf("Response body: %s\n", string(bodyBytes))
} }
{
func (tester *FileTester) TestFileExists(t *testing.T) {
var err error
fmt.Printf("=== FileExists ===\n") fmt.Printf("=== FileExists ===\n")
srv := tester.srv
require.NotNil(t, srv)
reqPath := `/v3/api/file/foo/bare` reqPath := `/v3/api/file/foo/bare`
routePath := `/v3/api/file/{filepath}` routePath := `/v3/api/file/{filepath}`
@@ -122,16 +97,9 @@ func (tester *FileTester) TestFileExists(t *testing.T) {
bodyBytes, err := io.ReadAll(bodyReader) bodyBytes, err := io.ReadAll(bodyReader)
fmt.Printf("Response body: %s\n", string(bodyBytes)) fmt.Printf("Response body: %s\n", string(bodyBytes))
} }
{
func (tester *FileTester) TestGetFile(t *testing.T) {
var err error
fmt.Printf("=== GetFile ===\n") fmt.Printf("=== GetFile ===\n")
srv := tester.srv
require.NotNil(t, srv)
reqPath := `/v3/api/file/foo/bare` reqPath := `/v3/api/file/foo/bare`
routePath := `/v3/api/file/{filepath}` routePath := `/v3/api/file/{filepath}`
@@ -154,16 +122,9 @@ func (tester *FileTester) TestGetFile(t *testing.T) {
bodyBytes, err := io.ReadAll(bodyReader) bodyBytes, err := io.ReadAll(bodyReader)
fmt.Printf("Response body: %s\n", string(bodyBytes)) fmt.Printf("Response body: %s\n", string(bodyBytes))
} }
{
func (tester *FileTester) TestDeleteFile(t *testing.T) {
var err error
fmt.Printf("=== DeleteFile ===\n") fmt.Printf("=== DeleteFile ===\n")
srv := tester.srv
require.NotNil(t, srv)
reqPath := `/v3/api/file/foo/bare` reqPath := `/v3/api/file/foo/bare`
routePath := `/v3/api/file/{filepath}` routePath := `/v3/api/file/{filepath}`
@@ -186,16 +147,11 @@ func (tester *FileTester) TestDeleteFile(t *testing.T) {
bodyBytes, err := io.ReadAll(bodyReader) bodyBytes, err := io.ReadAll(bodyReader)
fmt.Printf("Response body: %s\n", string(bodyBytes)) fmt.Printf("Response body: %s\n", string(bodyBytes))
} }
func (tester *FileTester) TestFileNotExists(t *testing.T) { {
var err error
fmt.Printf("=== FileNotExists ===\n") fmt.Printf("=== FileNotExists ===\n")
srv := tester.srv
require.NotNil(t, srv)
reqPath := `/v3/api/file/foo/bare` reqPath := `/v3/api/file/foo/bare`
routePath := `/v3/api/file/{filepath}` routePath := `/v3/api/file/{filepath}`
@@ -218,16 +174,9 @@ func (tester *FileTester) TestFileNotExists(t *testing.T) {
bodyBytes, err := io.ReadAll(bodyReader) bodyBytes, err := io.ReadAll(bodyReader)
fmt.Printf("Response body: %s\n", string(bodyBytes)) fmt.Printf("Response body: %s\n", string(bodyBytes))
} }
{
func (tester *FileTester) TestServiceHello(t *testing.T) {
var err error
fmt.Printf("=== ServiceHello ===\n") fmt.Printf("=== ServiceHello ===\n")
srv := tester.srv
require.NotNil(t, srv)
reqPath := "/service/hello" reqPath := "/service/hello"
routePath := "/service/hello" routePath := "/service/hello"
@@ -248,4 +197,5 @@ func (tester *FileTester) TestServiceHello(t *testing.T) {
bodyBytes, err := io.ReadAll(bodyReader) bodyBytes, err := io.ReadAll(bodyReader)
fmt.Printf("Response body: %s\n", string(bodyBytes)) fmt.Printf("Response body: %s\n", string(bodyBytes))
}
} }