Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed Apr 22, 2024
1 parent 6b19435 commit 166f879
Show file tree
Hide file tree
Showing 5 changed files with 279 additions and 0 deletions.
132 changes: 132 additions & 0 deletions src/test/java/com/amihaiemil/eoyaml/RtYamlInputTest.java
Expand Up @@ -2110,6 +2110,138 @@ public void readsTypicalSpringApplicationProperties() throws IOException {
);
}

/**
* We can read a typical kustomization.yml for k8s.
* @throws IOException If something goes wrong.
*/
@Test
public void readsTypicalKustomizationYaml() throws IOException {
final YamlInput input = Yaml.createYamlInput(
new FileReader(
"src/test/resources/typical_examples/kustomization.yml"
)
);
final YamlMapping read = input.readYamlMapping();
MatcherAssert.assertThat(
read.toString(),
Matchers.equalTo(
this.readTestResource(
"typical_examples/kustomization.yml"
)
)
);
}

/**
* We can read a typical deployment.yml for k8s.
* @throws IOException If something goes wrong.
*/
@Test
public void readsTypicalDeploymentYaml() throws IOException {
final YamlInput input = Yaml.createYamlInput(
new FileReader(
"src/test/resources/typical_examples/deployment.yml"
)
);
final YamlMapping read = input.readYamlMapping();
MatcherAssert.assertThat(
read.toString(),
Matchers.equalTo(
this.readTestResource(
"typical_examples/deployment.yml"
)
)
);
}

/**
* We can read a typical azure-pipeline.yml for k8s.
* @throws IOException If something goes wrong.
*/
@Test
public void readsTypicalAzurePipelineYaml() throws IOException {
final YamlInput input = Yaml.createYamlInput(
new FileReader(
"src/test/resources/typical_examples/azure-pipeline.yml"
)
);
final YamlMapping read = input.readYamlMapping();
MatcherAssert.assertThat(
read.toString(),
Matchers.equalTo(
this.readTestResource(
"typical_examples/azure-pipeline.yml"
)
)
);
}

/**
* We can read a typical rultor.yml for k8s.
* @throws IOException If something goes wrong.
*/
@Test
public void readsTypicalRultorYaml() throws IOException {
final YamlInput input = Yaml.createYamlInput(
new FileReader(
"src/test/resources/typical_examples/rultor.yml"
)
);
final YamlMapping read = input.readYamlMapping();
MatcherAssert.assertThat(
read.yamlMapping("docker").string("image"),
Matchers.equalTo("g4s8/rultor-jdk11:alpine3.10")
);
MatcherAssert.assertThat(
read.yamlSequence("architect").size(),
Matchers.equalTo(1)
);
MatcherAssert.assertThat(
read.yamlSequence("architect").string(0),
Matchers.equalTo("amihaiemil")
);
MatcherAssert.assertThat(
read.yamlMapping("env").string("MAVEN_OPTS"),
Matchers.equalTo("-XX:MaxPermSize=256m -Xmx1g")
);
MatcherAssert.assertThat(
read.yamlMapping("assets").string("settings.xml"),
Matchers.equalTo("amihaiemil/maven#settings.xml")
);
MatcherAssert.assertThat(
read.yamlMapping("assets").string("pubring.gpg"),
Matchers.equalTo("amihaiemil/maven#pubring.gpg")
);
MatcherAssert.assertThat(
read.yamlMapping("assets").string("secring.gpg"),
Matchers.equalTo("amihaiemil/maven#secring.gpg")
);
MatcherAssert.assertThat(
read.yamlMapping("merge").yamlSequence("script").size(),
Matchers.equalTo(1)
);
MatcherAssert.assertThat(
read.yamlMapping("merge").yamlSequence("script").string(0),
Matchers.equalTo("mvn clean install -Pcheckstyle,itcases")
);
MatcherAssert.assertThat(
read.yamlMapping("release").yamlSequence("script").size(),
Matchers.equalTo(3)
);
MatcherAssert.assertThat(
read.yamlMapping("release").yamlSequence("script").string(0),
Matchers.equalTo("export JAVA_HOME=/usr/lib/jvm/java-11-openjdk")
);
MatcherAssert.assertThat(
read.yamlMapping("release").yamlSequence("script").string(1),
Matchers.equalTo("chmod +x ./rrv.sh")
);
MatcherAssert.assertThat(
read.yamlMapping("release").yamlSequence("script").string(2),
Matchers.equalTo("./rrv.sh")
);
}

