Skip to content

Commit

Permalink
✅ test: added function testing #14
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Jan 13, 2024
1 parent 83ca460 commit 13b8099
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
21 changes: 17 additions & 4 deletions example/ami_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@ package example

import (
"testing"
"time"

"github.com/pnguyen215/voipkit/pkg/ami"
)

func TestAmiClient(t *testing.T) {
c := ami.GetAmiClientSample()
ami.D().Info("ami client request: %v", c.String())
func createConn() (*ami.AMI, error) {
c := ami.GetAmiClientSample().
SetEnabled(true).
SetPort(5038).
SetUsername("monast").
SetPassword("T5Monast").
SetTimeout(5 * time.Second)
return ami.NewClient(ami.NewTcp(), *c)
}

ami.NewClient(ami.NewTcp(), *c)
func TestAmiClient(t *testing.T) {
_, err := createConn()
if err != nil {
ami.D().Error(err.Error())
return
}
ami.D().Info("Authenticated successfully")
}
2 changes: 1 addition & 1 deletion pkg/ami/ami.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ func create(conn net.Conn) (*AMI, context.Context) {
_socket, err := WithSocket(ctx, addr)
if err == nil {
c.Socket = _socket
D().Info("Ami cloning (addr: %v) socket connection succeeded", addr)
D().Info("Ami network cloning (addr: %v) socket connection succeeded", addr)
}
}
return c, ctx
Expand Down
2 changes: 1 addition & 1 deletion pkg/ami/ami_dictionary.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (d *AMIDictionary) GetDictionaries() *[]AMIEventDictionary {

overlapDictionaries = &dictionaries
dictionary, _ := d.FindDictionaryByKey(config.AmiListenerEventCommon)
log.Printf("Dictionaries (common) was initialized, len = %d", len(dictionary.Dictionaries))
D().Info("Dictionaries (common) was initialized, len: %d", len(dictionary.Dictionaries))
return overlapDictionaries
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/ami/ami_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ func (e *AmiError) ErrorWrap(message string, args ...interface{}) *AmiError {
}

func (e *AmiError) Error() string {
return fmt.Sprintf("ami has error ocurred: %s%s", e.S, e.E)
return fmt.Sprintf("Ami has an error ocurred: %s%s", e.S, e.E)
}
10 changes: 5 additions & 5 deletions pkg/ami/ami_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,21 @@ func OnUdpConn(ip string, port int) (net.Conn, error) {
// defer conn.Close()
func NewNetwork(network, ip string, port int) (net.Conn, error) {
if !config.AmiNetworkKeys[network] {
return nil, AmiErrorWrap("AMI: Invalid network")
return nil, AmiErrorWrap("Ami: Invalid network")
}
if IsStringEmpty(ip) {
return nil, AmiErrorWrap("AMI: IP must be not empty")
return nil, AmiErrorWrap("Ami: IP must be not empty")
}
if port <= 0 {
return nil, AmiErrorWrap("AMI: Port must be positive number")
return nil, AmiErrorWrap("Ami: Port must be positive number")
}
host, _port, _ := DecodeIp(ip)
if len(host) > 0 && len(_port) > 0 {
form := net.JoinHostPort(host, _port)
D().Info("AMI: (IP decoded) dial connection: %v", form)
D().Info("Ami (IP decoded) dial connection: %v", form)
return net.Dial(network, form)
}
form := RemoveProtocol(ip, port)
D().Info("AMI: dial connection: %v", form)
D().Info("Ami dial connection: %v", form)
return net.Dial(network, form)
}

0 comments on commit 13b8099

Please sign in to comment.