-
Notifications
You must be signed in to change notification settings - Fork 705
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(config/test): provide a non-null halconfigDirectory in HalconfigP…
…arserMocker (#2172) * test(config): validate spring config behavior with HalconfigDirectoryStructure to pave the way for some refactoring to support java 17 * refactor(config): use constructor injection in HalconfigParser as a general improvement and also to pave the way to cleanly specify a non-null halconfigDirectory during testing. * refactor(config): use constructor injection in HalconfigDirectoryStructure as a general improvement and also to pave the way to cleanly specify a non-null halconfigDirectory during testing. * fix(config/test): provide a non-null halconfigDirectory in HalconfigParserMocker since tests like this fail in java 17 otherwise: > Task :halyard-config:test AccountServiceSpec > load an existent account node FAILED java.lang.NullPointerException at java.base/java.util.Objects.requireNonNull(Objects.java:209) at java.base/sun.nio.fs.UnixFileSystem.getPath(UnixFileSystem.java:263) at java.base/java.nio.file.Path.of(Path.java:147) at java.base/java.nio.file.Paths.get(Paths.java:69) at com.netflix.spinnaker.halyard.config.config.v1.HalconfigDirectoryStructure.getHalconfigPath(HalconfigDirectoryStructure.java:50) at com.netflix.spinnaker.halyard.config.config.v1.HalconfigParser.transformHalconfig(HalconfigParser.java:159) at com.netflix.spinnaker.halyard.config.services.v1.HalconfigParserMocker.mockHalconfigParser(HalconfigParserMocker.groovy:38) at com.netflix.spinnaker.halyard.config.services.v1.AccountServiceSpec.makeAccountService(AccountServiceSpec.groovy:34) at com.netflix.spinnaker.halyard.config.services.v1.AccountServiceSpec.load an existent account node(AccountServiceSpec.groovy:56) * refactor(config): use RequiredArgsConstructor in HalconfigDirectoryStructure to reduce boilerplate
- Loading branch information
Showing
6 changed files
with
84 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
.../test/java/com/netflix/spinnaker/halyard/config/config/v1/HalconfigConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2024 Salesforce, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.halyard.config.config.v1; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInfo; | ||
import org.springframework.boot.context.annotation.UserConfigurations; | ||
import org.springframework.boot.test.context.runner.ApplicationContextRunner; | ||
|
||
class HalconfigConfigurationTest { | ||
|
||
private final ApplicationContextRunner runner = | ||
new ApplicationContextRunner() | ||
.withConfiguration( | ||
UserConfigurations.of(ResourceConfig.class, HalconfigDirectoryStructure.class)); | ||
|
||
@BeforeEach | ||
void init(TestInfo testInfo) { | ||
System.out.println("--------------- Test " + testInfo.getDisplayName()); | ||
} | ||
|
||
@Test | ||
void testHalconfigDirectory() { | ||
runner.run( | ||
ctx -> { | ||
String homeDir = System.getProperty("user.home"); | ||
assertThat(homeDir).isNotNull(); | ||
|
||
assertThat(ctx).hasSingleBean(HalconfigDirectoryStructure.class); | ||
String halconfigDirectory = ctx.getBean("halconfigDirectory", String.class); | ||
assertThat(halconfigDirectory).isNotNull(); | ||
assertThat(halconfigDirectory).isEqualTo(homeDir + "/.hal"); | ||
HalconfigDirectoryStructure halconfigDirectoyStructure = | ||
ctx.getBean(HalconfigDirectoryStructure.class); | ||
assertThat(halconfigDirectoyStructure.getHalconfigDirectory()) | ||
.isEqualTo(halconfigDirectory); | ||
}); | ||
} | ||
} |