Fabric8 Kubernetes :: Assertions

This library provides a bunch of helpful assertj assertions for working with the kubernetes-api.

License

License

Categories

Categories

Kubernetes Container Virtualization Tools Net
GroupId

GroupId

io.fabric8
ArtifactId

ArtifactId

kubernetes-assertions
Last Version

Last Version

4.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

Fabric8 Kubernetes :: Assertions
This library provides a bunch of helpful assertj assertions for working with the kubernetes-api.
Project URL

Project URL

http://github.com/fabric8io/kubernetes-assertions

Download kubernetes-assertions

How to add to project

<!-- https://jarcasting.com/artifacts/io.fabric8/kubernetes-assertions/ -->
<dependency>
    <groupId>io.fabric8</groupId>
    <artifactId>kubernetes-assertions</artifactId>
    <version>4.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.fabric8/kubernetes-assertions/
implementation 'io.fabric8:kubernetes-assertions:4.0.0'
// https://jarcasting.com/artifacts/io.fabric8/kubernetes-assertions/
implementation ("io.fabric8:kubernetes-assertions:4.0.0")
'io.fabric8:kubernetes-assertions:jar:4.0.0'
<dependency org="io.fabric8" name="kubernetes-assertions" rev="4.0.0">
  <artifact name="kubernetes-assertions" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.fabric8', module='kubernetes-assertions', version='4.0.0')
)
libraryDependencies += "io.fabric8" % "kubernetes-assertions" % "4.0.0"
[io.fabric8/kubernetes-assertions "4.0.0"]

Dependencies

compile (7)

Group / Artifact Type Version
io.fabric8 : kubernetes-api jar 3.0.8
io.fabric8 : kubernetes-client jar 4.8.0
io.fabric8 : openshift-client jar 4.8.0
io.fabric8 : fabric8-utils jar 3.0.8
org.fusesource.jansi : jansi jar 1.11
org.assertj : assertj-core jar 3.15.0
org.junit.jupiter : junit-jupiter-api jar 5.6.0

test (1)

Group / Artifact Type Version
org.slf4j : slf4j-log4j12 jar 1.7.25

Project Modules

There are no modules declared in this project.

Kubernetes Assertions

CircleCI Maven Central Javadocs

This library provides a bunch of helpful assertj assertions for working with the kubernetes-api.

Default system test

The following code provides a default system test:

             assertThat(client).deployments().pods().isPodReadyForPeriod();

This will assert that the current project's Deployment creates at least one pod; that it becomes Ready within a time period (30 seconds by default), then that the pod keeps being Ready for a period (defaults to 10 seconds).

This may seem a fairly simple test case; but it catches most errors with the Deployment being invalid or failing to start; the pod starting then failing due to some configuration issue etc.

If your application uses liveness checks (which are used by default with Spring Boot apps) then this test also asserts that the liveness checks keep valid for the period too. So if your application fails to connect to a database or your Camel route fails to start a route or whatever; then the test fails!

This means to improve your system tests you can just improve your liveness checks; which also helps Kubernetes manage your production environment too!

Other examples

Some quick examples:

Navigating and asserting around resources

When working with Kubernetes and OpenShift resources in test cases you'll find that objects can be massively nested.

For example even using something as simple as a Pod you need to navigate to compare its name:

Pod pod = kubernetesClient.pods().inNamespace(ns).withName("foo").get();
assertThat(pod).metadata().name().isEqualTo("foo");

Things get even more complex when asserting a ReplicationController

ReplicationController rc = kubernetesClient.replicationControllers().inNamespace(ns).withName("foo").get();
assertThat(rc).spec().template().spec().containers().first().image().isEqualTo("someDockerImageName");

Whats great about Kubernetes Assertions is that you can chain methods together to navigate the model; if any navigation fails you get meaninful errors in the test failure telling you exactly which object was null or list was empty or other assertion failed (e.g. a list index was out of range) etc.

For example here's some example error messages from assertj when navigation or assertions fail in these tests:

    org.junit.ComparisonFailure: [podListWith2Items.items.first().metadata.name] expected:<"[shouldNotMatch]"> but was:<"[abc]">
    
    java.lang.AssertionError: [podListWith2Items.items.index]
    Expecting:
     <-1>
    to be greater than or equal to:
     <0>

