working commit
This commit is contained in:
+1
-1
@@ -16,7 +16,7 @@ import (
|
||||
"mstore/app/server"
|
||||
)
|
||||
|
||||
func TestFileOperations(t *testing.T) {
|
||||
func xxxTestFileOperations(t *testing.T) {
|
||||
var err error
|
||||
fmt.Printf("=== MakeServer ===\n")
|
||||
srv, err := server.NewServer()
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"mstore/pkg/client"
|
||||
"mstore/app/server"
|
||||
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestService(t *testing.T) {
|
||||
var srvport int64 = 10250
|
||||
srvdir := t.TempDir()
|
||||
srvaddr := fmt.Sprintf("127.0.0.1:%d", srvport)
|
||||
|
||||
srv, err := server.NewServer()
|
||||
require.NoError(t, err)
|
||||
{
|
||||
err = srv.Configure()
|
||||
require.NoError(t, err)
|
||||
|
||||
srv.SetDatadir(srvdir)
|
||||
srv.SetLogdir(srvdir)
|
||||
srv.SetRundir(srvdir)
|
||||
srv.SetPort(srvport)
|
||||
|
||||
err = srv.Build()
|
||||
require.NoError(t, err)
|
||||
|
||||
var svcWG sync.WaitGroup
|
||||
errPipe := make(chan error, 5)
|
||||
|
||||
startFunc := func() {
|
||||
err := srv.Service().Run()
|
||||
errPipe <- err
|
||||
svcWG.Done()
|
||||
}
|
||||
|
||||
stopFunc := func() {
|
||||
srv.Service().Stop()
|
||||
svcWG.Wait()
|
||||
err = <-errPipe
|
||||
require.NoError(t, err)
|
||||
}
|
||||
defer stopFunc()
|
||||
|
||||
svcWG.Add(1)
|
||||
go startFunc()
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
{
|
||||
fmt.Printf("=== ServiceHello ===\n")
|
||||
cli := client.NewClient()
|
||||
ctx := context.Background()
|
||||
ctx, _ = context.WithTimeout(ctx, 1*time.Second)
|
||||
|
||||
helloRes, err := cli.ServiceHello(ctx, srvaddr+"/hello")
|
||||
require.NoError(t, err)
|
||||
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)
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user