mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
console now can receive params with array value
This commit is contained in:
@@ -30,8 +30,8 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
lineR = regexp.MustCompile(`(\w+)\s*=\s*(.+?)(?:\s+|$)`)
|
||||
jsonR = regexp.MustCompile(`"(\w+)":(.+?)[,|}]`)
|
||||
lineR = regexp.MustCompile(`(\w+)\s*=\s*(\[.+?\]|.+?)(?:\s+|$)`)
|
||||
jsonR = regexp.MustCompile(`"(\w+)":(\[.+?\]|.+?)[,|}]`)
|
||||
)
|
||||
|
||||
// Commander implementation
|
||||
|
||||
@@ -53,8 +53,22 @@ func TestToJSONString(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestToJSONArrayNoSpace(t *testing.T) {
|
||||
jsn := ToJSON(`Param=["id1","id2","id3"] Another="Patram"`)
|
||||
if string(jsn) != `{"Param":["id1","id2","id3"],"Another":"Patram"}` {
|
||||
t.Error("Error string: ", string(jsn))
|
||||
}
|
||||
}
|
||||
|
||||
func TestToJSONArraySpace(t *testing.T) {
|
||||
jsn := ToJSON(`Param=["id1", "id2", "id3"] Another="Patram"`)
|
||||
if string(jsn) != `{"Param":["id1", "id2", "id3"],"Another":"Patram"}` {
|
||||
t.Error("Error string: ", string(jsn))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFromJSON(t *testing.T) {
|
||||
line := FromJSON([]byte(`{"TimeStart":"Test","Crazy":1,"Mama":true,"Test":1}`), []string{"TimeStart", "Test", "Crazy", "Mama", "Test"})
|
||||
line := FromJSON([]byte(`{"TimeStart":"Test","Crazy":1,"Mama":true,"Test":1}`), []string{"TimeStart", "Crazy", "Mama", "Test"})
|
||||
expected := `TimeStart="Test" Crazy=1 Mama=true Test=1`
|
||||
if line != expected {
|
||||
t.Errorf("Expected: %s got: '%s'", expected, line)
|
||||
@@ -76,3 +90,19 @@ func TestFromJSONString(t *testing.T) {
|
||||
t.Errorf("Expected: %s got: '%s'", expected, line)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFromJSONArrayNoSpace(t *testing.T) {
|
||||
line := FromJSON([]byte(`{"Param":["id1","id2","id3"], "TimeStart":"Test", "Test":1}`), []string{"Param", "TimeStart", "Test"})
|
||||
expected := `Param=["id1","id2","id3"] TimeStart="Test" Test=1`
|
||||
if line != expected {
|
||||
t.Errorf("Expected: %s got: '%s'", expected, line)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFromJSONArraySpace(t *testing.T) {
|
||||
line := FromJSON([]byte(`{"Param":["id1", "id2", "id3"], "TimeStart":"Test", "Test":1}`), []string{"Param", "TimeStart", "Test"})
|
||||
expected := `Param=["id1", "id2", "id3"] TimeStart="Test" Test=1`
|
||||
if line != expected {
|
||||
t.Errorf("Expected: %s got: '%s'", expected, line)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ func (s *Stats) ReloadQueues(ids []string, out *int) error {
|
||||
if cs, err := s.ratingDb.GetCdrStats(id); err == nil {
|
||||
s.AddQueue(cs, nil)
|
||||
} else {
|
||||
return fmt.Errorf("Cannot load cdr stats for id %v: %v", id, err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -672,7 +672,7 @@ func (rs *RedisStorage) SetCdrStats(cs *CdrStats) error {
|
||||
|
||||
func (rs *RedisStorage) GetCdrStats(key string) (cs *CdrStats, err error) {
|
||||
var values []byte
|
||||
if values, err = rs.db.Get(key); err == nil {
|
||||
if values, err = rs.db.Get(CDR_STATS_PREFIX + key); err == nil {
|
||||
err = rs.ms.Unmarshal(values, &cs)
|
||||
}
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user