Skip to content

Commit

Permalink
Added test for AsMapDestinations
Browse files Browse the repository at this point in the history
  • Loading branch information
adragusin committed Jul 1, 2020
1 parent 4ca51d2 commit 78276ed
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions engine/model_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,99 @@ func TestTPDestinationAsExportSlice(t *testing.T) {
}
}

func TestTpDestinationsAsMapDestinations(t *testing.T) {
in := &TpDestinations{}
eOut := map[string]*Destination{}

if rcv, err := in.AsMapDestinations(); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(rcv, eOut) {
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(eOut), utils.ToJSON(rcv))
}
in = &TpDestinations{
TpDestination{Tpid: "TEST_TPID", Tag: "TEST_DEST1", Prefix: "+491"},
TpDestination{Tpid: "TEST_TPID", Tag: "TEST_DEST2", Prefix: "+492"},
}
eOut = map[string]*Destination{
"TEST_DEST1": &Destination{
Id: "TEST_DEST1",
Prefixes: []string{"+491"},
},
"TEST_DEST2": &Destination{
Id: "TEST_DEST2",
Prefixes: []string{"+492"},
},
}
var rcv map[string]*Destination
if rcv, err = in.AsMapDestinations(); err != nil {
t.Error(err)
}
for key := range rcv {
if !reflect.DeepEqual(rcv[key], eOut[key]) {
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(eOut[key]), utils.ToJSON(rcv[key]))
}
}
in = &TpDestinations{
TpDestination{Tpid: "TEST_TPID", Tag: "TEST_DEST1", Prefix: "+491"},
TpDestination{Tpid: "TEST_TPID", Tag: "TEST_DEST2", Prefix: "+492"},
TpDestination{Tpid: "TEST_ID", Tag: "", Prefix: ""},
}
eOut = map[string]*Destination{
"TEST_DEST1": &Destination{
Id: "TEST_DEST1",
Prefixes: []string{"+491"},
},
"TEST_DEST2": &Destination{
Id: "TEST_DEST2",
Prefixes: []string{"+492"},
},
"": &Destination{
Id: "",
Prefixes: []string{""},
},
}
if rcv, err = in.AsMapDestinations(); err != nil {
t.Error(err)
}
for key, _ := range rcv {
if !reflect.DeepEqual(rcv[key], eOut[key]) {
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(eOut[key]), utils.ToJSON(rcv[key]))
}
}
}

func TestTpDestinationsAPItoModelDestination(t *testing.T) {
d := &utils.TPDestination{}
eOut := TpDestinations{
TpDestination{},
}
if rcv := APItoModelDestination(d); rcv != nil {
if !reflect.DeepEqual(rcv, eOut) {
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(eOut), utils.ToJSON(rcv))
}

}
d = &utils.TPDestination{
TPid: "TEST_TPID",
ID: "TEST_ID",
Prefixes: []string{"+491"},
}
eOut = TpDestinations{
TpDestination{
Tpid: "TEST_TPID",
Tag: "TEST_ID",
Prefix: "+491",
},
}
if rcv := APItoModelDestination(d); rcv != nil {
if !reflect.DeepEqual(rcv, eOut) {
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(eOut), utils.ToJSON(rcv))
}

}

}

func TestTpDestinationsAsTPDestinations(t *testing.T) {
tpd1 := TpDestination{Tpid: "TEST_TPID", Tag: "TEST_DEST", Prefix: "+491"}
tpd2 := TpDestination{Tpid: "TEST_TPID", Tag: "TEST_DEST", Prefix: "+492"}
Expand Down

0 comments on commit 78276ed

Please sign in to comment.