working commit

This commit is contained in:
2026-02-07 14:10:54 +02:00
parent 90905ace89
commit cd274d614a
12 changed files with 124 additions and 276 deletions
+40 -29
View File
@@ -20,6 +20,7 @@ import (
"net/http"
"net/http/httptest"
"path/filepath"
"strconv"
"testing"
"mstore/app/router"
@@ -32,21 +33,54 @@ func TestFileOperations(t *testing.T) {
srv, err := server.NewServer()
require.NoError(t, err)
var srvport int64 = 10240 + rand.Int63n(1024)
srvdir := t.TempDir()
//srvaddr := fmt.Sprintf("127.0.0.1:%d", srvport)
filename := `bare.bin?abc=12`
{
err = srv.Configure()
require.NoError(t, err)
//tmpdir := t.TempDir()
//srv.SetDatadir(tmpdir)
//srv.SetLogdir(tmpdir)
//srv.SetRundir(tmpdir)
err = srv.Configure()
require.NoError(t, err)
var tmpdir bool
tmpdir = true
if tmpdir {
srv.SetDatadir(srvdir)
srv.SetLogdir(srvdir)
srv.SetRundir(srvdir)
}
srv.SetPort(srvport)
err = srv.Build()
require.NoError(t, err)
}
{
fmt.Printf("=== ServiceHello ===\n")
reqPath := "/service/hello"
routePath := "/service/hello"
rout := router.NewRouter()
hand := srv.Handler()
rout.Get(routePath, hand.SendHello)
request, err := http.NewRequest("GET", reqPath, nil)
require.NoError(t, err)
recorder := httptest.NewRecorder()
rout.ServeHTTP(recorder, request)
require.Equal(t, http.StatusOK, recorder.Code)
fmt.Printf("Response code: %d\n", recorder.Code)
bodyReader := recorder.Body
bodyBytes, err := io.ReadAll(bodyReader)
fmt.Printf("Response body: %s\n", string(bodyBytes))
}
//return
{
fmt.Printf("=== PutFile ===\n")
reqPath := `/v3/api/file/` + filename
@@ -71,8 +105,9 @@ func TestFileOperations(t *testing.T) {
request, err := http.NewRequest("PUT", reqPath, source)
require.NoError(t, err)
request.Header.Set("Content-Size", fmt.Sprintf("%d", datasize))
request.ContentLength = int64(datasize)
request.Header.Set("Content-Type", "application/octet-stream")
request.Header.Set("Content-Size", strconv.FormatInt(int64(datasize), 10))
recorder := httptest.NewRecorder()
rout.ServeHTTP(recorder, request)
@@ -136,7 +171,6 @@ func TestFileOperations(t *testing.T) {
fmt.Printf("Response body: %s\n", string(bodyBytes))
}
return
{
fmt.Printf("=== DeleteFile ===\n")
reqPath := filepath.Join(`/v3/api/file`, filename)
@@ -187,29 +221,6 @@ func TestFileOperations(t *testing.T) {
bodyReader := recorder.Body
bodyBytes, err := io.ReadAll(bodyReader)
fmt.Printf("Response body: %s\n", string(bodyBytes))
}
{
fmt.Printf("=== ServiceHello ===\n")
reqPath := "/service/hello"
routePath := "/service/hello"
rout := router.NewRouter()
hand := srv.Handler()
rout.Get(routePath, hand.SendHello)
request, err := http.NewRequest("GET", reqPath, nil)
require.NoError(t, err)
recorder := httptest.NewRecorder()
rout.ServeHTTP(recorder, request)
require.Equal(t, http.StatusOK, recorder.Code)
fmt.Printf("Response code: %d\n", recorder.Code)
bodyReader := recorder.Body
bodyBytes, err := io.ReadAll(bodyReader)
fmt.Printf("Response body: %s\n", string(bodyBytes))
}
}