### Add it to your Maven pom.xml

To be able to use the Java code in your Apache Maven based project add this into your pom.xml

        <dependency>
            <groupId>io.fabric8</groupId>
            <artifactId>kubernetes-assertions</artifactId>
            <version>4.0.0</version>
            <scope>test</scope>
        </dependency>
io.fabric8

fabric8

open source development platform for kubernetes

Versions

Version
4.0.0
3.0.12
3.0.11
3.0.8
3.0.7
3.0.5
3.0.3
3.0.1
2.3.7
2.3.6
2.3.5
2.3.4
2.3.3
2.3.2
2.3.1
2.3.0
2.2.217
2.2.216
2.2.215
2.2.213
2.2.212
2.2.211
2.2.210
2.2.209
2.2.208
2.2.207
2.2.206
2.2.205
2.2.204
2.2.203
2.2.202
2.2.201
2.2.200
2.2.199
2.2.198
2.2.197
2.2.196
2.2.195
2.2.194
2.2.193
2.2.192
2.2.191
2.2.190
2.2.189
2.2.188
2.2.187
2.2.185
2.2.184
2.2.183
2.2.182
2.2.181
2.2.180
2.2.179
2.2.178
2.2.176
2.2.175
2.2.174
2.2.173
2.2.170
2.2.169
2.2.168
2.2.167
2.2.165
2.2.164
2.2.163
2.2.161
2.2.160
2.2.159
2.2.158
2.2.157
2.2.156
2.2.155
2.2.154
2.2.153
2.2.152
2.2.151
2.2.150
2.2.148
2.2.147
2.2.146
2.2.145
2.2.144
2.2.143
2.2.142
2.2.141
2.2.140
2.2.139
2.2.138
2.2.136
2.2.135
2.2.134
2.2.132
2.2.131
2.2.130
2.2.128
2.2.127
2.2.126
2.2.125
2.2.124
2.2.123
2.2.122
2.2.120
2.2.115
2.2.114
2.2.110
2.2.109
2.2.107
2.2.105
2.2.104
2.2.103
2.2.102
2.2.101
2.2.100
2.2.99
2.2.98
2.2.97
2.2.96
2.2.95
2.2.94
2.2.93
2.2.92
2.2.91
2.2.90
2.2.89
2.2.88
2.2.87
2.2.86
2.2.85
2.2.84
2.2.83
2.2.82
2.2.81
2.2.80
2.2.79
2.2.78
2.2.77
2.2.76
2.2.75
2.2.74
2.2.73
2.2.72
2.2.71
2.2.70
2.2.69
2.2.68
2.2.67
2.2.66
2.2.65
2.2.64
2.2.63
2.2.62
2.2.61
2.2.60
2.2.59
2.2.58
2.2.57
2.2.56
2.2.55
2.2.54
2.2.53
2.2.52
2.2.51
2.2.50
2.2.49
2.2.48
2.2.47
2.2.46
2.2.45
2.2.43
2.2.42
2.2.41
2.2.40
2.2.39
2.2.38
2.2.37
2.2.36
2.2.35
2.2.34
2.2.33
2.2.32
2.2.31
2.2.30
2.2.29
2.2.28
2.2.27
2.2.26
2.2.24
2.2.23
2.2.22
2.2.21
2.2.20
2.2.19
2.2.18
2.2.17
2.2.16
2.2.15
2.2.14
2.2.12
2.2.11
2.2.10
2.2.9
2.2.8
2.2.7
2.2.6
2.2.5
2.2.4
2.2.3
2.2.2
2.2.1
2.2.0
2.1.11
2.1.10
2.1.9
2.1.8
2.1.7
2.1.6
2.1.5
2.1.4
2.1.3
2.1.2
2.1.1
2.1.0
2.0.48
2.0.47
2.0.46
2.0.45
2.0.44
2.0.43
2.0.42
2.0.41
2.0.40
2.0.39
2.0.38
2.0.37
2.0.36
2.0.35
2.0.34
2.0.33
2.0.32
2.0.31
2.0.30
2.0.29
2.0.28
2.0.27
2.0.26
2.0.25
2.0.24
2.0.23
2.0.22
2.0.21
2.0.20
2.0.19
2.0.18
2.0.17