-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resolver_test.go
158 lines (148 loc) · 4.59 KB
/
resolver_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package bufresolv
import (
"slices"
"testing"
)
func TestBufLock(t *testing.T) {
t.Run("v1", func(t *testing.T) {
r, err := New(BufLock("testdata/bufroot/helloapis/buf.lock"))
if err != nil {
t.Fatal(err)
}
paths := r.Paths()
if !slices.Contains(paths, "buf/validate/validate.proto") {
t.Errorf("buf/validate/validate.proto not found in %v", paths)
}
if slices.Contains(paths, "acme/hello/v2/hello.proto") {
t.Errorf("acme/hello/v2/hello.proto found in %v", paths)
}
if slices.Contains(paths, "acme/world/v1/world.proto") {
t.Errorf("acme/world/v1/world.proto found in %v", paths)
}
})
t.Run("v2", func(t *testing.T) {
r, err := New(BufLock("testdata/bufroot_v2/buf.lock"))
if err != nil {
t.Fatal(err)
}
paths := r.Paths()
if !slices.Contains(paths, "buf/validate/validate.proto") {
t.Errorf("buf/validate/validate.proto not found in %v", paths)
}
if slices.Contains(paths, "acme/hello/v2/hello.proto") {
t.Errorf("acme/hello/v2/hello.proto found in %v", paths)
}
if slices.Contains(paths, "acme/world/v1/world.proto") {
t.Errorf("acme/world/v1/world.proto found in %v", paths)
}
})
}
func TestBufConfig(t *testing.T) {
t.Run("v1", func(t *testing.T) {
r, err := New(BufConfig("testdata/bufroot/helloapis/buf.yaml"))
if err != nil {
t.Fatal(err)
}
paths := r.Paths()
if !slices.Contains(paths, "buf/validate/validate.proto") {
t.Errorf("buf/validate/validate.proto not found in %v", paths)
}
if slices.Contains(paths, "acme/hello/v2/hello.proto") {
t.Errorf("acme/hello/v2/hello.proto found in %v", paths)
}
if slices.Contains(paths, "acme/world/v1/world.proto") {
t.Errorf("acme/world/v1/world.proto found in %v", paths)
}
})
t.Run("v2", func(t *testing.T) {
r, err := New(BufConfig("testdata/bufroot_v2/buf.yaml"))
if err != nil {
t.Fatal(err)
}
paths := r.Paths()
if !slices.Contains(paths, "buf/validate/validate.proto") {
t.Errorf("buf/validate/validate.proto not found in %v", paths)
}
if !slices.Contains(paths, "acme/hello/v2/hello.proto") {
t.Errorf("acme/hello/v2/hello.proto not found in %v", paths)
}
if !slices.Contains(paths, "acme/world/v1/world.proto") {
t.Errorf("acme/world/v1/world.proto not found in %v", paths)
}
})
t.Run("v2 no modules", func(t *testing.T) {
r, err := New(BufConfig("testdata/bufroot_v2_no_modules/buf.yaml"))
if err != nil {
t.Fatal(err)
}
paths := r.Paths()
if !slices.Contains(paths, "buf/validate/validate.proto") {
t.Errorf("buf/validate/validate.proto not found in %v", paths)
}
if !slices.Contains(paths, "helloapis/acme/hello/v2/hello.proto") {
t.Errorf("helloapis/acme/hello/v2/hello.proto not found in %v", paths)
}
if !slices.Contains(paths, "worldapis/acme/world/v1/world.proto") {
t.Errorf("worldapis/acme/world/v1/world.proto not found in %v", paths)
}
})
}
func TestModule(t *testing.T) {
r, err := New(BufModule("buf.build/bufbuild/protovalidate/tree/b983156c5e994cc9892e0ce3e64e17e0"))
if err != nil {
t.Fatal(err)
}
paths := r.Paths()
if !slices.Contains(paths, "buf/validate/validate.proto") {
t.Errorf("buf/validate/validate.proto not found in %v", paths)
}
}
func TestBufDir(t *testing.T) {
t.Run("v1", func(t *testing.T) {
r, err := New(BufDir("testdata/bufroot"))
if err != nil {
t.Fatal(err)
}
paths := r.Paths()
if !slices.Contains(paths, "buf/validate/validate.proto") {
t.Errorf("buf/validate/validate.proto not found in %v", paths)
}
if !slices.Contains(paths, "acme/hello/v2/hello.proto") {
t.Errorf("acme/hello/v2/hello.proto not found in %v", paths)
}
if !slices.Contains(paths, "acme/world/v1/world.proto") {
t.Errorf("acme/world/v1/world.proto not found in %v", paths)
}
})
t.Run("v2", func(t *testing.T) {
r, err := New(BufDir("testdata/bufroot_v2"))
if err != nil {
t.Fatal(err)
}
paths := r.Paths()
if !slices.Contains(paths, "buf/validate/validate.proto") {
t.Errorf("buf/validate/validate.proto not found in %v", paths)
}
if !slices.Contains(paths, "acme/hello/v2/hello.proto") {
t.Errorf("acme/hello/v2/hello.proto not found in %v", paths)
}
if !slices.Contains(paths, "acme/world/v1/world.proto") {
t.Errorf("acme/world/v1/world.proto not found in %v", paths)
}
})
}
func TestPaths(t *testing.T) {
r, err := New(BufConfig("testdata/bufroot/helloapis/buf.yaml"))
if err != nil {
t.Fatal(err)
}
got := len(r.Paths())
r2, err := New(BufConfig("testdata/bufroot/helloapis/buf.yaml"), BufConfig("testdata/bufroot/helloapis/buf.yaml"))
if err != nil {
t.Fatal(err)
}
got2 := len(r2.Paths())
if got != got2 {
t.Errorf("got %d, want %d", got2, got)
}
}