console now can receive params with array value

This commit is contained in:
Radu Ioan Fericean
2014-08-02 13:35:57 +03:00
parent 7c34c36f6f
commit a6b82806fd
4 changed files with 35 additions and 5 deletions

View File

@@ -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

View File

@@ -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)
}
}

View File

@@ -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

View File

@@ -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