Started testing the loaders implementation

This commit is contained in:
Trial97
2021-11-10 17:02:17 +02:00
committed by Dan Christian Bogos
parent 96e50f3962
commit bcdf7910d1
20 changed files with 883 additions and 1465 deletions

View File

@@ -1322,7 +1322,7 @@ func APItoModelTPCharger(tpCPP *utils.TPChargerProfile) (mdls ChargerMdls) {
return
}
func APItoChargerProfile(tpCPP *utils.TPChargerProfile, timezone string) (cpp *ChargerProfile, err error) {
func APItoChargerProfile(tpCPP *utils.TPChargerProfile, timezone string) (cpp *ChargerProfile) {
cpp = &ChargerProfile{
Tenant: tpCPP.Tenant,
ID: tpCPP.ID,
@@ -1337,7 +1337,7 @@ func APItoChargerProfile(tpCPP *utils.TPChargerProfile, timezone string) (cpp *C
for i, attribute := range tpCPP.AttributeIDs {
cpp.AttributeIDs[i] = attribute
}
return cpp, nil
return cpp
}
func ChargerProfileToAPI(chargerPrf *ChargerProfile) (tpCharger *utils.TPChargerProfile) {
@@ -1519,7 +1519,7 @@ func APItoModelTPDispatcherProfile(tpDPP *utils.TPDispatcherProfile) (mdls Dispa
return
}
func APItoDispatcherProfile(tpDPP *utils.TPDispatcherProfile, timezone string) (dpp *DispatcherProfile, err error) {
func APItoDispatcherProfile(tpDPP *utils.TPDispatcherProfile, timezone string) (dpp *DispatcherProfile) {
dpp = &DispatcherProfile{
Tenant: tpDPP.Tenant,
ID: tpDPP.ID,
@@ -1560,7 +1560,7 @@ func APItoDispatcherProfile(tpDPP *utils.TPDispatcherProfile, timezone string) (
}
}
return dpp, nil
return dpp
}
func DispatcherProfileToAPI(dpp *DispatcherProfile) (tpDPP *utils.TPDispatcherProfile) {

View File

@@ -1334,9 +1334,7 @@ func TestAPItoChargerProfile(t *testing.T) {
AttributeIDs: []string{"ATTR1", "ATTR2"},
Weight: 20,
}
if rcv, err := APItoChargerProfile(tpCPP, "UTC"); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expected, rcv) {
if rcv := APItoChargerProfile(tpCPP, "UTC"); !reflect.DeepEqual(expected, rcv) {
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rcv))
}
}
@@ -1701,9 +1699,7 @@ func TestAPItoDispatcherProfile(t *testing.T) {
},
},
}
if rcv, err := APItoDispatcherProfile(tpDPP, "UTC"); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expected, rcv) {
if rcv := APItoDispatcherProfile(tpDPP, "UTC"); !reflect.DeepEqual(expected, rcv) {
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rcv))
}
}
@@ -3392,7 +3388,7 @@ func TestAPItoDispatcherProfileCase2(t *testing.T) {
},
},
}
result, _ := APItoDispatcherProfile(structTest, "")
result := APItoDispatcherProfile(structTest, "")
if !reflect.DeepEqual(result, expStruct) {
t.Errorf("\nExpecting <%+v>>,\n Received <%+v>", utils.ToJSON(expStruct), utils.ToJSON(result))
}
@@ -4008,7 +4004,7 @@ func TestAPItoAttributeProfileError2(t *testing.T) {
}
_, err := APItoAttributeProfile(tpAlsPrf, "UTC")
expected := "Closed unspilit syntax "
expected := "Closed unspilit syntax"
if err == nil || err.Error() != expected {
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", expected, err)
}

View File

@@ -486,10 +486,7 @@ func (tpr *TpReader) WriteToDatabase(verbose, disableReverse bool) (err error) {
log.Print("ChargerProfiles:")
}
for _, tpTH := range tpr.chargerProfiles {
var th *ChargerProfile
if th, err = APItoChargerProfile(tpTH, tpr.timezone); err != nil {
return
}
th := APItoChargerProfile(tpTH, tpr.timezone)
if err = tpr.dm.SetChargerProfile(context.TODO(), th, true); err != nil {
return
}
@@ -504,10 +501,7 @@ func (tpr *TpReader) WriteToDatabase(verbose, disableReverse bool) (err error) {
log.Print("DispatcherProfiles:")
}
for _, tpTH := range tpr.dispatcherProfiles {
var th *DispatcherProfile
if th, err = APItoDispatcherProfile(tpTH, tpr.timezone); err != nil {
return
}
th := APItoDispatcherProfile(tpTH, tpr.timezone)
if err = tpr.dm.SetDispatcherProfile(context.TODO(), th, true); err != nil {
return
}

View File

@@ -324,10 +324,7 @@ func testLoaderITWriteToDatabase(t *testing.T) {
if err != nil {
t.Errorf("Failed GetChargerProfile, tenant: %s, id: %s, error: %s ", cpp.Tenant, cpp.ID, err.Error())
}
cp, err := APItoChargerProfile(cpp, "UTC")
if err != nil {
t.Error(err)
}
cp := APItoChargerProfile(cpp, "UTC")
if !reflect.DeepEqual(cp, rcv) {
t.Errorf("Expecting: %v, received: %v", cp, rcv)
}
@@ -338,10 +335,7 @@ func testLoaderITWriteToDatabase(t *testing.T) {
if err != nil {
t.Errorf("Failed GetDispatcherProfile, tenant: %s, id: %s, error: %s ", dpp.Tenant, dpp.ID, err.Error())
}
dp, err := APItoDispatcherProfile(dpp, "UTC")
if err != nil {
t.Error(err)
}
dp := APItoDispatcherProfile(dpp, "UTC")
if !reflect.DeepEqual(dp, rcv) {
t.Errorf("Expecting: %v, received: %v", dp, rcv)
}