working commit
This commit is contained in:
+17
-12
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user