From 1771d9de3a58ed2eb3474e8f21e7dd23428e2d7d Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Fri, 2 Aug 2013 12:54:35 +0300 Subject: [PATCH] history test passing --- engine/history_test.go | 13 ++++--------- history/mock_scribe.go | 1 + 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/engine/history_test.go b/engine/history_test.go index b64121caa..2e32a6e0c 100644 --- a/engine/history_test.go +++ b/engine/history_test.go @@ -20,19 +20,14 @@ package engine import ( "github.com/cgrates/cgrates/history" + "strings" "testing" ) func TestHistory(t *testing.T) { scribe := historyScribe.(*history.MockScribe) - expected := `[{"Key":"GERMANY","Object":{"Id":"GERMANY","Prefixes":["49"]}}] - [{"Key":"GERMANY","Object":{"Id":"GERMANY","Prefixes":["49"]}},{"Key":"GERMANY_O2","Object":{"Id":"GERMANY_O2","Prefixes":["41"]}}] - [{"Key":"GERMANY","Object":{"Id":"GERMANY","Prefixes":["49"]}},{"Key":"GERMANY_O2","Object":{"Id":"GERMANY_O2","Prefixes":["41"]}},{"Key":"GERMANY_PREMIUM","Object":{"Id":"GERMANY_PREMIUM","Prefixes":["43"]}}] - [{"Key":"ALL","Object":{"Id":"ALL","Prefixes":["49","41","43"]}},{"Key":"GERMANY","Object":{"Id":"GERMANY","Prefixes":["49"]}},{"Key":"GERMANY_O2","Object":{"Id":"GERMANY_O2","Prefixes":["41"]}},{"Key":"GERMANY_PREMIUM","Object":{"Id":"GERMANY_PREMIUM","Prefixes":["43"]}}] - [{"Key":"ALL","Object":{"Id":"ALL","Prefixes":["49","41","43"]}},{"Key":"GERMANY","Object":{"Id":"GERMANY","Prefixes":["49"]}},{"Key":"GERMANY_O2","Object":{"Id":"GERMANY_O2","Prefixes":["41"]}},{"Key":"GERMANY_PREMIUM","Object":{"Id":"GERMANY_PREMIUM","Prefixes":["43"]}},{"Key":"NAT","Object":{"Id":"NAT","Prefixes":["0256","0257","0723"]}}] - [{"Key":"ALL","Object":{"Id":"ALL","Prefixes":["49","41","43"]}},{"Key":"GERMANY","Object":{"Id":"GERMANY","Prefixes":["49"]}},{"Key":"GERMANY_O2","Object":{"Id":"GERMANY_O2","Prefixes":["41"]}},{"Key":"GERMANY_PREMIUM","Object":{"Id":"GERMANY_PREMIUM","Prefixes":["43"]}},{"Key":"NAT","Object":{"Id":"NAT","Prefixes":["0256","0257","0723"]}},{"Key":"RET","Object":{"Id":"RET","Prefixes":["0723","0724"]}}] - [{"Key":"ALL","Object":{"Id":"ALL","Prefixes":["49","41","43"]}},{"Key":"GERMANY","Object":{"Id":"GERMANY","Prefixes":["49"]}},{"Key":"GERMANY_O2","Object":{"Id":"GERMANY_O2","Prefixes":["41"]}},{"Key":"GERMANY_PREMIUM","Object":{"Id":"GERMANY_PREMIUM","Prefixes":["43"]}},{"Key":"NAT","Object":{"Id":"NAT","Prefixes":["0256","0257","0723"]}},{"Key":"RET","Object":{"Id":"RET","Prefixes":["0723","0724"]}},{"Key":"nat","Object":{"Id":"nat","Prefixes":["0257","0256","0723"]}}]` - if scribe.Buf.String() != expected { - //t.Error("Error in history content: ", scribe.Buf.String()) + expected := `[{"Key":"ALL","Object":{"Id":"ALL","Prefixes":["49","41","43"]}},{"Key":"GERMANY","Object":{"Id":"GERMANY","Prefixes":["49"]}},{"Key":"GERMANY_O2","Object":{"Id":"GERMANY_O2","Prefixes":["41"]}},{"Key":"GERMANY_PREMIUM","Object":{"Id":"GERMANY_PREMIUM","Prefixes":["43"]}},{"Key":"NAT","Object":{"Id":"NAT","Prefixes":["0256","0257","0723"]}},{"Key":"RET","Object":{"Id":"RET","Prefixes":["0723","0724"]}},{"Key":"nat","Object":{"Id":"nat","Prefixes":["0257","0256","0723"]}}]` + if strings.TrimSpace(scribe.Buf.String()) != expected { + t.Error("Error in history content:|", scribe.Buf.String(), "|") } } diff --git a/history/mock_scribe.go b/history/mock_scribe.go index 3b2665b9c..75f1a9d18 100644 --- a/history/mock_scribe.go +++ b/history/mock_scribe.go @@ -44,6 +44,7 @@ func (s *MockScribe) Record(key string, obj interface{}) error { } func (s *MockScribe) save() error { + s.Buf.Reset() b := bufio.NewWriter(&s.Buf) e := json.NewEncoder(b) defer b.Flush()