I got some test failures when building this project on Windows which works fine on Linux.
In JGitEnvironmentRepositoryTests
I got:
org.opentest4j.AssertionFailedError:
expected: "file:././target/repos/another-config-repo/sub/application.yml"
but was: "file:././target/repos/another-config-repo/file:D:\test\spring-cloud-config\spring-cloud-config-server\target\repos\another-config-repo\sub\application.yml"
at org.springframework.cloud.config.server.environment.JGitEnvironmentRepositoryTests.placeholderInSearchPath(JGitEnvironmentRepositoryTests.java:155)
org.opentest4j.AssertionFailedError:
expected: "file:././target/repos/config-repo/bar.properties"
but was: "file:././target/repos/config-repo/file:D:\test\spring-cloud-config\spring-cloud-config-server\target\repos\config-repo\bar.properties"
at org.springframework.cloud.config.server.environment.JGitEnvironmentRepositoryTests.branch(JGitEnvironmentRepositoryTests.java:183)
... and other similar 6 errors. It seems they have the same path problem.
Comment From: woshikid
The direct reason causes these failures is in EnvironmentCleaner#clean
public Environment clean(Environment value, String workingDir, String uri) {
Environment result = new Environment(value);
for (PropertySource source : value.getPropertySources()) {
// source.getName() = file:D:\test\spring-cloud-config\spring-cloud-config-server\target\repos\config-repo\bar.properties
// workingDir = file:/D:/test/spring-cloud-config/spring-cloud-config-server/target/repos/config-repo/
// the replace() here matches nothing
String name = source.getName().replace(workingDir, ""); // try to get filename: bar.properties
name = name.replace("applicationConfig: [", "");
name = uri + "/" + name.replace("]", "");
result.add(new PropertySource(name, clean(source.getSource(), uri)));
}
return result;
}
Comment From: woshikid
the workingDir is in URI format
// AbstractScmEnvironmentRepository#findOne
return this.cleaner.clean(result, getWorkingDirectory().toURI().toString(), getUri());
but PropertySource
's name is in windows path format
// StandardConfigDataResource
@Override
public String toString() {
if (this.resource instanceof FileSystemResource || this.resource instanceof FileUrlResource) {
try {
return "file [" + this.resource.getFile().toString() + "]"; // not using toURI()
}
catch (IOException ex) {
}
}
return this.resource.toString();
}
the best way to fix this issue is to change spring boot's StandardConfigDataResource
, but that may have lots side effects.
to solve the path problem within this project, I suggest to add some code in NativeEnvironmentRepository#clean
to change windows path format into uri format
// change windows path format into uri format
name = name.replace("\\", "/");
name = name.replaceAll("\\[/?", "[/");
// original source code below
name = name.replace("applicationConfig: [", "");
name = name.replace("file [", "file:");
name = name.replace("class path resource [", "classpath:/");