@@ -27,6 +27,7 @@ import (
27
27
"github.com/bufbuild/buf/private/bufpkg/bufmodule"
28
28
"github.com/bufbuild/buf/private/bufpkg/bufmodule/bufmoduletesting"
29
29
"github.com/bufbuild/buf/private/pkg/protoencoding"
30
+ "github.com/bufbuild/buf/private/pkg/slicesext"
30
31
"github.com/bufbuild/buf/private/pkg/slogtestext"
31
32
"github.com/bufbuild/buf/private/pkg/storage"
32
33
"github.com/bufbuild/buf/private/pkg/storage/storageos"
@@ -161,6 +162,11 @@ func TestSourceCodeInfo(t *testing.T) {
161
162
runSourceCodeInfoTest (t , "foo.bar" , "all.txtar" )
162
163
}
163
164
165
+ func TestUnusedDeps (t * testing.T ) {
166
+ t .Parallel ()
167
+ runDiffTest (t , "testdata/unuseddeps" , []string {"a.A" }, "a.txtar" )
168
+ }
169
+
164
170
func TestTransitivePublic (t * testing.T ) {
165
171
t .Parallel ()
166
172
ctx := context .Background ()
@@ -264,16 +270,23 @@ func runDiffTest(t *testing.T, testdataDir string, typenames []string, expectedF
264
270
assert .NotNil (t , image )
265
271
assert .True (t , imageIsDependencyOrdered (filteredImage ), "image files not in dependency order" )
266
272
273
+ // Convert the filtered image back to a proto image and then back to an image to ensure that the
274
+ // image is still valid after filtering.
275
+ protoImage , err := bufimage .ImageToProtoImage (filteredImage )
276
+ require .NoError (t , err )
277
+ filteredImage , err = bufimage .NewImageForProto (protoImage )
278
+ require .NoError (t , err )
279
+
267
280
// We may have filtered out custom options from the set in the step above. However, the options messages
268
281
// still contain extension fields that refer to the custom options, as a result of building the image.
269
282
// So we serialize and then de-serialize, and use only the filtered results to parse extensions. That
270
283
// way, the result will omit custom options that aren't present in the filtered set (as they will be
271
284
// considered unrecognized fields).
272
- data , err := protoencoding . NewWireMarshaler (). Marshal ( bufimage . ImageToFileDescriptorSet ( filteredImage ))
273
- require . NoError ( t , err )
274
- fileDescriptorSet := & descriptorpb. FileDescriptorSet {}
275
- err = protoencoding . NewWireUnmarshaler ( filteredImage . Resolver ()). Unmarshal ( data , fileDescriptorSet )
276
- require . NoError ( t , err )
285
+ fileDescriptorSet := & descriptorpb. FileDescriptorSet {
286
+ File : slicesext . Map ( filteredImage . Files (), func ( imageFile bufimage. ImageFile ) * descriptorpb. FileDescriptorProto {
287
+ return imageFile . FileDescriptorProto ()
288
+ }),
289
+ }
277
290
278
291
files , err := protodesc .NewFiles (fileDescriptorSet )
279
292
require .NoError (t , err )
0 commit comments