-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ test: added function for testing command #14
- Loading branch information
1 parent
5d2d3c6
commit 33d8849
Showing
1 changed file
with
250 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,6 @@ func TestAllEventConsume(t *testing.T) { | |
} | ||
|
||
func TestDialOut(t *testing.T) { | ||
// adding logic here | ||
} | ||
|
||
func TestChanspy(t *testing.T) { | ||
|
@@ -59,7 +58,112 @@ func TestGetSIPPeersStatus(t *testing.T) { | |
ami.D().Error(err.Error()) | ||
return | ||
} | ||
log.Println(fmt.Sprintf("SIP peer status: %v", ami.JsonString(peers[1]))) | ||
/* | ||
{ | ||
"action_id": "5ce39195-ae27-2f31-493d-570552478757", | ||
"channel_type": "SIP", | ||
"event": "PeerStatus", | ||
"peer": "SIP/1004", | ||
"peer_status": "Unknown", | ||
"privilege": "System" | ||
} | ||
*/ | ||
for _, v := range peers { | ||
ami.D().Info("Status: %v| Privilege: %v| Peer: %v", | ||
v.Get("peer_status"), | ||
v.Get("privilege"), | ||
v.Get("peer"), | ||
) | ||
} | ||
} | ||
|
||
func TestGetSIPPeer(t *testing.T) { | ||
c, err := createConn() | ||
if err != nil { | ||
ami.D().Error(err.Error()) | ||
return | ||
} | ||
c.Core().AddSession() | ||
c.Core().Dictionary.SetEnabledForceTranslate(true) | ||
c.Core().Dictionary.AddKeyLinkTranslator("https://raw.githubusercontent.com/pnguyen215/gear-insights-free/master/ami.dictionaries.json") | ||
peer, err := c.Core().GetSIPPeer(c.Context(), "1004") | ||
if err != nil { | ||
ami.D().Error(err.Error()) | ||
return | ||
} | ||
/* | ||
{ | ||
"acl": "Y", | ||
"action_id": "d6e2496e-8cdf-a178-11f3-5d840a051c38", | ||
"address_ip": "(null)", | ||
"address_port": "0", | ||
"ama_flags": "Unknown", | ||
"busy_level": "0", | ||
"call_group": "", | ||
"call_limit": "2147483647", | ||
"caller_id": "Ext_1004 <1004>", | ||
"chan_object_type": "peer", | ||
"channel_type": "SIP", | ||
"cid_calling_pres": "Presentation Allowed, Not Screened", | ||
"codecs": "(alaw)", | ||
"context": "from-internal", | ||
"default_addr_ip": "(null)", | ||
"default_addr_port": "0", | ||
"default_username": "1004", | ||
"description": "", | ||
"dynamic": "Y", | ||
"lang": "en", | ||
"last_message_sent": "-1", | ||
"max_call_br": "384 kbps", | ||
"max_forwards": "0", | ||
"md5_secret_exist": "N", | ||
"moh_suggest": "", | ||
"named_call_group": "", | ||
"named_pick_up_group": "", | ||
"object_name": "1004", | ||
"parking_lot": "", | ||
"pickup_group": "", | ||
"qualify_freq": "60000 ms", | ||
"reg_contact": "sip:[email protected]:58745;ob", | ||
"reg_expire": "-1 seconds", | ||
"remote_secret_exist": "N", | ||
"response": "Success", | ||
"secret_exist": "Y", | ||
"sip_auth_in_secure": "no", | ||
"sip_can_reinvite": "N", | ||
"sip_comedia": "Y", | ||
"sip_direct_media": "N", | ||
"sip_dtmf_mode": "rfc2833", | ||
"sip_encryption": "N", | ||
"sip_forcer_port": "Y", | ||
"sip_promisc_redir": "N", | ||
"sip_rtcp_mux": "N", | ||
"sip_rtp_engine": "asterisk", | ||
"sip_sess_expires": "1800", | ||
"sip_sess_min": "90", | ||
"sip_sess_refresh": "uas", | ||
"sip_sess_timers": "Accept", | ||
"sip_text_support": "N", | ||
"sip_time_38_ec": "Unknown", | ||
"sip_time_38_max_dt_grm": "4294967295", | ||
"sip_time_38_support": "N", | ||
"sip_use_reason_header": "N", | ||
"sip_user_agent": "MicroSIP/3.21.3", | ||
"sip_user_phone": "N", | ||
"sip_video_support": "N", | ||
"status": "UNKNOWN", | ||
"to_host": "", | ||
"tone_zone": "<Not set>", | ||
"transfer_mode": "open", | ||
"voicemail_box": "" | ||
} | ||
*/ | ||
ami.D().Info("Caller.ID: %v| CID: %v| Context: %v| qualify_freq: %v", | ||
peer.Get("caller_id"), | ||
peer.Get("cid_calling_pres"), | ||
peer.Get("context"), | ||
peer.Get("qualify_freq"), | ||
) | ||
} | ||
|
||
func TestGetQueueStatuses(t *testing.T) { | ||
|
@@ -71,12 +175,40 @@ func TestGetQueueStatuses(t *testing.T) { | |
c.Core().AddSession() | ||
c.Core().Dictionary.SetEnabledForceTranslate(true) | ||
c.Core().Dictionary.AddKeyLinkTranslator("https://raw.githubusercontent.com/pnguyen215/gear-insights-free/master/ami.dictionaries.json") | ||
peers, err := c.Core().GetQueueStatuses(c.Context(), "") | ||
queues, err := c.Core().GetQueueStatuses(c.Context(), "") | ||
if err != nil { | ||
ami.D().Error(err.Error()) | ||
return | ||
} | ||
log.Println(fmt.Sprintf("SIP queues status: %v", ami.JsonString(peers))) | ||
/* | ||
{ | ||
"action_id": "ce7e68b1-b9c5-209a-46e1-aacadf38d9b1", | ||
"calls_taken": "0", | ||
"event": "QueueMember", | ||
"in_call": "0", | ||
"last_call": "0", | ||
"last_pause": "0", | ||
"location": "Local/8102@from-queue/n", | ||
"login_time": "1701427389", | ||
"membership": "dynamic", | ||
"name": "Ext_8102", | ||
"paused": "0", | ||
"paused_reason": "", | ||
"penalty": "0", | ||
"queue": "8002", | ||
"status": "5", | ||
"status_interface": "hint:8102@ext-local", | ||
"wrap_uptime": "0" | ||
} | ||
*/ | ||
for _, v := range queues { | ||
ami.D().Info("Location: %v| Login Time: %v| Name: %v| Queue: %v ", | ||
v.Get("location"), | ||
v.Get("login_time"), | ||
v.Get("name"), | ||
v.Get("queue"), | ||
) | ||
} | ||
} | ||
|
||
func TestGetQueueSummary(t *testing.T) { | ||
|
@@ -88,10 +220,122 @@ func TestGetQueueSummary(t *testing.T) { | |
c.Core().AddSession() | ||
c.Core().Dictionary.SetEnabledForceTranslate(true) | ||
c.Core().Dictionary.AddKeyLinkTranslator("https://raw.githubusercontent.com/pnguyen215/gear-insights-free/master/ami.dictionaries.json") | ||
peers, err := c.Core().GetQueueSummary(c.Context(), "") | ||
queues, err := c.Core().GetQueueSummary(c.Context(), "") | ||
if err != nil { | ||
ami.D().Error(err.Error()) | ||
return | ||
} | ||
/* | ||
[ | ||
{ | ||
"action_id": "6aa0c877-193a-1be2-d401-d833e73272b1", | ||
"available": "0", | ||
"callers": "0", | ||
"event": "QueueSummary", | ||
"hold_time": "0", | ||
"logged_in": "0", | ||
"longest_hold_time": "0", | ||
"queue": "default", | ||
"talk_time": "0" | ||
} | ||
] | ||
*/ | ||
for _, v := range queues { | ||
ami.D().Info("Queue: %v| Hold Time: %v| Logged In: %v| Longest Hold Time: %v| Talk Time: %v| Available: %v", | ||
v.Get("queue"), | ||
v.Get("hold_time"), | ||
v.Get("logged_in"), | ||
v.Get("longest_hold_time"), | ||
v.Get("talk_time"), | ||
v.Get("available"), | ||
) | ||
} | ||
} | ||
|
||
func TestExtensionStateList(t *testing.T) { | ||
c, err := createConn() | ||
if err != nil { | ||
ami.D().Error(err.Error()) | ||
return | ||
} | ||
c.Core().AddSession() | ||
c.Core().Dictionary.SetEnabledForceTranslate(true) | ||
c.Core().Dictionary.AddKeyLinkTranslator("https://raw.githubusercontent.com/pnguyen215/gear-insights-free/master/ami.dictionaries.json") | ||
extensions, err := c.Core().ExtensionStateList(c.Context()) | ||
if err != nil { | ||
ami.D().Error(err.Error()) | ||
return | ||
} | ||
/* | ||
{ | ||
"action_id": "7443bd11-e2c6-71bf-8d19-cc3cb49b71ec", | ||
"context": "ext-local", | ||
"event": "ExtensionStatus", | ||
"exten": "1010", | ||
"hint": "SIP/1010\u0026Custom:DND1010,CustomPresence:1010", | ||
"status": "0", | ||
"status_text": "Idle" | ||
} | ||
*/ | ||
for _, v := range extensions { | ||
ami.D().Info("Extension: %v| Status: %v| Status Text: %v| Context: %v", | ||
v.Get("exten"), | ||
v.Get("status"), | ||
v.Get("status_text"), | ||
v.Get("context"), | ||
) | ||
} | ||
} | ||
|
||
func TestExtensionState(t *testing.T) { | ||
c, err := createConn() | ||
if err != nil { | ||
ami.D().Error(err.Error()) | ||
return | ||
} | ||
c.Core().AddSession() | ||
c.Core().Dictionary.SetEnabledForceTranslate(true) | ||
c.Core().Dictionary.AddKeyLinkTranslator("https://raw.githubusercontent.com/pnguyen215/gear-insights-free/master/ami.dictionaries.json") | ||
extensions, err := c.Core().ExtensionStates(c.Context()) | ||
if err != nil { | ||
ami.D().Error(err.Error()) | ||
return | ||
} | ||
/* | ||
{ | ||
"action_id": "7443bd11-e2c6-71bf-8d19-cc3cb49b71ec", | ||
"context": "ext-local", | ||
"event": "ExtensionStatus", | ||
"exten": "1010", | ||
"hint": "SIP/1010\u0026Custom:DND1010,CustomPresence:1010", | ||
"status": "0", | ||
"status_text": "Idle" | ||
} | ||
*/ | ||
for _, v := range extensions { | ||
ami.D().Info("Extension: %v| Status: %v| Status Text: %v| Context: %v", | ||
v.Get("exten"), | ||
v.Get("status"), | ||
v.Get("status_text"), | ||
v.Get("context"), | ||
) | ||
} | ||
} | ||
|
||
func TestCommand(t *testing.T) { | ||
c, err := createConn() | ||
if err != nil { | ||
ami.D().Error(err.Error()) | ||
return | ||
} | ||
c.Socket().SetDebugMode(true) | ||
c.Core().AddSession() | ||
c.Core().Dictionary.SetEnabledForceTranslate(true) | ||
c.Core().Dictionary.AddKeyLinkTranslator("https://raw.githubusercontent.com/pnguyen215/gear-insights-free/master/ami.dictionaries.json") | ||
response, err := c.Core().Command(c.Context(), "sip show users") | ||
if err != nil { | ||
ami.D().Error(err.Error()) | ||
return | ||
} | ||
log.Println(fmt.Sprintf("SIP queues summary: %v", ami.JsonString(peers))) | ||
log.Println(fmt.Sprintf("%v", ami.JsonString(response))) | ||
} |