Files
cgrates/engine/eventrequest_test.go

59 lines
1.9 KiB
Go

/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package engine
import (
"fmt"
"reflect"
"testing"
"time"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
)
func TestAgentRequestParseFieldDateTime(t *testing.T) {
tntTpl := config.NewRSRParsersMustCompile("*daily", utils.InfieldSep)
AgentReq := NewEventRequest(utils.MapStorage{}, nil, nil, tntTpl, "", "", nil, nil)
fctTemp := &config.FCTemplate{
Type: utils.MetaDateTime,
Value: config.NewRSRParsersMustCompile("*daily", utils.InfieldSep),
Layout: "“Mon Jan _2 15:04:05 2006”",
Timezone: "",
}
result, err := AgentReq.ParseField(fctTemp)
if err != nil {
t.Errorf("Expected %v but received %v", nil, err)
}
expected, err := utils.ParseTimeDetectLayout("*daily", utils.FirstNonEmpty(fctTemp.Timezone, config.CgrConfig().GeneralCfg().DefaultTimezone))
if err != nil {
t.Errorf("Expected %v but received %v", nil, err)
}
strRes := fmt.Sprintf("%v", result)
finRes, err := time.Parse("“Mon Jan _2 15:04:05 2006”", strRes)
if err != nil {
t.Errorf("Expected %v but received %v", nil, err)
}
if !reflect.DeepEqual(finRes.Day(), expected.Day()) {
t.Errorf("Expected %v but received %v", expected, result)
}
}