use of io.fabric8.annotations.Configuration in project fabric8 by fabric8io.
the class OpenShiftPipelineTest method testPipelinesFromConfigMap.
@Test
public void testPipelinesFromConfigMap() throws Exception {
String namespace = "myproject";
final ConfigMap configMap = loadTestConfigMap();
server.expect().withPath("/api/v1/namespaces/" + namespace + "/configmaps/" + FABRIC8_PIPELINES).andReturn(200, configMap).once();
PipelineConfiguration configuration = PipelineConfiguration.loadPipelineConfiguration(getKubernetesClient(), namespace);
assertJobName(configuration, "foo", "dummy", PipelineKind.CD);
assertJobName(configuration, "bar", "dummy", PipelineKind.CI);
assertJobName(configuration, "whatnot", "dummy", PipelineKind.Developer);
assertJobName(configuration, "random", "master", "git@github.com:fabric8io/random.git", PipelineKind.CD);
assertJobName(configuration, "random", "master", "https://github.com/fabric8io/random.git", PipelineKind.CD);
assertJobName(configuration, "random", "not-master", "https://github.com/fabric8io/random.git", PipelineKind.Developer);
assertJobName(configuration, "random", "master", "https://github.com/bar/foo.git", PipelineKind.Developer);
assertJobName(configuration, "random", "master", "git@github.com:bar/foo.git", PipelineKind.Developer);
// lets show we can opt out of CD pipelines for specific builds in an organisation if required
assertJobName(configuration, "random", "master", "https://github.com/random/whatnot.git", PipelineKind.Developer);
assertJobName(configuration, "random", "release", "https://github.com/random/whatnot.git", PipelineKind.CD);
assertJobName(configuration, "random", "whatever", "https://github.com/random/whatnot.git", PipelineKind.CI);
}
use of io.fabric8.annotations.Configuration in project fabric8 by fabric8io.
the class PipelineConfigurationParseTest method testLoadMutateAndLoadPipelineConfiguration.
@Test
public void testLoadMutateAndLoadPipelineConfiguration() throws Exception {
ConfigMap configMap = loadTestConfigMap();
PipelineConfiguration pipelineConfiguration = PipelineConfiguration.getPipelineConfiguration(configMap);
pipelineConfiguration.setCdBranchPatterns(Arrays.asList("cd-1", "cd-2"));
pipelineConfiguration.setCiBranchPatterns(Arrays.asList("ci-1", "ci-2"));
pipelineConfiguration.setJobNameToKindMap(new HashMap<>());
pipelineConfiguration.setJobNamesCD("job-cd");
pipelineConfiguration.setJobNamesCI("job-ci");
HashMap<String, List<String>> cdGitHostAndOrganisationToBranchPatterns = new HashMap<>();
cdGitHostAndOrganisationToBranchPatterns.put("github.com/acme", Arrays.asList("release1"));
cdGitHostAndOrganisationToBranchPatterns.put("github.com/another", Arrays.asList("release2"));
pipelineConfiguration.setCdGitHostAndOrganisationToBranchPatterns(cdGitHostAndOrganisationToBranchPatterns);
// reload the modified configuration
configMap = pipelineConfiguration.createConfigMap();
pipelineConfiguration = PipelineConfiguration.getPipelineConfiguration(configMap);
assertThat(pipelineConfiguration.getCdBranchPatterns()).describedAs("getCdBranchPatterns()").contains("cd-1").contains("cd-2");
assertThat(pipelineConfiguration.getCiBranchPatterns()).describedAs("getCiBranchPatterns()").contains("ci-1").contains("ci-2");
assertThat(pipelineConfiguration.getJobNameToKindMap()).describedAs("getJobNameToKindMap()").containsEntry("job-cd", PipelineKind.CD).containsEntry("job-ci", PipelineKind.CI);
assertThat(pipelineConfiguration.getCdGitHostAndOrganisationToBranchPatterns()).describedAs("getCdGitHostAndOrganisationToBranchPatterns()").containsEntry("github.com/acme", Arrays.asList("release1")).containsEntry("github.com/another", Arrays.asList("release2"));
}
use of io.fabric8.annotations.Configuration in project fabric8 by fabric8io.
the class ConfigurationTest method testNamespaceFoundFromConfigMap.
@Test
public void testNamespaceFoundFromConfigMap() {
String devNamespace = "myproject";
String environmentKey = "testing";
String testNamespace = "myproject-testing";
Map<String, String> data = new HashMap<>();
data.put(environmentKey, " name: Testing\n" + " namespace: " + testNamespace + "\n" + " order: 0");
server.expect().withPath("/api/v1/namespaces/" + devNamespace + "/configmaps/fabric8-environments").andReturn(200, new ConfigMapBuilder().withNewMetadata().withName("fabric8-environments").endMetadata().withData(data).build()).once();
Map<String, String> map = new HashMap<>();
map.put(FABRIC8_ENVIRONMENT, environmentKey);
map.put(DEVELOPMENT_NAMESPACE, devNamespace);
Configuration configuration = Configuration.fromMap(map, getKubernetesClient());
assertEquals(testNamespace, configuration.getNamespace());
assertTrue(configuration.isAnsiLoggerEnabled());
assertTrue(configuration.isEnvironmentInitEnabled());
assertTrue(configuration.isNamespaceLazyCreateEnabled());
assertFalse(configuration.isNamespaceCleanupEnabled());
assertFalse(configuration.isCreateNamespaceForTest());
}
use of io.fabric8.annotations.Configuration in project fabric8 by fabric8io.
the class ConfigurationTest method testEnvironmentKeyButNoConfigMap.
@Test
public void testEnvironmentKeyButNoConfigMap() {
String devNamespace = "myproject";
String environmentKey = "testing";
String testNamespace = devNamespace;
Map<String, String> data = new HashMap<>();
data.put("staging", " name: Staging\n" + " namespace: myproject-staging\n" + " order: 0");
server.expect().withPath("/api/v1/namespaces/" + devNamespace + "/configmaps/fabric8-environments").andReturn(404, "Not found").once();
Map<String, String> map = new HashMap<>();
map.put(FABRIC8_ENVIRONMENT, environmentKey);
map.put(DEVELOPMENT_NAMESPACE, devNamespace);
KubernetesClient kubernetesClient = getKubernetesClient();
Config config = new Config();
config.setNamespace(devNamespace);
config.setMasterUrl(kubernetesClient.getMasterUrl().toString());
DefaultKubernetesClient clientWithDefaultNamespace = new DefaultKubernetesClient(config);
Configuration configuration = Configuration.fromMap(map, clientWithDefaultNamespace);
assertEquals(testNamespace, configuration.getNamespace());
assertTrue(configuration.isAnsiLoggerEnabled());
assertTrue(configuration.isEnvironmentInitEnabled());
assertTrue(configuration.isNamespaceLazyCreateEnabled());
assertFalse(configuration.isNamespaceCleanupEnabled());
assertFalse(configuration.isCreateNamespaceForTest());
}
use of io.fabric8.annotations.Configuration in project fabric8 by fabric8io.
the class ConfigurationTest method testNamespaceNotFoundFromConfigMap.
@Ignore
public void testNamespaceNotFoundFromConfigMap() {
String devNamespace = "myproject";
String environmentKey = "testing";
String testNamespace = devNamespace;
Map<String, String> data = new HashMap<>();
data.put("staging", " name: Staging\n" + " namespace: myproject-staging\n" + " order: 0");
server.expect().withPath("/api/v1/namespaces/" + devNamespace + "/configmaps/fabric8-environments").andReturn(200, new ConfigMapBuilder().withNewMetadata().withName("fabric8-environments").endMetadata().withData(data).build()).once();
Map<String, String> map = new HashMap<>();
map.put(FABRIC8_ENVIRONMENT, environmentKey);
map.put(DEVELOPMENT_NAMESPACE, devNamespace);
Configuration configuration = Configuration.fromMap(map, kubernetesClient);
assertEquals(testNamespace, configuration.getNamespace());
assertTrue(configuration.isAnsiLoggerEnabled());
assertTrue(configuration.isEnvironmentInitEnabled());
assertTrue(configuration.isNamespaceLazyCreateEnabled());
assertFalse(configuration.isNamespaceCleanupEnabled());
assertFalse(configuration.isCreateNamespaceForTest());
}
Aggregations