Fix handling trackers. Test cover

This commit is contained in:
rumanzo 2022-04-04 17:09:05 +03:00
parent f2decc007c
commit 2d91e47377
2 changed files with 14 additions and 4 deletions

View File

@ -144,15 +144,20 @@ func (transfer *TransferStructure) HandleLabels() {
// GetTrackers recurstive function for searching trackers in resume item trackers // GetTrackers recurstive function for searching trackers in resume item trackers
func (transfer *TransferStructure) GetTrackers(trackers interface{}) { func (transfer *TransferStructure) GetTrackers(trackers interface{}) {
switch strct := trackers.(type) { switch strct := trackers.(type) {
case []interface{}: case []string:
for _, st := range strct { for _, str := range strct {
transfer.GetTrackers(st) for _, str := range strings.Fields(str) {
transfer.Fastresume.Trackers = append(transfer.Fastresume.Trackers, []string{str})
}
} }
case string: case string:
for _, str := range strings.Fields(strct) { for _, str := range strings.Fields(strct) {
transfer.Fastresume.Trackers = append(transfer.Fastresume.Trackers, []string{str}) transfer.Fastresume.Trackers = append(transfer.Fastresume.Trackers, []string{str})
} }
case []interface{}:
for _, st := range strct {
transfer.GetTrackers(st)
}
} }
} }

View File

@ -1139,6 +1139,9 @@ func TestTransferStructure_GetTrackers(t *testing.T) {
"test6", "test6",
}, },
}, },
[]interface{}{
[]interface{}{"test7", "test8"},
},
} }
expect := [][]string{ expect := [][]string{
[]string{"test1"}, []string{"test1"},
@ -1147,6 +1150,8 @@ func TestTransferStructure_GetTrackers(t *testing.T) {
[]string{"test4"}, []string{"test4"},
[]string{"test5"}, []string{"test5"},
[]string{"test6"}, []string{"test6"},
[]string{"test7"},
[]string{"test8"},
} }
transferStructure.GetTrackers(testTrackers) transferStructure.GetTrackers(testTrackers)
if !reflect.DeepEqual(transferStructure.Fastresume.Trackers, expect) { if !reflect.DeepEqual(transferStructure.Fastresume.Trackers, expect) {