4
4
import com .github .containersolutions .operator .sample .TestCustomResourceSpec ;
5
5
import io .fabric8 .kubernetes .api .model .ConfigMap ;
6
6
import io .fabric8 .kubernetes .api .model .ObjectMetaBuilder ;
7
- import org .junit .jupiter .api .BeforeAll ;
8
- import org .junit .jupiter .api .BeforeEach ;
9
7
import org .junit .jupiter .api .Test ;
10
8
import org .junit .jupiter .api .TestInstance ;
11
9
import org .slf4j .Logger ;
15
13
16
14
import static com .github .containersolutions .operator .IntegrationTestSupport .TEST_NAMESPACE ;
17
15
import static org .assertj .core .api .Assertions .assertThat ;
18
- import static org .assertj .core .api .Assertions .fail ;
19
16
import static org .awaitility .Awaitility .await ;
20
17
21
18
@ TestInstance (TestInstance .Lifecycle .PER_CLASS )
@@ -24,51 +21,69 @@ public class ControllerExecutionIT {
24
21
private final static Logger log = LoggerFactory .getLogger (ControllerExecutionIT .class );
25
22
private IntegrationTestSupport integrationTestSupport = new IntegrationTestSupport ();
26
23
27
- @ BeforeAll
28
- public void setup () {
29
- integrationTestSupport .initialize ();
30
- }
31
-
32
- @ BeforeEach
33
- public void cleanup () {
24
+ public void initAndCleanup (boolean controllerStatusUpdate ) {
25
+ integrationTestSupport .initialize (controllerStatusUpdate );
34
26
integrationTestSupport .cleanup ();
35
27
}
36
28
37
29
@ Test
38
- public void configMapGetsCreatedForTestCustomResource () throws Exception {
30
+ public void configMapGetsCreatedForTestCustomResource () {
31
+ initAndCleanup (true );
39
32
integrationTestSupport .teardownIfSuccess (() -> {
40
- TestCustomResource resource = new TestCustomResource ();
41
- resource .setMetadata (new ObjectMetaBuilder ()
42
- .withName ("test-custom-resource" )
43
- .withNamespace (TEST_NAMESPACE )
44
- .build ());
45
- resource .setKind ("CustomService" );
46
- resource .setSpec (new TestCustomResourceSpec ());
47
- resource .getSpec ().setConfigMapName ("test-config-map" );
48
- resource .getSpec ().setKey ("test-key" );
49
- resource .getSpec ().setValue ("test-value" );
33
+ TestCustomResource resource = testCustomResource ();
34
+
50
35
integrationTestSupport .getCrOperations ().inNamespace (TEST_NAMESPACE ).create (resource );
51
36
52
- await ("configmap created" ).atMost (5 , TimeUnit .SECONDS )
53
- .untilAsserted (() -> {
54
- ConfigMap configMap = integrationTestSupport .getK8sClient ().configMaps ().inNamespace (TEST_NAMESPACE )
55
- .withName ("test-config-map" ).get ();
56
- assertThat (configMap ).isNotNull ();
57
- assertThat (configMap .getData ().get ("test-key" )).isEqualTo ("test-value" );
58
- });
59
- await ("cr status updated" ).atMost (5 , TimeUnit .SECONDS )
60
- .untilAsserted (() -> {
61
- TestCustomResource cr = integrationTestSupport .getCrOperations ().inNamespace (TEST_NAMESPACE ).withName ("test-custom-resource" ).get ();
62
- assertThat (cr ).isNotNull ();
63
- assertThat (cr .getStatus ()).isNotNull ();
64
- assertThat (cr .getStatus ().getConfigMapStatus ()).isEqualTo ("ConfigMap Ready" );
65
- });
37
+ awaitResourcesCreatedOrUpdated ();
38
+ awaitStatusUpdated ();
66
39
});
67
40
}
68
41
69
42
@ Test
70
43
public void eventIsSkippedChangedOnMetadataOnlyUpdate () {
71
- fail ("TODO" );
44
+ initAndCleanup (false );
45
+ integrationTestSupport .teardownIfSuccess (() -> {
46
+ TestCustomResource resource = testCustomResource ();
47
+
48
+ integrationTestSupport .getCrOperations ().inNamespace (TEST_NAMESPACE ).create (resource );
49
+
50
+ awaitResourcesCreatedOrUpdated ();
51
+ assertThat (integrationTestSupport .numberOfControllerExecutions ()).isEqualTo (1 );
52
+ });
53
+ }
54
+
55
+ void awaitResourcesCreatedOrUpdated () {
56
+ await ("configmap created" ).atMost (5 , TimeUnit .SECONDS )
57
+ .untilAsserted (() -> {
58
+ ConfigMap configMap = integrationTestSupport .getK8sClient ().configMaps ().inNamespace (TEST_NAMESPACE )
59
+ .withName ("test-config-map" ).get ();
60
+ assertThat (configMap ).isNotNull ();
61
+ assertThat (configMap .getData ().get ("test-key" )).isEqualTo ("test-value" );
62
+ });
63
+ }
64
+
65
+ void awaitStatusUpdated () {
66
+ await ("cr status updated" ).atMost (5 , TimeUnit .SECONDS )
67
+ .untilAsserted (() -> {
68
+ TestCustomResource cr = integrationTestSupport .getCrOperations ().inNamespace (TEST_NAMESPACE ).withName ("test-custom-resource" ).get ();
69
+ assertThat (cr ).isNotNull ();
70
+ assertThat (cr .getStatus ()).isNotNull ();
71
+ assertThat (cr .getStatus ().getConfigMapStatus ()).isEqualTo ("ConfigMap Ready" );
72
+ });
73
+ }
74
+
75
+ private TestCustomResource testCustomResource () {
76
+ TestCustomResource resource = new TestCustomResource ();
77
+ resource .setMetadata (new ObjectMetaBuilder ()
78
+ .withName ("test-custom-resource" )
79
+ .withNamespace (TEST_NAMESPACE )
80
+ .build ());
81
+ resource .setKind ("CustomService" );
82
+ resource .setSpec (new TestCustomResourceSpec ());
83
+ resource .getSpec ().setConfigMapName ("test-config-map" );
84
+ resource .getSpec ().setKey ("test-key" );
85
+ resource .getSpec ().setValue ("test-value" );
86
+ return resource ;
72
87
}
73
88
74
89
}
0 commit comments