github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/pkg/subsystem/entities_test.go (about) 1 // Copyright 2023 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 package subsystem 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestReachableParents(t *testing.T) { 13 parentParent := &Subsystem{} 14 parentA := &Subsystem{Parents: []*Subsystem{parentParent}} 15 parentB := &Subsystem{Parents: []*Subsystem{parentParent}} 16 entity := &Subsystem{Parents: []*Subsystem{parentA, parentB}} 17 18 retParents := []*Subsystem{} 19 for item := range entity.ReachableParents() { 20 retParents = append(retParents, item) 21 } 22 assert.ElementsMatch(t, retParents, []*Subsystem{parentA, parentB, parentParent}) 23 } 24 25 func TestSubsystemEmails(t *testing.T) { 26 parentParent := &Subsystem{Lists: []string{"a@list.com"}, Maintainers: []string{"a@person.com"}} 27 parent1 := &Subsystem{Lists: []string{"b@list.com"}, Maintainers: []string{"b@person.com"}} 28 parent2 := &Subsystem{ 29 Lists: []string{"c@list.com"}, 30 Maintainers: []string{"c@person.com"}, 31 Parents: []*Subsystem{parentParent}, 32 } 33 parent3 := &Subsystem{ 34 Lists: []string{"d@list.com"}, 35 NoIndirectCc: true, 36 } 37 subsystem := &Subsystem{ 38 Lists: []string{"e@list.com"}, 39 Maintainers: []string{"e@person.com"}, 40 Parents: []*Subsystem{parent1, parent2, parent3}, 41 } 42 assert.ElementsMatch(t, subsystem.Emails(), []string{ 43 "a@list.com", "b@list.com", "c@list.com", "e@list.com", "e@person.com", 44 }) 45 } 46 47 func TestFilterList(t *testing.T) { 48 parentParent := &Subsystem{} 49 parentA := &Subsystem{Parents: []*Subsystem{parentParent}} 50 parentB := &Subsystem{Parents: []*Subsystem{parentParent}} 51 entity := &Subsystem{Parents: []*Subsystem{parentA, parentB}} 52 53 newList := FilterList([]*Subsystem{parentA, parentB, parentParent, entity}, 54 func(s *Subsystem) bool { 55 return s != parentB 56 }, 57 ) 58 assert.Len(t, newList, 3) 59 assert.ElementsMatch(t, entity.Parents, []*Subsystem{parentA}) 60 }