aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/subsystem/entities_test.go
blob: a15b25ea7fda833845fbcb602919cbcfc3ceb23d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2023 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

package subsystem

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestReachableParents(t *testing.T) {
	parentParent := &Subsystem{}
	parentA := &Subsystem{Parents: []*Subsystem{parentParent}}
	parentB := &Subsystem{Parents: []*Subsystem{parentParent}}
	entity := &Subsystem{Parents: []*Subsystem{parentA, parentB}}

	retParents := []*Subsystem{}
	for item := range entity.ReachableParents() {
		retParents = append(retParents, item)
	}
	assert.ElementsMatch(t, retParents, []*Subsystem{parentA, parentB, parentParent})
}

func TestSubsystemEmails(t *testing.T) {
	parentParent := &Subsystem{Lists: []string{"a@list.com"}, Maintainers: []string{"a@person.com"}}
	parent1 := &Subsystem{Lists: []string{"b@list.com"}, Maintainers: []string{"b@person.com"}}
	parent2 := &Subsystem{
		Lists:       []string{"c@list.com"},
		Maintainers: []string{"c@person.com"},
		Parents:     []*Subsystem{parentParent},
	}
	parent3 := &Subsystem{
		Lists:        []string{"d@list.com"},
		NoIndirectCc: true,
	}
	subsystem := &Subsystem{
		Lists:       []string{"e@list.com"},
		Maintainers: []string{"e@person.com"},
		Parents:     []*Subsystem{parent1, parent2, parent3},
	}
	assert.ElementsMatch(t, subsystem.Emails(), []string{
		"a@list.com", "b@list.com", "c@list.com", "e@list.com", "e@person.com",
	})
}

func TestFilterList(t *testing.T) {
	parentParent := &Subsystem{}
	parentA := &Subsystem{Parents: []*Subsystem{parentParent}}
	parentB := &Subsystem{Parents: []*Subsystem{parentParent}}
	entity := &Subsystem{Parents: []*Subsystem{parentA, parentB}}

	newList := FilterList([]*Subsystem{parentA, parentB, parentParent, entity},
		func(s *Subsystem) bool {
			return s != parentB
		},
	)
	assert.Len(t, newList, 3)
	assert.ElementsMatch(t, entity.Parents, []*Subsystem{parentA})
}