@@ -14,6 +14,7 @@ import (
1414
1515 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1"
1616 "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client"
17+ esclient "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client"
1718 "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/observer"
1819 "github.com/elastic/cloud-on-k8s/pkg/utils/k8s"
1920 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -81,6 +82,41 @@ func Test_annotateWithUUID(t *testing.T) {
8182 require .True (t , AnnotatedForBootstrap (retrieved ))
8283}
8384
85+ func Test_clusterIsBootstrapped (t * testing.T ) {
86+ tests := []struct {
87+ name string
88+ state observer.State
89+ want bool
90+ }{
91+ {
92+ name : "empty state" ,
93+ state : observer.State {},
94+ want : false ,
95+ },
96+ {
97+ name : "cluster uuid empty" ,
98+ state : observer.State {ClusterInfo : & esclient.Info {}},
99+ want : false ,
100+ },
101+ {
102+ name : "cluster uuid _na_ (not available) yet, cluster is still forming" ,
103+ state : observer.State {ClusterInfo : & esclient.Info {ClusterUUID : "_na_" }},
104+ want : false ,
105+ },
106+ {
107+ name : "cluster uuid set, cluster bootstrapped" ,
108+ state : observer.State {ClusterInfo : & esclient.Info {ClusterUUID : "6902c192-ec1d-11e9-81b4-2a2ae2dbcce4" }},
109+ want : true ,
110+ },
111+ }
112+
113+ for _ , tt := range tests {
114+ t .Run (tt .name , func (t * testing.T ) {
115+ require .Equal (t , tt .want , clusterIsBootstrapped (tt .state ))
116+ })
117+ }
118+ }
119+
84120func TestReconcileClusterUUID (t * testing.T ) {
85121 require .NoError (t , v1beta1 .AddToScheme (scheme .Scheme ))
86122 tests := []struct {
0 commit comments