SortedSuppliers.Count attribute

This commit is contained in:
DanB
2019-04-26 20:24:16 +02:00
parent f6a9ec0ab6
commit 8720d45131
6 changed files with 45 additions and 3 deletions

View File

@@ -46,7 +46,8 @@ var sTestsDNS = []func(t *testing.T){
testDNSitApierRpcConn,
testDNSitTPFromFolder,
testDNSitClntConn,
testDNSitClntNAPTRDryRun,
//testDNSitClntNAPTRDryRun,
testDNSitClntNAPTRSuppliers,
testDNSitStopEngine,
}
@@ -147,6 +148,28 @@ func testDNSitClntNAPTRDryRun(t *testing.T) {
}
}
func testDNSitClntNAPTRSuppliers(t *testing.T) {
m := new(dns.Msg)
m.SetQuestion("4.6.9.4.7.1.7.1.5.6.8.9.4.e164.arpa.", dns.TypeNAPTR)
if err := dnsClnt.WriteMsg(m); err != nil {
t.Error(err)
}
if rply, err := dnsClnt.ReadMsg(); err != nil {
t.Error(err)
} else {
if rply.Rcode != dns.RcodeSuccess {
t.Errorf("failed to get an valid answer\n%v", rply)
}
answr := rply.Answer[0].(*dns.NAPTR)
if answr.Order != 100 {
t.Errorf("received: <%q>", answr.Order)
}
if answr.Replacement != "sip:1\\@172.16.1.10." {
t.Errorf("received: <%q>", answr.Replacement)
}
}
}
func testDNSitStopEngine(t *testing.T) {
if err := engine.KillEngine(*waitRater); err != nil {
t.Error(err)

View File

@@ -34,6 +34,9 @@
"chargers_conns": [
{"address": "*internal"}
],
"suppliers_conns": [
{"address": "127.0.0.1:2012", "transport": "*json"}
],
},
@@ -60,9 +63,17 @@
},
"suppliers": {
"enabled": true,
},
"dns_agent": {
"enabled": true,
"listen": ":2053"
"listen": ":2053",
"sessions_conns": [
{"address": "127.0.0.1:2012", "transport": "*json"}
],
},

View File

@@ -3,7 +3,7 @@
"dns_agent": {
"request_processors": [
{
"id": "dryrun1",
"id": "DryRunNAPTR",
"filters": ["*string:~*vars.QueryType:NAPTR", "*string:~*vars.E164Address:4986517174963"],
"flags": ["*dryrun"],
"request_fields":[

View File

@@ -37,6 +37,7 @@ type SortedSupplier struct {
type SortedSuppliers struct {
ProfileID string // Profile matched
Sorting string // Sorting algorithm
Count int // number of suppliers returned
SortedSuppliers []*SortedSupplier // list of supplier IDs and SortingData data
}

View File

@@ -441,6 +441,7 @@ func (spS *SupplierService) sortedSuppliersForEvent(args *ArgsGetSuppliers) (sor
sortedSuppliers.SortedSuppliers = sortedSuppliers.SortedSuppliers[:*args.Paginator.Limit]
}
}
sortedSuppliers.Count = len(sortedSuppliers.SortedSuppliers)
return sortedSuppliers, nil
}

View File

@@ -415,6 +415,7 @@ func TestSuppliersSortedForEvent(t *testing.T) {
eFirstSupplierProfile := &SortedSuppliers{
ProfileID: "SupplierProfile1",
Sorting: utils.MetaWeight,
Count: 1,
SortedSuppliers: []*SortedSupplier{
{
SupplierID: "supplier1",
@@ -436,6 +437,7 @@ func TestSuppliersSortedForEvent(t *testing.T) {
eFirstSupplierProfile = &SortedSuppliers{
ProfileID: "SupplierProfile2",
Sorting: utils.MetaWeight,
Count: 3,
SortedSuppliers: []*SortedSupplier{
{
SupplierID: "supplier1",
@@ -472,6 +474,7 @@ func TestSuppliersSortedForEvent(t *testing.T) {
eFirstSupplierProfile = &SortedSuppliers{
ProfileID: "SupplierProfilePrefix",
Sorting: utils.MetaWeight,
Count: 1,
SortedSuppliers: []*SortedSupplier{
{
SupplierID: "supplier1",
@@ -496,6 +499,7 @@ func TestSuppliersSortedForEventWithLimit(t *testing.T) {
eFirstSupplierProfile := &SortedSuppliers{
ProfileID: "SupplierProfile2",
Sorting: utils.MetaWeight,
Count: 2,
SortedSuppliers: []*SortedSupplier{
{
SupplierID: "supplier1",
@@ -529,6 +533,7 @@ func TestSuppliersSortedForEventWithOffset(t *testing.T) {
eFirstSupplierProfile := &SortedSuppliers{
ProfileID: "SupplierProfile2",
Sorting: utils.MetaWeight,
Count: 1,
SortedSuppliers: []*SortedSupplier{
{
SupplierID: "supplier3",
@@ -555,6 +560,7 @@ func TestSuppliersSortedForEventWithLimitAndOffset(t *testing.T) {
eFirstSupplierProfile := &SortedSuppliers{
ProfileID: "SupplierProfile2",
Sorting: utils.MetaWeight,
Count: 1,
SortedSuppliers: []*SortedSupplier{
{
SupplierID: "supplier2",