-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings_test.go
44 lines (36 loc) · 1.21 KB
/
settings_test.go
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
package qawaylinter
import (
"go/types"
"testing"
)
func TestGetMatchingTarget(t *testing.T) {
settings := Settings{
Targets: []Rules{
{Packages: []string{"example.com/foo"}},
{Packages: []string{"example.com/foo/bar"}},
{Packages: []string{"example.com/foo/bar/baz"}},
},
}
pkg := types.NewPackage("example.com/foo/bar/baz/qux", "qux")
matchingTarget := settings.GetMatchingTarget(pkg)
expected := "example.com/foo/bar/baz"
if matchingTarget == nil || matchingTarget.Packages[0] != expected {
t.Errorf("Expected most concrete target to be %s, but got %v", expected, matchingTarget)
}
}
func TestFindMostConcreteTarget(t *testing.T) {
targets := []Rules{
{Packages: []string{"example.com/foo"}},
{Packages: []string{"example.com/foo/bar"}},
{Packages: []string{"example.com/foo/bar/baz"}},
}
matchingTargets := make(map[*Rules]string)
for i := range targets {
matchingTargets[&targets[i]] = targets[i].Packages[0]
}
mostConcreteTarget := findMostConcreteTarget(matchingTargets)
expected := "example.com/foo/bar/baz"
if mostConcreteTarget == nil || mostConcreteTarget.Packages[0] != expected {
t.Errorf("Expected most concrete target to be %s, but got %v", expected, mostConcreteTarget)
}
}