File tree Expand file tree Collapse file tree 2 files changed +39
-6
lines changed
dd-java-agent/agent-ci-visibility/src
main/java/datadog/trace/civisibility
test/groovy/datadog/trace/civisibility Expand file tree Collapse file tree 2 files changed +39
-6
lines changed Original file line number Diff line number Diff line change @@ -89,18 +89,18 @@ public class CiVisibilityRepoServices {
8989 }
9090 }
9191
92- private static String getModuleName (Config config , Path path , CIInfo ciInfo ) {
92+ static String getModuleName (Config config , Path path , CIInfo ciInfo ) {
9393 // if parent process is instrumented, it will provide build system's module name
9494 String parentModuleName = config .getCiVisibilityModuleName ();
9595 if (parentModuleName != null ) {
9696 return parentModuleName ;
9797 }
9898 String repoRoot = ciInfo .getNormalizedCiWorkspace ();
99- if (repoRoot != null
100- && path . startsWith (repoRoot )
101- // module name cannot be empty
102- && ! path . toString (). equals ( repoRoot )) {
103- return Paths . get ( repoRoot ). relativize ( path ). toString ();
99+ if (repoRoot != null && path . startsWith ( repoRoot )) {
100+ String relativePath = Paths . get (repoRoot ). relativize ( path ). toString ();
101+ if (! relativePath . isEmpty ()) {
102+ return relativePath ;
103+ }
104104 }
105105 return config .getServiceName ();
106106 }
Original file line number Diff line number Diff line change 1+ package datadog.trace.civisibility
2+
3+
4+ import datadog.trace.api.Config
5+ import datadog.trace.civisibility.ci.CIInfo
6+ import spock.lang.Specification
7+
8+ import java.nio.file.Paths
9+
10+ class CiVisibilityRepoServicesTest extends Specification {
11+
12+ def " test get parent module name: #parentModuleName, #repoSubFolder, #serviceName" () {
13+ given :
14+ def config = Stub (Config )
15+ config. getCiVisibilityModuleName() >> parentModuleName
16+ config. getServiceName() >> serviceName
17+
18+ def repoRoot = " /path/to/repo/root/"
19+ def path = Paths . get(repoRoot + repoSubFolder)
20+
21+ def ciInfo = Stub (CIInfo )
22+ ciInfo. getNormalizedCiWorkspace() >> repoRoot
23+
24+ expect :
25+ CiVisibilityRepoServices . getModuleName(config, path, ciInfo) == moduleName
26+
27+ where :
28+ parentModuleName | repoSubFolder | serviceName | moduleName
29+ " parent-module" | " child-module" | " service-name" | " parent-module"
30+ null | " child-module" | " service-name" | " child-module"
31+ null | " " | " service-name" | " service-name"
32+ }
33+ }
You can’t perform that action at this time.
0 commit comments