|
17 | 17 | import java.util.ArrayList; |
18 | 18 | import java.util.Arrays; |
19 | 19 | import java.util.Comparator; |
20 | | -import java.util.HashSet; |
21 | 20 | import java.util.List; |
22 | 21 | import java.util.Map; |
23 | 22 | import java.util.Set; |
@@ -78,7 +77,9 @@ private static <T extends HasMetadata> List<T> resourcesFromFiles(Set<Path> path |
78 | 77 | // should never see an invalid resource in production |
79 | 78 | List<T> resources = paths.stream().map(Path::toFile).map(file -> { |
80 | 79 | try { |
81 | | - return YAML_MAPPER.readValue(file, valueType); |
| 80 | + T resource = YAML_MAPPER.readValue(file, valueType); |
| 81 | + assertMinimalMetadata(resource.getMetadata(), file.toPath().toString()); |
| 82 | + return resource; |
82 | 83 | } |
83 | 84 | catch (IOException e) { |
84 | 85 | throw new UncheckedIOException("Error reading " + file, e); |
@@ -199,10 +200,8 @@ private static List<DynamicTest> testsForDir(List<DesiredFn<KafkaProxy, ?>> depe |
199 | 200 | throws IOException { |
200 | 201 | try { |
201 | 202 | var unusedFiles = TestFiles.childFilesMatching(testDir, "*"); |
202 | | - String inFileName = "in-KafkaProxy.yaml"; |
203 | | - Path input = testDir.resolve(inFileName); |
| 203 | + Path input = testDir.resolve("in-KafkaProxy.yaml"); |
204 | 204 | KafkaProxy kafkaProxy = resourceFromFile(input, KafkaProxy.class); |
205 | | - assertMinimalMetadata(kafkaProxy.getMetadata(), inFileName); |
206 | 205 | List<VirtualKafkaCluster> virtualKafkaClusters = resourcesFromFiles(TestFiles.childFilesMatching(testDir, "in-VirtualKafkaCluster-*"), |
207 | 206 | VirtualKafkaCluster.class); |
208 | 207 | List<KafkaService> kafkaServiceRefs = resourcesFromFiles(TestFiles.childFilesMatching(testDir, "in-KafkaService-*"), KafkaService.class); |
@@ -298,15 +297,9 @@ private static Context<KafkaProxy> buildContext(Path testDir, |
298 | 297 | var resourceContext = new DefaultManagedWorkflowAndDependentResourceContext(null, null, context); |
299 | 298 | doReturn(resourceContext).when(context).managedWorkflowAndDependentResourceContext(); |
300 | 299 |
|
301 | | - Set<KafkaProtocolFilter> filterInstances = new HashSet<>(); |
302 | | - String fileName = "in-" + HasMetadata.getKind(KafkaProtocolFilter.class) + "-*.yaml"; |
303 | | - try (var dirStream = Files.newDirectoryStream(testDir, fileName)) { |
304 | | - for (Path p : dirStream) { |
305 | | - KafkaProtocolFilter resource = YAML_MAPPER.readValue(p.toFile(), KafkaProtocolFilter.class); |
306 | | - assertMinimalMetadata(resource.getMetadata(), fileName); |
307 | | - filterInstances.add(resource); |
308 | | - } |
309 | | - } |
| 300 | + Set<KafkaProtocolFilter> filterInstances = Set.copyOf(resourcesFromFiles(TestFiles.childFilesMatching(testDir, |
| 301 | + "in-" + HasMetadata.getKind(KafkaProtocolFilter.class) + "-*.yaml"), KafkaProtocolFilter.class)); |
| 302 | + |
310 | 303 | doReturn(filterInstances).when(context).getSecondaryResources(KafkaProtocolFilter.class); |
311 | 304 | doReturn(Set.copyOf(virtualKafkaClusters)).when(context).getSecondaryResources(VirtualKafkaCluster.class); |
312 | 305 | doReturn(Set.copyOf(kafkaServiceRefs)).when(context).getSecondaryResources(KafkaService.class); |
|
0 commit comments