mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add and revise new unit tests on agents
This commit is contained in:
committed by
Dan Christian Bogos
parent
d3975b4d2f
commit
2d6912657d
@@ -89,3 +89,13 @@ func TestHandleChannelDestroyedFail(t *testing.T) {
|
||||
t.Errorf("Expected ev to not change, received <%v>", utils.ToJSON(ev))
|
||||
}
|
||||
}
|
||||
|
||||
func TestAstAgentV1WarnDisconnect(t *testing.T) {
|
||||
tAsteriskAgent := &AsteriskAgent{}
|
||||
tMap := map[string]any{}
|
||||
tString := ""
|
||||
err := tAsteriskAgent.V1WarnDisconnect(nil, tMap, &tString)
|
||||
if err != utils.ErrNotImplemented {
|
||||
t.Errorf("Expected error: %v, got: %v", utils.ErrNotImplemented, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1339,6 +1339,63 @@ func TestFSEventGetOptions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFseventGetADC(t *testing.T) {
|
||||
type testCase struct {
|
||||
name string
|
||||
fsev FSEvent
|
||||
fieldName string
|
||||
expect time.Duration
|
||||
err error
|
||||
}
|
||||
testCases := []testCase{
|
||||
{
|
||||
name: "ACD from Var-CGR-ACD with seconds",
|
||||
fsev: FSEvent{"Var-CGR-ACD": "1640"},
|
||||
fieldName: "ACD",
|
||||
expect: 0 * time.Second,
|
||||
},
|
||||
{
|
||||
name: "ACD from Var-CGR-ACD with empty string",
|
||||
fsev: FSEvent{"Var-CGR-ACD": ""},
|
||||
fieldName: "ACD",
|
||||
expect: 0,
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
name: "Static value prefixed field",
|
||||
fsev: FSEvent{"static_value": "30s"},
|
||||
fieldName: "static_value",
|
||||
expect: 30 * time.Second,
|
||||
},
|
||||
{
|
||||
name: "Non-existent field",
|
||||
fsev: FSEvent{},
|
||||
fieldName: "non_existent",
|
||||
expect: 0,
|
||||
err: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got, err := tc.fsev.GetADC(tc.fieldName)
|
||||
if tc.err != nil {
|
||||
if err == nil {
|
||||
t.Errorf("Expected error: %v, got none", tc.err)
|
||||
}
|
||||
} else {
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if got != tc.expect {
|
||||
t.Errorf("Expected duration: %v, got: %v", tc.expect, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFseventMissingParameter(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
|
||||
@@ -1206,3 +1206,42 @@ func TestLibDiamHeaderLen(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibdiamDiamBareErr(t *testing.T) {
|
||||
testMessage := &diam.Message{
|
||||
Header: &diam.Header{
|
||||
CommandFlags: 0,
|
||||
},
|
||||
}
|
||||
resCode := uint32(200)
|
||||
returnedMessage := diamBareErr(testMessage, resCode)
|
||||
if returnedMessage == nil {
|
||||
t.Error("Expected a non-nil message, got nil")
|
||||
return
|
||||
}
|
||||
if returnedMessage.Header.CommandFlags != diam.ErrorFlag {
|
||||
t.Errorf("Expected CommandFlags to be %d, got %d", diam.ErrorFlag, returnedMessage.Header.CommandFlags)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibdiamDiamErr(t *testing.T) {
|
||||
tMessage := &diam.Message{
|
||||
Header: &diam.Header{
|
||||
CommandFlags: 0,
|
||||
},
|
||||
}
|
||||
resCode := uint32(200)
|
||||
reqVars := &utils.DataNode{}
|
||||
tpl := []*config.FCTemplate{}
|
||||
tnt := "cgrates.org"
|
||||
tmz := "UTC"
|
||||
filterS := &engine.FilterS{}
|
||||
returnedMessage, err := diamErr(tMessage, resCode, reqVars, tpl, tnt, tmz, filterS)
|
||||
if err != nil {
|
||||
t.Errorf("Expected no error, but got: %v", err)
|
||||
}
|
||||
if returnedMessage == nil {
|
||||
t.Error("Expected a non-nil diam.Message, got nil")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user