Skip to content

Commit

Permalink
Test demonstrating issue dekorateio#1000
Browse files Browse the repository at this point in the history
  • Loading branch information
kabir committed Jun 9, 2022
1 parent f242d45 commit 8b4569b
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,12 @@ dekorate.servicebinding.services[0].api-version=postgresql.dev/v1
dekorate.servicebinding.services[0].kind=Database
dekorate.servicebinding.services[0].name=demo-database
dekorate.kubernetes.image-pull-policy=IfNotPresent
dekorate.kubernetes.env-vars[0].name=from-props
dekorate.kubernetes.env-vars[0].value=prop-value
dekorate.kubernetes.env-vars[1].name=from-props2
dekorate.kubernetes.env-vars[1].value=prop-value2
dekorate.kubernetes.ports[0].name=http
dekorate.kubernetes.ports[0].containerPort=8080
dekorate.kubernetes.ports[1].name=httpx
dekorate.kubernetes.ports[1].containerPort=8089

Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2018 The original authors.
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>dekorate-tests</artifactId>
<groupId>io.dekorate</groupId>
<version>2.9-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

<groupId>io.dekorate</groupId>
<artifactId>issue-100-docker-registry-docker-file-needs-Dockerfile</artifactId>
<packaging>jar</packaging>
<name>Dekorate :: Tests :: Annotations :: Kubernetes :: Integration Test for #1000</name>
<description>Docker registry is defined</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<dependencies>
<dependency>
<groupId>io.dekorate</groupId>
<artifactId>kubernetes-annotations</artifactId>
<version>${project.version}</version>
</dependency>
<!-- Testing -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${version.maven-surefire-plugin}</version>
<inherited>true</inherited>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.maven-compiler-plugin}</version>
<configuration>
<source>${java.source}</source>
<target>${java.target}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright 2018 The original authors.
*
* 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 io.dekorate.example;

import io.dekorate.annotation.Dekorate;

@Dekorate
public class Main {

public static void main(String[] args) {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM openjdk:8u171-alpine3.7
RUN apk --no-cache add curl
COPY target/*.jar example.jar
CMD java ${JAVA_OPTS} -jar example.jar
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dekorate:
docker:
registry: localhost:3000
docker-file: src/main/resources/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright 2018 The original authors.
*
* 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 io.dekorate.example;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Optional;

import org.junit.jupiter.api.Test;

import io.dekorate.utils.Serialization;
import io.fabric8.kubernetes.api.model.Container;
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.api.model.KubernetesList;
import io.fabric8.kubernetes.api.model.apps.Deployment;

public class Issue420Test {

@Test
public void shouldHaveRegistry() {
KubernetesList list = Serialization
.unmarshalAsList(Issue420Test.class.getClassLoader().getResourceAsStream("META-INF/dekorate/kubernetes.yml"));
assertNotNull(list);
Deployment d = findFirst(list, Deployment.class).orElseThrow(() -> new IllegalStateException());
assertNotNull(d);
Container c = d.getSpec().getTemplate().getSpec().getContainers().get(0);
assertNotNull(c);
String image = c.getImage();
assertTrue(image.startsWith("localhost:3000"));
}

<T extends HasMetadata> Optional<T> findFirst(KubernetesList list, Class<T> t) {
return (Optional<T>) list.getItems().stream()
.filter(i -> t.isInstance(i))
.findFirst();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import io.dekorate.utils.Serialization
import io.fabric8.kubernetes.api.model.KubernetesList
import io.fabric8.kubernetes.api.model.apps.Deployment;

//Check that file exits
String base = basedir
File kubernetesYml = new File(base, "target/classes/META-INF/dekorate/kubernetes.yml")
assert !kubernetesYml.exists()

0 comments on commit 8b4569b

Please sign in to comment.