working commit

This commit is contained in:
2026-02-01 21:03:43 +02:00
parent 9c18f62997
commit 18e2a61c8a
10 changed files with 410 additions and 111 deletions
+17 -12
View File
@@ -10,26 +10,29 @@ import (
"math/rand"
"net/http"
"net/http/httptest"
"path/filepath"
"testing"
"mstore/app/router"
"mstore/app/server"
)
func xxxTestFileOperations(t *testing.T) {
func TestFileOperations(t *testing.T) {
var err error
fmt.Printf("=== MakeServer ===\n")
srv, err := server.NewServer()
require.NoError(t, err)
filename := `bare.bin`
{
err = srv.Configure()
require.NoError(t, err)
tmpdir := t.TempDir()
srv.SetDatadir(tmpdir)
srv.SetLogdir(tmpdir)
srv.SetRundir(tmpdir)
//tmpdir := t.TempDir()
//srv.SetDatadir(tmpdir)
//srv.SetLogdir(tmpdir)
//srv.SetRundir(tmpdir)
err = srv.Build()
require.NoError(t, err)
@@ -37,7 +40,7 @@ func xxxTestFileOperations(t *testing.T) {
{
fmt.Printf("=== PutFile ===\n")
reqPath := `/v3/api/file/foo/bare`
reqPath := `/v3/api/file/` + filename
routePath := `/v3/api/file/{filepath}`
rout := router.NewRouter()
@@ -46,19 +49,20 @@ func xxxTestFileOperations(t *testing.T) {
rout.Put(routePath, hand.PutFile)
datasize := 16
datasize := 64
filedata := make([]byte, datasize)
_, err = rand.Read(filedata)
require.NoError(t, err)
filedata = []byte(hex.EncodeToString(filedata))
datasize *= 2
source := bytes.NewReader(filedata)
request, err := http.NewRequest("PUT", reqPath, source)
require.NoError(t, err)
request.Header.Set("Content-Length", fmt.Sprintf("%d", datasize))
request.Header.Set("Content-Size", fmt.Sprintf("%d", datasize))
request.Header.Set("Content-Type", "application/octet-stream")
recorder := httptest.NewRecorder()
@@ -75,7 +79,7 @@ func xxxTestFileOperations(t *testing.T) {
{
fmt.Printf("=== FileExists ===\n")
reqPath := `/v3/api/file/foo/bare`
reqPath := filepath.Join(`/v3/api/file`, filename)
routePath := `/v3/api/file/{filepath}`
rout := router.NewRouter()
@@ -100,7 +104,7 @@ func xxxTestFileOperations(t *testing.T) {
}
{
fmt.Printf("=== GetFile ===\n")
reqPath := `/v3/api/file/foo/bare`
reqPath := filepath.Join(`/v3/api/file`, filename)
routePath := `/v3/api/file/{filepath}`
rout := router.NewRouter()
@@ -123,9 +127,10 @@ func xxxTestFileOperations(t *testing.T) {
fmt.Printf("Response body: %s\n", string(bodyBytes))
}
return
{
fmt.Printf("=== DeleteFile ===\n")
reqPath := `/v3/api/file/foo/bare`
reqPath := filepath.Join(`/v3/api/file`, filename)
routePath := `/v3/api/file/{filepath}`
rout := router.NewRouter()
@@ -152,7 +157,7 @@ func xxxTestFileOperations(t *testing.T) {
{
fmt.Printf("=== FileNotExists ===\n")
reqPath := `/v3/api/file/foo/bare`
reqPath := filepath.Join(`/v3/api/file`, filename)
routePath := `/v3/api/file/{filepath}`
rout := router.NewRouter()
+8 -9
View File
@@ -9,14 +9,13 @@ import (
"testing"
"time"
"mstore/pkg/client"
"mstore/app/server"
"mstore/pkg/client"
"github.com/stretchr/testify/require"
)
func TestService(t *testing.T) {
func xxxTestService(t *testing.T) {
var srvport int64 = 10250
srvdir := t.TempDir()
srvaddr := fmt.Sprintf("127.0.0.1:%d", srvport)
@@ -74,13 +73,13 @@ func TestService(t *testing.T) {
err := os.WriteFile(tmpfile, filedata, 0666)
require.NoError(t, err)
//fmt.Printf("=== PutFile ===\n")
//cli := client.NewClient()
//ctx := context.Background()
//ctx, _ = context.WithTimeout(ctx, 1*time.Second)
fmt.Printf("=== PutFile ===\n")
cli := client.NewClient()
ctx := context.Background()
ctx, _ = context.WithTimeout(ctx, 1*time.Second)
//err = cli.PutFile(ctx, tmpfile, srvaddr+"/foo.bin")
//require.NoError(t, err)
err = cli.PutFile(ctx, tmpfile, srvaddr+"/foo.bin")
require.NoError(t, err)
}
}