-
Notifications
You must be signed in to change notification settings - Fork 402
JENKINS-55920: add CasC support to GitHubPluginConfig w/Tests #210
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
Changes from all commits
69a5dfb
4c90018
e0155aa
d51eb78
bfe3a17
b08bc56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package org.jenkinsci.plugins.github.config; | ||
|
|
||
| import io.jenkins.plugins.casc.ConfigurationAsCode; | ||
| import io.jenkins.plugins.casc.misc.ConfiguredWithCode; | ||
| import io.jenkins.plugins.casc.misc.JenkinsConfiguredWithCodeRule; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.jvnet.hudson.test.JenkinsRule; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.both; | ||
| import static org.hamcrest.Matchers.hasItems; | ||
| import static org.hamcrest.Matchers.hasSize; | ||
| import static org.hamcrest.Matchers.is; | ||
| import static org.jenkinsci.plugins.github.test.GitHubServerConfigMatcher.withClientCacheSize; | ||
| import static org.jenkinsci.plugins.github.test.GitHubServerConfigMatcher.withCredsId; | ||
| import static org.jenkinsci.plugins.github.test.GitHubServerConfigMatcher.withApiUrl; | ||
| import static org.jenkinsci.plugins.github.test.GitHubServerConfigMatcher.withIsManageHooks; | ||
| import static org.jenkinsci.plugins.github.test.GitHubServerConfigMatcher.withName; | ||
|
|
||
| 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 export_configuration() throws Exception { | ||
| /* TODO (From JCASC): Need to provide some YAML assertion library so that the resulting exported yaml | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to update the plugin docs but it is being tested in this way in a few plugins and in the configuration-as-code repo:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| stream can be checked for expected content. */ | ||
| ConfigurationAsCode.get().export(System.out); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. never user System.out, use loggers if you want to print something. |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| unclassified: | ||
|
|
||
| githubpluginconfig: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe another more minimal test which shows what you need if you set manage hooks false and no hook url? |
||
| hookUrl: "http://some.com/github-webhook/secret-path" | ||
| hookSecretConfig: | ||
| credentialsId: "hook_secret_cred_id" | ||
| configs: | ||
| - credentialsId: "public_cred_id" | ||
| name: "Public GitHub" | ||
| apiUrl: "https://api.github.com" | ||
| manageHooks: true | ||
| clientCacheSize: 20 | ||
| - credentialsId: "private_cred_id" | ||
| name: "Private GitHub" | ||
| apiUrl: "https://api.some.com" | ||
| manageHooks: false | ||
| clientCacheSize: 40 | ||
Uh oh!
There was an error while loading. Please reload this page.