11package org .testcontainers .k3s ;
22
3- import org .junit .ClassRule ;
4- import org .junit .Test ;
3+ import org .junit .jupiter .api .AfterAll ;
4+ import org .junit .jupiter .api .BeforeAll ;
5+ import org .junit .jupiter .api .Test ;
56import org .testcontainers .containers .GenericContainer ;
67import org .testcontainers .containers .Network ;
78import org .testcontainers .containers .startupcheck .OneShotStartupCheckStrategy ;
1112import java .time .Duration ;
1213
1314import static org .assertj .core .api .Assertions .assertThat ;
15+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
1416
15- public class KubectlContainerTest {
17+ class KubectlContainerTest {
1618
17- public static Network network = Network .SHARED ;
19+ private static final Network network = Network .SHARED ;
1820
19- @ ClassRule
20- public static K3sContainer k3s = new K3sContainer (DockerImageName .parse ("rancher/k3s:v1.21.3-k3s1" ))
21+ private static final K3sContainer k3s = new K3sContainer (DockerImageName .parse ("rancher/k3s:v1.21.3-k3s1" ))
2122 .withNetwork (network )
2223 .withNetworkAliases ("k3s" );
2324
25+ @ BeforeAll
26+ static void setup () {
27+ k3s .start ();
28+ }
29+
30+ @ AfterAll
31+ static void teardown () {
32+ k3s .stop ();
33+ }
34+
2435 @ Test
2536 public void shouldExposeKubeConfigForNetworkAlias () throws Exception {
2637 String kubeConfigYaml = k3s .generateInternalKubeConfigYaml ("k3s" );
@@ -38,8 +49,9 @@ public void shouldExposeKubeConfigForNetworkAlias() throws Exception {
3849 }
3950 }
4051
41- @ Test ( expected = IllegalArgumentException . class )
52+ @ Test
4253 public void shouldThrowAnExceptionForUnknownNetworkAlias () {
43- k3s .generateInternalKubeConfigYaml ("not-set-network-alias" );
54+ assertThatThrownBy (() -> k3s .generateInternalKubeConfigYaml ("not-set-network-alias" ))
55+ .isInstanceOf (IllegalArgumentException .class );
4456 }
4557}
0 commit comments