/**
* We can read a typical docker-compose.yml file.
* @throws IOException If something goes wrong.
Expand Down
67 changes: 67 additions & 0 deletions src/test/resources/typical_examples/azure-pipeline.yml
@@ -0,0 +1,67 @@
parameters:
-
name: withFrontendSonarAnalysis
displayName: Analyse Monorepo-Frontend (app and libs) with Sonar
type: boolean
default: false
-
name: withBackendSonarAnalysis
displayName: Analyse Backend with Sonar
type: boolean
default: true
-
name: gitCommitId
displayName: Git Commit Id
type: string
default: null
stages:
-
stage: Build_App
displayName: Build app
dependsOn: SetupAndChecks
condition: >
and(
succeeded('SetupAndChecks'),
and(
containsValue(split(stageDependencies.SetupAndChecks.outputs['SetupBranchPrPipeline.CheckBoundedContextChanges.buildBoundedContext'],' '), 'dokument'),
and(
ne(stageDependencies.SetupAndChecks.outputs['SetupBranchPrPipeline.CheckBoundedContextChanges.skipRun'], 'true'),
ne(stageDependencies.SetupAndChecks.outputs['SetupBranchPrPipeline.GetPullRequestInfos.skipRun'], 'true')
)
)
)
jobs:
-
template: ../cd-scripts/build-monorepo-template.yaml
parameters:
containerRegistryConnection: $(container-registry-connection)
boundedContext: app
withSonar: ${{ parameters.withFrontendSonarAnalysis }}
gitCommitId: ${{ parameters.gitCommitId }}
-
template: ../cd-scripts/java-build-template.yaml
parameters:
containerRegistryConnection: $(container-registry-connection)
containerRegistryUrl: $(container-registry-url)
boundedContext: app
microService: backend
withSonar: ${{ parameters.withBackendSonarAnalysis }}
gitCommitId: ${{ parameters.gitCommitId }}
-
template: ../cd-scripts/java-build-template.yaml
parameters:
containerRegistryConnection: $(container-registry-connection)
containerRegistryUrl: $(container-registry-url)
boundedContext: dokument
microService: authzhook
withSonar: ${{ parameters.withBackendSonarAnalysis }}
gitCommitId: ${{ parameters.gitCommitId }}
-
template: ../cd-scripts/java-build-template.yaml
parameters:
containerRegistryConnection: $(container-registry-connection)
containerRegistryUrl: $(container-registry-url)
boundedContext: dokument
microService: authzhookmock
withSonar: ${{ parameters.withBackendSonarAnalysis }}
gitCommitId: ${{ parameters.gitCommitId }}
55 changes: 55 additions & 0 deletions src/test/resources/typical_examples/deployment.yml
@@ -0,0 +1,55 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: app-backend
annotations:
reloader.stakater.com/auto: true
spec:
replicas: 1
template:
spec:
securityContext:
fsGroup: 0
runAsGroup: 0
runAsNonRoot: false
runAsUser: 0
containers:
-
name: app-backend
image: localhost:5000/app-backend:dev
imagePullPolicy: Always
env:
-
name: SPRING_DATA_MONGODB_URI
valueFrom:
secretKeyRef:
name: app-secret
key: CONNECTION_STRING
-
name: SPRING_DATA_MONGODB_DATABASE
valueFrom:
secretKeyRef:
name: app-secret
key: DATABASE_NAME
-
name: APP_TENANTID
valueFrom:
configMapKeyRef:
name: local-dev-config
key: app-tenant-id
-
name: SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI
valueFrom:
configMapKeyRef:
name: local-dev-config
key: keycloak-issuer-uri
-
name: SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI
valueFrom:
configMapKeyRef:
name: local-dev-config
key: keycloak-jwk-set-uri
# Enable remote debugging: uncomment these lines and forward 5005 to localhost in Tiltfile
-
name: JAVA_TOOL_OPTIONS
value: "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=localhost:5005"
7 changes: 7 additions & 0 deletions src/test/resources/typical_examples/kustomization.yml
@@ -0,0 +1,7 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- service1/
- service2/
- service3/
- service4-cleanup/
18 changes: 18 additions & 0 deletions src/test/resources/typical_examples/rultor.yml
@@ -0,0 +1,18 @@
docker:
image: g4s8/rultor-jdk11:alpine3.10
architect:
- amihaiemil
env:
MAVEN_OPTS: "-XX:MaxPermSize=256m -Xmx1g"
merge:
script: |-
mvn clean install -Pcheckstyle,itcases
assets:
settings.xml: "amihaiemil/maven#settings.xml"
pubring.gpg: "amihaiemil/maven#pubring.gpg"
secring.gpg: "amihaiemil/maven#secring.gpg"
release:
script: |-
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk
chmod +x ./rrv.sh
./rrv.sh

0 comments on commit 166f879

Please sign in to comment.