working commit

This commit is contained in:
2026-01-30 19:13:59 +02:00
parent 57f9775280
commit d5a3c7e69b
+31 -3
View File
@@ -2,6 +2,9 @@ package server
import ( import (
"context" "context"
"fmt"
"os"
"path/filepath"
"sync" "sync"
"testing" "testing"
"time" "time"
@@ -12,12 +15,21 @@ import (
) )
func TestService(t *testing.T) { func TestService(t *testing.T) {
var srvport int64 = 10250
srvdir := t.TempDir()
srvaddr := fmt.Sprintf("127.0.0.1:%d", srvport)
srv, err := NewServer() srv, err := NewServer()
require.NoError(t, err) require.NoError(t, err)
{ {
err = srv.Configure() err = srv.Configure()
require.NoError(t, err) require.NoError(t, err)
srv.SetDatadir(srvdir)
srv.SetLogdir(srvdir)
srv.SetRundir(srvdir)
srv.SetPort(srvport)
err = srv.Build() err = srv.Build()
require.NoError(t, err) require.NoError(t, err)
@@ -42,15 +54,31 @@ func TestService(t *testing.T) {
go startFunc() go startFunc()
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
} }
{ {
fmt.Printf("=== ServiceHello ===\n")
cli := client.NewClient() cli := client.NewClient()
ctx := context.Background() ctx := context.Background()
ctx, _ = context.WithTimeout(ctx, 1*time.Second) ctx, _ = context.WithTimeout(ctx, 1*time.Second)
helloRes, err := cli.ServiceHello(ctx, "127.0.0.1:1025/hello") helloRes, err := cli.ServiceHello(ctx, srvaddr+"/hello")
require.NoError(t, err) require.NoError(t, err)
require.True(t, helloRes) require.True(t, helloRes)
} }
{
tmpdir := t.TempDir()
tmpfile := filepath.Join(tmpdir, "foo.bin")
filedata := make([]byte, 16)
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)
err = cli.PutFile(ctx, tmpfile, srvaddr+"/foo.bin")
require.NoError(t, err)
}
} }