Finished tests for model helpers

This commit is contained in:
andronache
2020-12-08 14:09:42 +02:00
committed by Dan Christian Bogos
parent ce013604be
commit 86e9e742c8
4 changed files with 380 additions and 155 deletions

View File

@@ -347,8 +347,8 @@ func APItoModelRates(rs []*utils.TPRateRALs) (result RateMdls) {
type DestinationRateMdls []DestinationRateMdl
func (tps DestinationRateMdls) AsMapDestinationRates() (map[string]*utils.TPDestinationRate, error) {
result := make(map[string]*utils.TPDestinationRate)
func (tps DestinationRateMdls) AsMapDestinationRates() (result map[string]*utils.TPDestinationRate) {
result = make(map[string]*utils.TPDestinationRate)
for _, tp := range tps {
dr := &utils.TPDestinationRate{
TPid: tp.Tpid,
@@ -372,18 +372,14 @@ func (tps DestinationRateMdls) AsMapDestinationRates() (map[string]*utils.TPDest
}
result[tp.Tag] = existing
}
return result, nil
return
}
func (tps DestinationRateMdls) AsTPDestinationRates() (result []*utils.TPDestinationRate, err error) {
if atps, err := tps.AsMapDestinationRates(); err != nil {
return nil, err
} else {
for _, tp := range atps {
result = append(result, tp)
}
return result, nil
func (tps DestinationRateMdls) AsTPDestinationRates() (result []*utils.TPDestinationRate) {
for _, tp := range tps.AsMapDestinationRates() {
result = append(result, tp)
}
return
}
func MapTPDestinationRates(s []*utils.TPDestinationRate) (map[string]*utils.TPDestinationRate, error) {
@@ -435,8 +431,8 @@ func APItoModelDestinationRates(drs []*utils.TPDestinationRate) (result Destinat
type RatingPlanMdls []RatingPlanMdl
func (tps RatingPlanMdls) AsMapTPRatingPlans() (map[string]*utils.TPRatingPlan, error) {
result := make(map[string]*utils.TPRatingPlan)
func (tps RatingPlanMdls) AsMapTPRatingPlans() (result map[string]*utils.TPRatingPlan) {
result = make(map[string]*utils.TPRatingPlan)
for _, tp := range tps {
rp := &utils.TPRatingPlan{
TPid: tp.Tpid,
@@ -454,18 +450,14 @@ func (tps RatingPlanMdls) AsMapTPRatingPlans() (map[string]*utils.TPRatingPlan,
existing.RatingPlanBindings = append(existing.RatingPlanBindings, rpb)
}
}
return result, nil
return
}
func (tps RatingPlanMdls) AsTPRatingPlans() (result []*utils.TPRatingPlan, err error) {
if atps, err := tps.AsMapTPRatingPlans(); err != nil {
return nil, err
} else {
for _, tp := range atps {
result = append(result, tp)
}
return result, nil
func (tps RatingPlanMdls) AsTPRatingPlans() (result []*utils.TPRatingPlan) {
for _, tp := range tps.AsMapTPRatingPlans() {
result = append(result, tp)
}
return
}
func GetRateInterval(rpl *utils.TPRatingPlanBinding, dr *utils.DestinationRate) (i *RateInterval) {
@@ -546,8 +538,8 @@ func APItoModelRatingPlans(rps []*utils.TPRatingPlan) (result RatingPlanMdls) {
type RatingProfileMdls []RatingProfileMdl
func (tps RatingProfileMdls) AsMapTPRatingProfiles() (map[string]*utils.TPRatingProfile, error) {
result := make(map[string]*utils.TPRatingProfile)
func (tps RatingProfileMdls) AsMapTPRatingProfiles() (result map[string]*utils.TPRatingProfile) {
result = make(map[string]*utils.TPRatingProfile)
for _, tp := range tps {
rp := &utils.TPRatingProfile{
TPid: tp.Tpid,
@@ -568,18 +560,14 @@ func (tps RatingProfileMdls) AsMapTPRatingProfiles() (map[string]*utils.TPRating
existing.RatingPlanActivations = append(existing.RatingPlanActivations, ra)
}
}
return result, nil
return
}
func (tps RatingProfileMdls) AsTPRatingProfiles() (result []*utils.TPRatingProfile, err error) {
if atps, err := tps.AsMapTPRatingProfiles(); err != nil {
return nil, err
} else {
for _, tp := range atps {
result = append(result, tp)
}
return result, nil
func (tps RatingProfileMdls) AsTPRatingProfiles() (result []*utils.TPRatingProfile) {
for _, tp := range tps.AsMapTPRatingProfiles() {
result = append(result, tp)
}
return
}
func MapTPRatingProfiles(s []*utils.TPRatingProfile) (map[string]*utils.TPRatingProfile, error) {
@@ -632,8 +620,8 @@ func APItoModelRatingProfiles(rps []*utils.TPRatingProfile) (result RatingProfil
type SharedGroupMdls []SharedGroupMdl
func (tps SharedGroupMdls) AsMapTPSharedGroups() (map[string]*utils.TPSharedGroups, error) {
result := make(map[string]*utils.TPSharedGroups)
func (tps SharedGroupMdls) AsMapTPSharedGroups() (result map[string]*utils.TPSharedGroups) {
result = make(map[string]*utils.TPSharedGroups)
for _, tp := range tps {
sgs := &utils.TPSharedGroups{
TPid: tp.Tpid,
@@ -651,18 +639,14 @@ func (tps SharedGroupMdls) AsMapTPSharedGroups() (map[string]*utils.TPSharedGrou
existing.SharedGroups = append(existing.SharedGroups, sg)
}
}
return result, nil
return
}
func (tps SharedGroupMdls) AsTPSharedGroups() (result []*utils.TPSharedGroups, err error) {
if atps, err := tps.AsMapTPSharedGroups(); err != nil {
return nil, err
} else {
for _, tp := range atps {
result = append(result, tp)
}
return result, nil
func (tps SharedGroupMdls) AsTPSharedGroups() (result []*utils.TPSharedGroups) {
for _, tp := range tps.AsMapTPSharedGroups() {
result = append(result, tp)
}
return
}
func MapTPSharedGroup(s []*utils.TPSharedGroups) map[string][]*utils.TPSharedGroup {
@@ -711,8 +695,8 @@ func APItoModelSharedGroups(sgs []*utils.TPSharedGroups) (result SharedGroupMdls
type ActionMdls []ActionMdl
func (tps ActionMdls) AsMapTPActions() (map[string]*utils.TPActions, error) {
result := make(map[string]*utils.TPActions)
func (tps ActionMdls) AsMapTPActions() (result map[string]*utils.TPActions) {
result = make(map[string]*utils.TPActions)
for _, tp := range tps {
as := &utils.TPActions{
TPid: tp.Tpid,
@@ -743,18 +727,14 @@ func (tps ActionMdls) AsMapTPActions() (map[string]*utils.TPActions, error) {
existing.Actions = append(existing.Actions, a)
}
}
return result, nil
return
}
func (tps ActionMdls) AsTPActions() (result []*utils.TPActions, err error) {
if atps, err := tps.AsMapTPActions(); err != nil {
return nil, err
} else {
for _, tp := range atps {
result = append(result, tp)
}
return result, nil
func (tps ActionMdls) AsTPActions() (result []*utils.TPActions) {
for _, tp := range tps.AsMapTPActions() {
result = append(result, tp)
}
return result
}
func MapTPActions(s []*utils.TPActions) map[string][]*utils.TPAction {
@@ -816,8 +796,8 @@ func APItoModelActions(as []*utils.TPActions) (result ActionMdls) {
type ActionPlanMdls []ActionPlanMdl
func (tps ActionPlanMdls) AsMapTPActionPlans() (map[string]*utils.TPActionPlan, error) {
result := make(map[string]*utils.TPActionPlan)
func (tps ActionPlanMdls) AsMapTPActionPlans() (result map[string]*utils.TPActionPlan) {
result = make(map[string]*utils.TPActionPlan)
for _, tp := range tps {
as := &utils.TPActionPlan{
TPid: tp.Tpid,
@@ -835,18 +815,14 @@ func (tps ActionPlanMdls) AsMapTPActionPlans() (map[string]*utils.TPActionPlan,
existing.ActionPlan = append(existing.ActionPlan, a)
}
}
return result, nil
return
}
func (tps ActionPlanMdls) AsTPActionPlans() (result []*utils.TPActionPlan, err error) {
if atps, err := tps.AsMapTPActionPlans(); err != nil {
return nil, err
} else {
for _, tp := range atps {
result = append(result, tp)
}
return result, nil
func (tps ActionPlanMdls) AsTPActionPlans() (result []*utils.TPActionPlan) {
for _, tp := range tps.AsMapTPActionPlans() {
result = append(result, tp)
}
return
}
func MapTPActionTimings(s []*utils.TPActionPlan) map[string][]*utils.TPActionTiming {
@@ -895,8 +871,8 @@ func APItoModelActionPlans(aps []*utils.TPActionPlan) (result ActionPlanMdls) {
type ActionTriggerMdls []ActionTriggerMdl
func (tps ActionTriggerMdls) AsMapTPActionTriggers() (map[string]*utils.TPActionTriggers, error) {
result := make(map[string]*utils.TPActionTriggers)
func (tps ActionTriggerMdls) AsMapTPActionTriggers() (result map[string]*utils.TPActionTriggers) {
result = make(map[string]*utils.TPActionTriggers)
for _, tp := range tps {
ats := &utils.TPActionTriggers{
TPid: tp.Tpid,
@@ -932,18 +908,14 @@ func (tps ActionTriggerMdls) AsMapTPActionTriggers() (map[string]*utils.TPAction
existing.ActionTriggers = append(existing.ActionTriggers, at)
}
}
return result, nil
return
}
func (tps ActionTriggerMdls) AsTPActionTriggers() (result []*utils.TPActionTriggers, err error) {
if atps, err := tps.AsMapTPActionTriggers(); err != nil {
return nil, err
} else {
for _, tp := range atps {
result = append(result, tp)
}
return result, nil
func (tps ActionTriggerMdls) AsTPActionTriggers() (result []*utils.TPActionTriggers) {
for _, tp := range tps.AsMapTPActionTriggers() {
result = append(result, tp)
}
return
}
func MapTPActionTriggers(s []*utils.TPActionTriggers) map[string][]*utils.TPActionTrigger {
@@ -1027,15 +999,12 @@ func (tps AccountActionMdls) AsMapTPAccountActions() (map[string]*utils.TPAccoun
return result, nil
}
func (tps AccountActionMdls) AsTPAccountActions() (result []*utils.TPAccountActions, err error) {
if atps, err := tps.AsMapTPAccountActions(); err != nil {
return nil, err
} else {
for _, tp := range atps {
result = append(result, tp)
}
return result, nil
func (tps AccountActionMdls) AsTPAccountActions() (result []*utils.TPAccountActions) {
atps, _ := tps.AsMapTPAccountActions()
for _, tp := range atps {
result = append(result, tp)
}
return result
}
func MapTPAccountActions(s []*utils.TPAccountActions) (map[string]*utils.TPAccountActions, error) {

View File

@@ -612,9 +612,8 @@ func TestAPItoModelDestinationRates(t *testing.T) {
func TestTpDestinationRatesAsTPDestinationRates(t *testing.T) {
pts := DestinationRateMdls{}
eOut := []*utils.TPDestinationRate{}
if rcv, err := pts.AsTPDestinationRates(); err != nil {
t.Error(err)
} else if rcv != nil {
rcv := pts.AsTPDestinationRates()
if rcv != nil {
t.Errorf("Expecting: nil, received: %+v", utils.ToJSON(rcv))
}
@@ -647,9 +646,8 @@ func TestTpDestinationRatesAsTPDestinationRates(t *testing.T) {
},
},
}
if rcv, err := pts.AsTPDestinationRates(); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(eOut, rcv) {
rcv = pts.AsTPDestinationRates()
if !reflect.DeepEqual(eOut, rcv) {
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(eOut), utils.ToJSON(rcv))
}
@@ -6661,3 +6659,283 @@ func TestModelHelpersResourceProfileToAPICase2(t *testing.T) {
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ToJSON(expStruct), utils.ToJSON(result))
}
}
func TestModelHelpersAPItoResourceError1(t *testing.T) {
testStruct := &utils.TPResourceProfile{
TPid: "",
Tenant: "",
ID: "",
FilterIDs: nil,
ActivationInterval: nil,
UsageTTL: "cat",
Limit: "",
AllocationMessage: "",
Blocker: false,
Stored: false,
Weight: 0,
ThresholdIDs: nil,
}
_, err := APItoResource(testStruct, "")
if err == nil || err.Error() != "time: invalid duration \"cat\"" {
t.Errorf("\nExpecting <time: invalid duration \"cat\">,\n Received <%+v>", err)
}
}
func TestModelHelpersAPItoResourceError2(t *testing.T) {
testStruct := &utils.TPResourceProfile{
TPid: "",
Tenant: "",
ID: "",
FilterIDs: nil,
ActivationInterval: &utils.TPActivationInterval{
ActivationTime: "cat",
},
UsageTTL: "",
Limit: "",
AllocationMessage: "",
Blocker: false,
Stored: false,
Weight: 0,
ThresholdIDs: nil,
}
_, err := APItoResource(testStruct, "")
if err == nil || err.Error() != "Unsupported time format" {
t.Errorf("\nExpecting <Unsupported time format>,\n Received <%+v>", err)
}
}
func TestModelHelpersAPItoResourceError3(t *testing.T) {
testStruct := &utils.TPResourceProfile{
TPid: "",
Tenant: "",
ID: "",
FilterIDs: nil,
UsageTTL: "",
Limit: "cat",
AllocationMessage: "",
Blocker: false,
Stored: false,
Weight: 0,
ThresholdIDs: nil,
}
_, err := APItoResource(testStruct, "")
if err == nil || err.Error() != "strconv.ParseFloat: parsing \"cat\": invalid syntax" {
t.Errorf("\nExpecting <strconv.ParseFloat: parsing \"cat\": invalid syntax>,\n Received <%+v>", err)
}
}
func TestTpResourcesAsTpResources2(t *testing.T) {
testStruct := []*ResourceMdl{
{
Tpid: "TEST_TPID",
Tenant: "cgrates.org",
ID: "ResGroup1",
FilterIDs: "FLTR_RES_GR1",
ActivationInterval: "2014-07-27T15:00:00Z;2014-07-28T15:00:00Z",
ThresholdIDs: "WARN_RES1",
},
}
expStruct := []*utils.TPResourceProfile{
{
TPid: "TEST_TPID",
Tenant: "cgrates.org",
ID: "ResGroup1",
FilterIDs: []string{"FLTR_RES_GR1"},
ActivationInterval: &utils.TPActivationInterval{
ActivationTime: "2014-07-27T15:00:00Z",
ExpiryTime: "2014-07-28T15:00:00Z",
},
ThresholdIDs: []string{"WARN_RES1"},
},
}
result := ResourceMdls(testStruct).AsTPResources()
if !reflect.DeepEqual(result, expStruct) {
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ToJSON(expStruct), utils.ToJSON(result))
}
}
func TestModelHelpersMapTPAccountActionsError(t *testing.T) {
testStruct := []*utils.TPAccountActions{
{
TPid: "ee",
LoadId: "ee",
Tenant: "",
Account: "",
ActionPlanId: "",
ActionTriggersId: "",
AllowNegative: false,
Disabled: false,
},
{
TPid: "ee",
LoadId: "ee",
Tenant: "",
Account: "",
ActionPlanId: "",
ActionTriggersId: "",
AllowNegative: false,
Disabled: false,
},
}
_, err := MapTPAccountActions(testStruct)
if err == nil || err.Error() != "Non unique ID :" {
t.Errorf("\nExpecting <Non unique ID :>,\n Received <%+v>", err)
}
}
func TestModelHelpersMapTPSharedGroup2(t *testing.T) {
testStruct := []*utils.TPSharedGroups{
{
TPid: "",
ID: "2",
SharedGroups: []*utils.TPSharedGroup{
{
Account: "",
Strategy: "",
RatingSubject: "",
},
},
},
{
TPid: "",
ID: "2",
SharedGroups: []*utils.TPSharedGroup{
{
Account: "",
Strategy: "",
RatingSubject: "",
},
},
},
}
expStruct := map[string][]*utils.TPSharedGroup{
"2": []*utils.TPSharedGroup{
{
Account: "",
Strategy: "",
RatingSubject: "",
},
{
Account: "",
Strategy: "",
RatingSubject: "",
},
},
}
result := MapTPSharedGroup(testStruct)
if !reflect.DeepEqual(result, expStruct) {
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ToJSON(expStruct), utils.ToJSON(result))
}
}
func TestSharedGroupMdlsAsMapTPSharedGroups2(t *testing.T) {
testStruct := SharedGroupMdls{
{
Id: 2,
Tpid: "2",
Tag: "",
Account: "",
Strategy: "",
RatingSubject: "",
},
{
Id: 2,
Tpid: "2",
Tag: "",
Account: "",
Strategy: "",
RatingSubject: "",
},
}
expStruct := map[string]*utils.TPSharedGroups{
"": &utils.TPSharedGroups{
TPid: "2",
ID: "",
SharedGroups: []*utils.TPSharedGroup{
{
Account: "",
Strategy: "",
RatingSubject: "",
},
{
Account: "",
Strategy: "",
RatingSubject: "",
},
},
},
}
result := testStruct.AsMapTPSharedGroups()
if !reflect.DeepEqual(result, expStruct) {
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ToJSON(expStruct), utils.ToJSON(result))
}
}
func TestModelHelpersMapTPRatingProfilesError(t *testing.T) {
testStruct := []*utils.TPRatingProfile{
{
TPid: "2",
LoadId: "",
Tenant: "",
Category: "",
Subject: "",
RatingPlanActivations: nil,
},
{
TPid: "2",
LoadId: "",
Tenant: "",
Category: "",
Subject: "",
RatingPlanActivations: nil,
},
}
_, err := MapTPRatingProfiles(testStruct)
if err == nil || err.Error() != "Non unique id :*out:::" {
t.Errorf("\nExpecting <Non unique id :*out:::>,\n Received <%+v>", err)
}
}
func TestModelHelpersCSVLoadErrorInt(t *testing.T) {
type testStruct struct {
Id int64
Tpid string
Tag int `index:"0" re:"\w+\s*,\s*"`
CreatedAt time.Time
}
_, err := csvLoad(testStruct{}, []string{"TEST_DEST"})
if err == nil || err.Error() != "invalid value \"TEST_DEST\" for field testStruct.Tag" {
t.Errorf("\nExpecting <invalid value \"TEST_DEST\" for field testStruct.Tag>,\n Received <%+v>", err)
}
}
func TestModelHelpersCSVLoadErrorFloat64(t *testing.T) {
type testStruct struct {
Id int64
Tpid string
Tag float64 `index:"0" re:"\w+\s*,\s*"`
CreatedAt time.Time
}
_, err := csvLoad(testStruct{}, []string{"TEST_DEST"})
if err == nil || err.Error() != "invalid value \"TEST_DEST\" for field testStruct.Tag" {
t.Errorf("\nExpecting <invalid value \"TEST_DEST\" for field testStruct.Tag>,\n Received <%+v>", err)
}
}
func TestModelHelpersCSVLoadErrorBool(t *testing.T) {
type testStruct struct {
Id int64
Tpid string
Tag bool `index:"0" re:"\w+\s*,\s*"`
CreatedAt time.Time
}
_, err := csvLoad(testStruct{}, []string{"TEST_DEST"})
if err == nil || err.Error() != "invalid value \"TEST_DEST\" for field testStruct.Tag" {
t.Errorf("\nExpecting <invalid value \"TEST_DEST\" for field testStruct.Tag>,\n Received <%+v>", err)
}
}

View File

@@ -462,7 +462,7 @@ func (csvs *CSVStorage) GetTPDestinationRates(tpid, id string, p *utils.Paginato
}); err != nil {
return nil, err
}
return tpDestinationRates.AsTPDestinationRates()
return tpDestinationRates.AsTPDestinationRates(), nil
}
func (csvs *CSVStorage) GetTPRatingPlans(tpid, id string, p *utils.Paginator) ([]*utils.TPRatingPlan, error) {
@@ -474,7 +474,7 @@ func (csvs *CSVStorage) GetTPRatingPlans(tpid, id string, p *utils.Paginator) ([
}); err != nil {
return nil, err
}
return tpRatingPlans.AsTPRatingPlans()
return tpRatingPlans.AsTPRatingPlans(), nil
}
func (csvs *CSVStorage) GetTPRatingProfiles(filter *utils.TPRatingProfile) ([]*utils.TPRatingProfile, error) {
@@ -489,7 +489,7 @@ func (csvs *CSVStorage) GetTPRatingProfiles(filter *utils.TPRatingProfile) ([]*u
}); err != nil {
return nil, err
}
return tpRatingProfiles.AsTPRatingProfiles()
return tpRatingProfiles.AsTPRatingProfiles(), nil
}
func (csvs *CSVStorage) GetTPSharedGroups(tpid, id string) ([]*utils.TPSharedGroups, error) {
@@ -501,7 +501,7 @@ func (csvs *CSVStorage) GetTPSharedGroups(tpid, id string) ([]*utils.TPSharedGro
}); err != nil {
return nil, err
}
return tpSharedGroups.AsTPSharedGroups()
return tpSharedGroups.AsTPSharedGroups(), nil
}
func (csvs *CSVStorage) GetTPActions(tpid, id string) ([]*utils.TPActions, error) {
@@ -513,7 +513,7 @@ func (csvs *CSVStorage) GetTPActions(tpid, id string) ([]*utils.TPActions, error
}); err != nil {
return nil, err
}
return tpActions.AsTPActions()
return tpActions.AsTPActions(), nil
}
func (csvs *CSVStorage) GetTPActionPlans(tpid, id string) ([]*utils.TPActionPlan, error) {
@@ -525,7 +525,7 @@ func (csvs *CSVStorage) GetTPActionPlans(tpid, id string) ([]*utils.TPActionPlan
}); err != nil {
return nil, err
}
return tpActionPlans.AsTPActionPlans()
return tpActionPlans.AsTPActionPlans(), nil
}
func (csvs *CSVStorage) GetTPActionTriggers(tpid, id string) ([]*utils.TPActionTriggers, error) {
@@ -537,7 +537,7 @@ func (csvs *CSVStorage) GetTPActionTriggers(tpid, id string) ([]*utils.TPActionT
}); err != nil {
return nil, err
}
return tpActionTriggers.AsTPActionTriggers()
return tpActionTriggers.AsTPActionTriggers(), nil
}
func (csvs *CSVStorage) GetTPAccountActions(filter *utils.TPAccountActions) ([]*utils.TPAccountActions, error) {
@@ -552,7 +552,7 @@ func (csvs *CSVStorage) GetTPAccountActions(filter *utils.TPAccountActions) ([]*
}); err != nil {
return nil, err
}
return tpAccountActions.AsTPAccountActions()
return tpAccountActions.AsTPAccountActions(), nil
}
func (csvs *CSVStorage) GetTPResources(tpid, tenant, id string) ([]*utils.TPResourceProfile, error) {

View File

@@ -1261,14 +1261,11 @@ func (self *SQLStorage) GetTPDestinationRates(tpid, id string, pagination *utils
if err := q.Find(&tpDestinationRates).Error; err != nil {
return nil, err
}
if drs, err := tpDestinationRates.AsTPDestinationRates(); err != nil {
return nil, err
} else {
if len(drs) == 0 {
return drs, utils.ErrNotFound
}
return drs, nil
drs := tpDestinationRates.AsTPDestinationRates()
if len(drs) == 0 {
return drs, utils.ErrNotFound
}
return drs, nil
}
func (self *SQLStorage) GetTPTimings(tpid, id string) ([]*utils.ApierTPTiming, error) {
@@ -1304,14 +1301,12 @@ func (self *SQLStorage) GetTPRatingPlans(tpid, id string, pagination *utils.Pagi
q = q.Offset(*pagination.Offset)
}
}
if rps, err := tpRatingPlans.AsTPRatingPlans(); err != nil {
return nil, err
} else {
if len(rps) == 0 {
return rps, utils.ErrNotFound
}
return rps, nil
rps := tpRatingPlans.AsTPRatingPlans()
if len(rps) == 0 {
return rps, utils.ErrNotFound
}
return rps, nil
}
func (self *SQLStorage) GetTPRatingProfiles(filter *utils.TPRatingProfile) ([]*utils.TPRatingProfile, error) {
@@ -1332,14 +1327,11 @@ func (self *SQLStorage) GetTPRatingProfiles(filter *utils.TPRatingProfile) ([]*u
if err := q.Find(&tpRpfs).Error; err != nil {
return nil, err
}
if rps, err := tpRpfs.AsTPRatingProfiles(); err != nil {
return nil, err
} else {
if len(rps) == 0 {
return rps, utils.ErrNotFound
}
return rps, nil
rps := tpRpfs.AsTPRatingProfiles()
if len(rps) == 0 {
return rps, utils.ErrNotFound
}
return rps, nil
}
func (self *SQLStorage) GetTPSharedGroups(tpid, id string) ([]*utils.TPSharedGroups, error) {
@@ -1351,14 +1343,12 @@ func (self *SQLStorage) GetTPSharedGroups(tpid, id string) ([]*utils.TPSharedGro
if err := q.Find(&tpShareGroups).Error; err != nil {
return nil, err
}
if sgs, err := tpShareGroups.AsTPSharedGroups(); err != nil {
return nil, err
} else {
if len(sgs) == 0 {
return sgs, utils.ErrNotFound
}
return sgs, nil
sgs := tpShareGroups.AsTPSharedGroups()
if len(sgs) == 0 {
return sgs, utils.ErrNotFound
}
return sgs, nil
}
func (self *SQLStorage) GetTPActions(tpid, id string) ([]*utils.TPActions, error) {
@@ -1370,14 +1360,11 @@ func (self *SQLStorage) GetTPActions(tpid, id string) ([]*utils.TPActions, error
if err := q.Find(&tpActions).Error; err != nil {
return nil, err
}
if as, err := tpActions.AsTPActions(); err != nil {
return nil, err
} else {
if len(as) == 0 {
return as, utils.ErrNotFound
}
return as, nil
as := tpActions.AsTPActions()
if len(as) == 0 {
return as, utils.ErrNotFound
}
return as, nil
}
func (self *SQLStorage) GetTPActionTriggers(tpid, id string) ([]*utils.TPActionTriggers, error) {
@@ -1389,14 +1376,11 @@ func (self *SQLStorage) GetTPActionTriggers(tpid, id string) ([]*utils.TPActionT
if err := q.Find(&tpActionTriggers).Error; err != nil {
return nil, err
}
if ats, err := tpActionTriggers.AsTPActionTriggers(); err != nil {
return nil, err
} else {
if len(ats) == 0 {
return ats, utils.ErrNotFound
}
return ats, nil
ats := tpActionTriggers.AsTPActionTriggers()
if len(ats) == 0 {
return ats, utils.ErrNotFound
}
return ats, nil
}
func (self *SQLStorage) GetTPActionPlans(tpid, id string) ([]*utils.TPActionPlan, error) {
@@ -1408,14 +1392,11 @@ func (self *SQLStorage) GetTPActionPlans(tpid, id string) ([]*utils.TPActionPlan
if err := q.Find(&tpActionPlans).Error; err != nil {
return nil, err
}
if aps, err := tpActionPlans.AsTPActionPlans(); err != nil {
return nil, err
} else {
if len(aps) == 0 {
return aps, utils.ErrNotFound
}
return aps, nil
aps := tpActionPlans.AsTPActionPlans()
if len(aps) == 0 {
return aps, utils.ErrNotFound
}
return aps, nil
}
func (self *SQLStorage) GetTPAccountActions(filter *utils.TPAccountActions) ([]*utils.TPAccountActions, error) {
@@ -1433,14 +1414,11 @@ func (self *SQLStorage) GetTPAccountActions(filter *utils.TPAccountActions) ([]*
if err := q.Find(&tpAccActs).Error; err != nil {
return nil, err
}
if aas, err := tpAccActs.AsTPAccountActions(); err != nil {
return nil, err
} else {
if len(aas) == 0 {
return aas, utils.ErrNotFound
}
return aas, nil
aas := tpAccActs.AsTPAccountActions()
if len(aas) == 0 {
return aas, utils.ErrNotFound
}
return aas, nil
}
func (self *SQLStorage) GetTPResources(tpid, tenant, id string) ([]*utils.TPResourceProfile, error) {