-
Notifications
You must be signed in to change notification settings - Fork 711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow configuring max aliases for a collection #1375
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
80b822b
increase max aliases for collection
jetersen 57aebdd
Move ConfigurationContext one level up to enable configurable max ali…
jetersen 3b61d7e
Merge branch 'master' into fix/1374
jetersen d2a3d3f
add test for max aliases in collections
jetersen e05453a
add test for invalid input
jetersen 6a5a841
provide a more helpful error message
jetersen b5bf2a8
fix imports
jetersen 8455a55
check the cause message
jetersen File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
81 changes: 81 additions & 0 deletions
81
test-harness/src/test/java/io/jenkins/plugins/casc/YamlMaxAliasesCollection.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,81 @@ | ||
package io.jenkins.plugins.casc; | ||
|
||
import io.jenkins.plugins.casc.misc.EnvVarsRule; | ||
import jenkins.model.Jenkins; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.contrib.java.lang.system.RestoreSystemProperties; | ||
import org.junit.rules.RuleChain; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertThrows; | ||
|
||
public class YamlMaxAliasesCollection { | ||
|
||
private JenkinsRule j; | ||
|
||
private EnvVarsRule env; | ||
|
||
@Rule | ||
public RuleChain rc = RuleChain.outerRule(env = new EnvVarsRule()) | ||
.around(new RestoreSystemProperties()) | ||
.around(j = new JenkinsRule()); | ||
|
||
@Test | ||
public void testAMaxOfOneEnv() { | ||
env.set(ConfigurationContext.CASC_YAML_MAX_ALIASES_ENV, "1"); | ||
ConfiguratorException e = assertThrows(ConfiguratorException.class, () -> | ||
ConfigurationAsCode.get() | ||
.configure(getClass().getResource("maxAliasesLimit.yml").toExternalForm())); | ||
assertEquals("Number of aliases for non-scalar nodes exceeds the specified max=1\n" | ||
+ "You can increase the maximum by setting an environment variable or property\n" | ||
+ " ENV: CASC_YAML_MAX_ALIASES=\"100\"\n" | ||
+ " PROPERTY: -Dcasc.yaml.max.aliases=\"100\"", e.getCause().getMessage().replaceAll("\\r\\n?", "\n")); | ||
} | ||
|
||
@Test | ||
public void testAMaxOfOneProp() { | ||
System.setProperty(ConfigurationContext.CASC_YAML_MAX_ALIASES_PROPERTY, "1"); | ||
ConfiguratorException e = assertThrows(ConfiguratorException.class, () -> | ||
ConfigurationAsCode.get() | ||
.configure(getClass().getResource("maxAliasesLimit.yml").toExternalForm())); | ||
assertEquals("Number of aliases for non-scalar nodes exceeds the specified max=1\n" | ||
+ "You can increase the maximum by setting an environment variable or property\n" | ||
+ " ENV: CASC_YAML_MAX_ALIASES=\"100\"\n" | ||
+ " PROPERTY: -Dcasc.yaml.max.aliases=\"100\"", e.getCause().getMessage().replaceAll("\\r\\n?", "\n")); | ||
} | ||
|
||
@Test | ||
public void testAMaxOfTwoEnv() throws ConfiguratorException { | ||
env.set(ConfigurationContext.CASC_YAML_MAX_ALIASES_ENV, "2"); | ||
ConfigurationAsCode.get().configure(getClass().getResource("maxAliasesLimit.yml").toExternalForm()); | ||
final Jenkins jenkins = Jenkins.get(); | ||
assertEquals(2, jenkins.getNodes().size()); | ||
assertEquals("static-agent1", jenkins.getNode("static-agent1").getNodeName()); | ||
assertEquals("static-agent2", jenkins.getNode("static-agent2").getNodeName()); | ||
} | ||
|
||
@Test | ||
public void testAMaxOfTwoProp() throws ConfiguratorException { | ||
System.setProperty(ConfigurationContext.CASC_YAML_MAX_ALIASES_PROPERTY, "2"); | ||
ConfigurationAsCode.get().configure(getClass().getResource("maxAliasesLimit.yml").toExternalForm()); | ||
final Jenkins jenkins = Jenkins.get(); | ||
assertEquals(2, jenkins.getNodes().size()); | ||
assertEquals("static-agent1", jenkins.getNode("static-agent1").getNodeName()); | ||
assertEquals("static-agent2", jenkins.getNode("static-agent2").getNodeName()); | ||
} | ||
|
||
@Test | ||
public void invalidInputShouldDefaultTo50() throws ConfiguratorException { | ||
System.setProperty(ConfigurationContext.CASC_YAML_MAX_ALIASES_PROPERTY, "HELLO"); | ||
ConfiguratorRegistry registry = ConfiguratorRegistry.get(); | ||
ConfigurationContext context = new ConfigurationContext(registry); | ||
assertEquals(50, context.getYamlMaxAliasesForCollections()); | ||
ConfigurationAsCode.get().configure(getClass().getResource("maxAliasesLimit.yml").toExternalForm()); | ||
final Jenkins jenkins = Jenkins.get(); | ||
assertEquals(2, jenkins.getNodes().size()); | ||
assertEquals("static-agent1", jenkins.getNode("static-agent1").getNodeName()); | ||
assertEquals("static-agent2", jenkins.getNode("static-agent2").getNodeName()); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
test-harness/src/test/resources/io/jenkins/plugins/casc/maxAliasesLimit.yml
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,17 @@ | ||
x-jenkins-linux-node: &jenkins_linux_node_anchor | ||
remoteFS: "/home/jenkins" | ||
launcher: | ||
jnlp: | ||
workDirSettings: | ||
disabled: true | ||
failIfWorkDirIsMissing: false | ||
internalDir: "remoting" | ||
workDirPath: "/tmp" | ||
jenkins: | ||
nodes: | ||
- permanent: | ||
name: "static-agent1" | ||
<<: *jenkins_linux_node_anchor | ||
- permanent: | ||
name: "static-agent2" | ||
<<: *jenkins_linux_node_anchor |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@timja Please see 57aebdd commit message for my reasoning to use a property.