fixed display of help command for maxusage

This commit is contained in:
gezimbll
2025-12-15 10:19:15 +01:00
committed by Dan Christian Bogos
parent e859be8806
commit 40ff69ba40
4 changed files with 25 additions and 15 deletions

View File

@@ -19,6 +19,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>
package console
import (
"encoding/json"
"fmt"
"time"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -54,7 +58,10 @@ func (self *CmdGetMaxUsage) RpcMethod() string {
func (self *CmdGetMaxUsage) RpcParams(reset bool) any {
if reset || self.rpcParams == nil {
self.rpcParams = new(engine.UsageRecordWithAPIOpts)
self.rpcParams = &engine.UsageRecordWithAPIOpts{
UsageRecord: new(engine.UsageRecord),
APIOpts: make(map[string]any),
}
}
return self.rpcParams
}
@@ -64,10 +71,18 @@ func (self *CmdGetMaxUsage) PostprocessRpcParams() error {
}
func (self *CmdGetMaxUsage) RpcResult() any {
var f int64
return &f
var d time.Duration
return &d
}
func (self *CmdGetMaxUsage) ClientArgs() []string {
return self.clientArgs
}
func (self *CmdGetMaxUsage) GetFormatedResult(result any) string {
if tv, canCast := result.(*time.Duration); canCast {
return fmt.Sprintf(`"%s"`, tv.String())
}
out, _ := json.MarshalIndent(result, utils.EmptyString, " ")
return string(out)
}

View File

@@ -53,14 +53,9 @@ func TestCmdMaxUsage(t *testing.T) {
}
// for coverage purpose
formatedResult := command.GetFormatedResult(command.RpcResult())
expected := GetFormatedResult(command.RpcResult(), utils.StringSet{
utils.Usage: {},
utils.GroupIntervalStart: {},
utils.RateIncrement: {},
utils.RateUnit: {},
})
if !reflect.DeepEqual(formatedResult, expected) {
t.Errorf("Expected <%+v>, Received <%+v>", expected, formatedResult)
if formatedResult != `"0s"` {
t.Errorf("Expected 0s, Received %s", formatedResult)
}
expected2 := []string{utils.ToR, utils.RequestType, utils.Tenant,
utils.Category, utils.AccountField, utils.Subject, utils.Destination,