working commit
This commit is contained in:
+61
-12
@@ -43,9 +43,10 @@ func TestAccountOperations(t *testing.T) {
|
||||
|
||||
err = srv.Configure()
|
||||
require.NoError(t, err)
|
||||
var tmpdir bool
|
||||
tmpdir = true
|
||||
if tmpdir {
|
||||
|
||||
useTmpdir := true
|
||||
|
||||
if useTmpdir {
|
||||
srv.SetDatadir(srvdir)
|
||||
srv.SetLogdir(srvdir)
|
||||
srv.SetRundir(srvdir)
|
||||
@@ -79,7 +80,7 @@ func TestAccountOperations(t *testing.T) {
|
||||
fmt.Printf("Response body: %s\n", string(bodyBytes))
|
||||
}
|
||||
var accountID string
|
||||
var accountName = "testname"
|
||||
var accountName = "testname1"
|
||||
{
|
||||
fmt.Printf("=== CreateAccount ===\n")
|
||||
reqpath := `/v3/api/account/create`
|
||||
@@ -123,13 +124,61 @@ func TestAccountOperations(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
fmt.Printf("Formatted body: \n%s\n", jsonBuffer.String())
|
||||
|
||||
resp := handler.GenericResponse[operator.CreateAccountResult]{}
|
||||
resp := handler.Response[operator.CreateAccountResult]{}
|
||||
err = json.Unmarshal(bodyBytes, &resp)
|
||||
require.False(t, resp.Error)
|
||||
require.Equal(t, len(resp.Result.AccountID), 36)
|
||||
accountID = resp.Result.AccountID
|
||||
}
|
||||
fmt.Printf("AccountID: %s", accountID)
|
||||
fmt.Printf("AccountID: %s\n", accountID)
|
||||
{
|
||||
fmt.Printf("=== UpdateAccount ===\n")
|
||||
reqpath := `/v3/api/account/create`
|
||||
routepath := `/v3/api/account/create`
|
||||
|
||||
rout := router.NewRouter()
|
||||
hand := srv.Handler()
|
||||
require.NotNil(t, hand)
|
||||
|
||||
req := operator.UpdateAccountParams{
|
||||
AccountID: accountID,
|
||||
NewPassword: "newpass",
|
||||
}
|
||||
reqdata, err := json.Marshal(req)
|
||||
require.NoError(t, err)
|
||||
|
||||
reqsize := len(reqdata)
|
||||
reqsrc := bytes.NewReader(reqdata)
|
||||
|
||||
request, err := http.NewRequest("POST", reqpath, reqsrc)
|
||||
require.NoError(t, err)
|
||||
|
||||
request.ContentLength = int64(reqsize)
|
||||
request.Header.Set("Content-Type", "application/json")
|
||||
|
||||
recorder := httptest.NewRecorder()
|
||||
|
||||
rout.Post(routepath, hand.UpdateAccount)
|
||||
rout.ServeHTTP(recorder, request)
|
||||
|
||||
fmt.Printf("Response code: %d\n", recorder.Code)
|
||||
|
||||
bodyReader := recorder.Body
|
||||
bodyBytes, err := io.ReadAll(bodyReader)
|
||||
|
||||
fmt.Printf("Response body: %s\n", string(bodyBytes))
|
||||
require.Equal(t, http.StatusOK, recorder.Code)
|
||||
|
||||
jsonBuffer := bytes.NewBuffer(nil)
|
||||
err = json.Indent(jsonBuffer, bodyBytes, "", " ")
|
||||
require.NoError(t, err)
|
||||
fmt.Printf("Formatted body: \n%s\n", jsonBuffer.String())
|
||||
|
||||
resp := handler.Response[operator.UpdateAccountResult]{}
|
||||
err = json.Unmarshal(bodyBytes, &resp)
|
||||
require.False(t, resp.Error)
|
||||
}
|
||||
|
||||
{
|
||||
fmt.Printf("=== GetAccount ===\n")
|
||||
reqpath := `/v3/api/account/get`
|
||||
@@ -140,7 +189,7 @@ func TestAccountOperations(t *testing.T) {
|
||||
require.NotNil(t, hand)
|
||||
|
||||
req := operator.GetAccountParams{
|
||||
Username: accountName,
|
||||
AccountID: accountID,
|
||||
}
|
||||
reqdata, err := json.Marshal(req)
|
||||
require.NoError(t, err)
|
||||
@@ -172,7 +221,7 @@ func TestAccountOperations(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
fmt.Printf("Formatted body: \n%s\n", jsonBuffer.String())
|
||||
|
||||
resp := handler.GenericResponse[operator.GetAccountResult]{}
|
||||
resp := handler.Response[operator.GetAccountResult]{}
|
||||
err = json.Unmarshal(bodyBytes, &resp)
|
||||
require.False(t, resp.Error)
|
||||
require.Equal(t, resp.Result.Account.Username, accountName)
|
||||
@@ -217,7 +266,7 @@ func TestAccountOperations(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
fmt.Printf("Formatted body: \n%s\n", jsonBuffer.String())
|
||||
|
||||
resp := handler.GenericResponse[operator.ListAccountsResult]{}
|
||||
resp := handler.Response[operator.ListAccountsResult]{}
|
||||
err = json.Unmarshal(bodyBytes, &resp)
|
||||
require.False(t, resp.Error)
|
||||
require.Equal(t, len(resp.Result.Accounts), 1)
|
||||
@@ -233,7 +282,7 @@ func TestAccountOperations(t *testing.T) {
|
||||
require.NotNil(t, hand)
|
||||
|
||||
req := operator.DeleteAccountParams{
|
||||
Username: accountName,
|
||||
AccountID: accountID,
|
||||
}
|
||||
reqdata, err := json.Marshal(req)
|
||||
require.NoError(t, err)
|
||||
@@ -265,7 +314,7 @@ func TestAccountOperations(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
fmt.Printf("Formatted body: \n%s\n", jsonBuffer.String())
|
||||
|
||||
resp := handler.GenericResponse[operator.DeleteAccountResult]{}
|
||||
resp := handler.Response[operator.DeleteAccountResult]{}
|
||||
err = json.Unmarshal(bodyBytes, &resp)
|
||||
require.False(t, resp.Error)
|
||||
}
|
||||
@@ -309,7 +358,7 @@ func TestAccountOperations(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
fmt.Printf("Formatted body: \n%s\n", jsonBuffer.String())
|
||||
|
||||
resp := handler.GenericResponse[operator.ListAccountsResult]{}
|
||||
resp := handler.Response[operator.ListAccountsResult]{}
|
||||
err = json.Unmarshal(bodyBytes, &resp)
|
||||
require.False(t, resp.Error)
|
||||
require.Equal(t, len(resp.Result.Accounts), 0)
|
||||
|
||||
Reference in New Issue
Block a user