Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
theodolite
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sören Henning
theodolite
Commits
bf023009
Commit
bf023009
authored
2 years ago
by
JustAnotherChristoph
Committed by
Christopher Konkel
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
testing ResourceSets#loadResourceSet(..) by creating ResourceSets Objects from yaml
parent
6aeba702
No related branches found
No related tags found
1 merge request
!269
correct and test ResourceSets#loadResourceSet(..)
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
theodolite/src/test/kotlin/theodolite/benchmark/ResourceSetsTest.kt
+133
-0
133 additions, 0 deletions
.../src/test/kotlin/theodolite/benchmark/ResourceSetsTest.kt
with
133 additions
and
0 deletions
theodolite/src/test/kotlin/theodolite/benchmark/ResourceSetsTest.kt
0 → 100644
+
133
−
0
View file @
bf023009
package
theodolite.benchmark
import
com.fasterxml.jackson.databind.ObjectMapper
import
com.fasterxml.jackson.dataformat.yaml.YAMLFactory
import
io.fabric8.kubernetes.api.model.ConfigMap
import
io.fabric8.kubernetes.api.model.ConfigMapBuilder
import
io.fabric8.kubernetes.api.model.HasMetadata
import
io.fabric8.kubernetes.client.server.mock.KubernetesServer
import
io.quarkus.test.junit.QuarkusTest
import
io.quarkus.test.kubernetes.client.KubernetesTestServer
import
io.quarkus.test.kubernetes.client.WithKubernetesTestServer
import
org.junit.jupiter.api.AfterEach
import
org.junit.jupiter.api.Assertions.assertEquals
import
org.junit.jupiter.api.Assertions.assertTrue
import
org.junit.jupiter.api.BeforeEach
import
org.junit.jupiter.api.Test
import
org.junit.jupiter.api.assertThrows
import
org.junit.jupiter.api.io.TempDir
import
theodolite.util.DeploymentFailedException
import
java.nio.file.Files
import
java.nio.file.Path
@QuarkusTest
@WithKubernetesTestServer
internal
class
ResourceSetsTest
{
@KubernetesTestServer
private
lateinit
var
server
:
KubernetesServer
@TempDir
@JvmField
final
var
tempDir
:
Path
?
=
null
private
val
objectMapper
:
ObjectMapper
=
ObjectMapper
(
YAMLFactory
())
@BeforeEach
fun
setUp
()
{
server
.
before
()
}
@AfterEach
fun
tearDown
()
{
server
.
after
()
}
private
fun
deployAndGetResource
(
vararg
resources
:
HasMetadata
):
ConfigMapResourceSet
{
val
configMap
=
ConfigMapBuilder
()
.
withNewMetadata
().
withName
(
resources
[
0
].
metadata
.
name
).
endMetadata
()
.
let
{
resources
.
foldIndexed
(
it
)
{
i
,
b
,
r
->
b
.
addToData
(
"resource_$i.yaml"
,
objectMapper
.
writeValueAsString
(
r
))
}
}
.
build
()
server
.
client
.
configMaps
().
createOrReplace
(
configMap
)
val
resourceSet
=
ConfigMapResourceSet
()
resourceSet
.
name
=
resources
[
0
].
metadata
.
name
return
resourceSet
}
private
fun
copyTestResourceFile
(
fileName
:
String
,
tempDir
:
Path
)
{
val
stream
=
javaClass
.
getResourceAsStream
(
"/k8s-resource-files/$fileName"
)
?:
throw
IllegalArgumentException
(
"File does not exist"
)
val
target
=
tempDir
.
resolve
(
fileName
)
Files
.
copy
(
stream
,
target
)
}
@Test
fun
testLoadConfigMap
()
{
val
resource
=
ConfigMapBuilder
()
.
withNewMetadata
()
.
withName
(
"test-configmap"
)
.
endMetadata
()
.
build
()
deployAndGetResource
(
resource
)
val
yamlString
=
"""
configMap:
name: test-configmap
files:
"""
val
resourcesSet
:
ResourceSets
=
objectMapper
.
readValue
(
yamlString
,
ResourceSets
::
class
.
java
)
assertTrue
(
resourcesSet
.
fileSystem
==
null
)
assertTrue
(
resourcesSet
.
configMap
!=
null
)
val
configMap
=
resourcesSet
.
loadResourceSet
(
server
.
client
)
assertEquals
(
1
,
configMap
.
size
)
assertTrue
(
configMap
.
toList
().
first
().
second
is
ConfigMap
)
assertTrue
(
configMap
.
toList
().
first
().
second
.
toString
().
contains
(
other
=
resource
.
metadata
.
name
))
assertEquals
(
configMap
.
elementAt
(
0
).
second
,
resource
)
}
@Test
fun
testLoadFileSystem
(
@TempDir
tempDir
:
Path
)
{
copyTestResourceFile
(
"test-deployment.yaml"
,
tempDir
)
val
resourceSet
=
FileSystemResourceSet
()
resourceSet
.
path
=
tempDir
.
toString
()
resourceSet
.
files
=
listOf
(
"test-deployment.yaml"
)
assertEquals
(
1
,
resourceSet
.
getResourceSet
(
server
.
client
).
size
)
val
yamlString
=
"""
fileSystem:
path: ${resourceSet.path}
files:
- test-deployment.yaml
"""
val
resourcesSet
:
ResourceSets
=
objectMapper
.
readValue
(
yamlString
,
ResourceSets
::
class
.
java
)
assertTrue
(
resourcesSet
.
fileSystem
!=
null
)
assertTrue
(
resourcesSet
.
configMap
==
null
)
val
fileSystem
=
resourcesSet
.
loadResourceSet
(
server
.
client
)
assertEquals
(
fileSystem
.
size
,
1
)
assertTrue
(
fileSystem
.
elementAt
(
0
).
second
is
HasMetadata
)
}
@Test
fun
testEmptyResourceSets
()
{
val
resourceSet
=
ResourceSets
()
assertThrows
<
DeploymentFailedException
>
{
resourceSet
.
loadResourceSet
(
server
.
client
)
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment