-
Notifications
You must be signed in to change notification settings - Fork 396
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
End Pr210 #221
Merged
Merged
End Pr210 #221
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2df5c22
JENKINS-55920: add CasC support to GitHubPluginConfig.
d13a017
JENKINS-55920: address PR comments.
8d3da69
Address PR comments
dgarzon 4189420
Remove unused import added in previous JENKINS-55920 commits
er1c 4be509e
Update JENKINS-55920 PR to keep the setHookUrl(String) signature, and…
er1c 4c98e97
Add org.jenkinsci.plugins.github.config.ConfigAsCodeTest for JENKINS-…
er1c c38d013
Fix binding
KostyaSha d505d03
Update test
KostyaSha 17d0366
Update pom.xml
KostyaSha 8de92c7
remove comment
KostyaSha b2b7d15
Merge branch 'pr210' of github.com:KostyaSha/github-plugin into pr210
KostyaSha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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
96 changes: 96 additions & 0 deletions
96
src/test/java/org/jenkinsci/plugins/github/config/ConfigAsCodeTest.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,96 @@ | ||
package org.jenkinsci.plugins.github.config; | ||
|
||
import io.jenkins.plugins.casc.ConfigurationContext; | ||
import io.jenkins.plugins.casc.Configurator; | ||
import io.jenkins.plugins.casc.ConfiguratorRegistry; | ||
import io.jenkins.plugins.casc.misc.ConfiguredWithCode; | ||
import io.jenkins.plugins.casc.misc.JenkinsConfiguredWithCodeRule; | ||
import io.jenkins.plugins.casc.model.CNode; | ||
import io.jenkins.plugins.casc.model.Mapping; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
import static org.jenkinsci.plugins.github.test.GitHubServerConfigMatcher.*; | ||
|
||
public class ConfigAsCodeTest { | ||
|
||
@Rule | ||
public JenkinsConfiguredWithCodeRule r = new JenkinsConfiguredWithCodeRule(); | ||
|
||
@Test | ||
@ConfiguredWithCode("configuration-as-code.yml") | ||
public void shouldSupportConfigurationAsCode() throws Exception { | ||
|
||
GitHubPluginConfig gitHubPluginConfig = GitHubPluginConfig.all().get(GitHubPluginConfig.class); | ||
|
||
/** Test Global Config Properties */ | ||
|
||
assertThat( | ||
"getHookUrl() is configured", | ||
gitHubPluginConfig.getHookUrl().toString(), | ||
is("http://some.com/github-webhook/secret-path") | ||
); | ||
|
||
assertThat( | ||
"getHookSecretConfig().getCredentialsId() is configured", | ||
gitHubPluginConfig.getHookSecretConfig().getCredentialsId(), | ||
is("hook_secret_cred_id") | ||
); | ||
|
||
/** Test GitHub Server Configs */ | ||
|
||
assertThat("configs are loaded", gitHubPluginConfig.getConfigs(), hasSize(2)); | ||
|
||
assertThat("configs are set", gitHubPluginConfig.getConfigs(), hasItems( | ||
both(withName(is("Public GitHub"))) | ||
.and(withApiUrl(is("https://api.github.com"))) | ||
.and(withCredsId(is("public_cred_id"))) | ||
.and(withClientCacheSize(is(20))) | ||
.and(withIsManageHooks(is(true))), | ||
both(withName(is("Private GitHub"))) | ||
.and(withApiUrl(is("https://api.some.com"))) | ||
.and(withCredsId(is("private_cred_id"))) | ||
.and(withClientCacheSize(is(40))) | ||
.and(withIsManageHooks(is(false))) | ||
)); | ||
} | ||
|
||
@Test | ||
@ConfiguredWithCode("configuration-as-code.yml") | ||
public void exportConfiguration() throws Exception { | ||
GitHubPluginConfig globalConfiguration = GitHubPluginConfig.all().get(GitHubPluginConfig.class); | ||
|
||
ConfiguratorRegistry registry = ConfiguratorRegistry.get(); | ||
ConfigurationContext context = new ConfigurationContext(registry); | ||
final Configurator c = context.lookupOrFail(GitHubPluginConfig.class); | ||
|
||
@SuppressWarnings("unchecked") | ||
CNode node = c.describe(globalConfiguration, context); | ||
assertThat(node, notNullValue()); | ||
final Mapping mapping = node.asMapping(); | ||
|
||
assertThat(mapping.getScalarValue("hookUrl"), is("http://some.com/github-webhook/secret-path")); | ||
|
||
CNode configsNode = mapping.get("configs"); | ||
assertThat(configsNode, notNullValue()); | ||
|
||
List<Mapping> configsMapping = (List) configsNode.asSequence(); | ||
assertThat(configsMapping, hasSize(2)); | ||
|
||
assertThat("configs are set", configsMapping, | ||
hasItems( | ||
both(withCredsIdS(is("public_cred_id"))) | ||
.and(withNameS(is("Public GitHub"))), | ||
both(withNameS(is("Private GitHub"))) | ||
.and(withApiUrlS(is("https://api.some.com"))) | ||
.and(withCredsIdS(is("private_cred_id"))) | ||
.and(withClientCacheSizeS(is(40))) | ||
.and(withIsManageHooksS(is(false))) | ||
) | ||
); | ||
} | ||
} |
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
Oops, something went wrong.
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.
you could probably write a simpler test with a fixture, there's nothing dynamic here so should be straightforward:
https://github.com/jenkinsci/slack-plugin/blob/master/src/test/java/jenkins/plugins/slack/jcasc/ConfigurationAsCodeTest.java#L34
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.
What is the difference with the source yaml?
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.
the source yaml is the same, the expected one doesn't have the attribute that you do a .get on, in the case of slack it's missing
slackNotifier
but has all the fields under itThere 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.
i not sure also btw, final yaml is missing default return settings, is it ok?
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 i can merge&release finally this caasc support and i can accept PR for test update if you want to change it
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.
probably not worth it, it works and is unlikely to ever need to change.