@@ -5,10 +5,6 @@ import (
55 "testing"
66 "time"
77
8- "github.com/stretchr/testify/assert"
9- "github.com/stretchr/testify/mock"
10- "github.com/stretchr/testify/require"
11-
128 appcontroller "github.com/replicatedhq/embedded-cluster/api/controllers/app/install"
139 appconfig "github.com/replicatedhq/embedded-cluster/api/internal/managers/app/config"
1410 "github.com/replicatedhq/embedded-cluster/api/internal/managers/kubernetes/infra"
@@ -23,6 +19,9 @@ import (
2319 "github.com/replicatedhq/embedded-cluster/pkg/release"
2420 kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
2521 "github.com/replicatedhq/kotskinds/multitype"
22+ "github.com/stretchr/testify/assert"
23+ "github.com/stretchr/testify/mock"
24+ "github.com/stretchr/testify/require"
2625)
2726
2827func TestGetInstallationConfig (t * testing.T ) {
@@ -127,7 +126,7 @@ func TestConfigureInstallation(t *testing.T) {
127126 config types.KubernetesInstallationConfig
128127 currentState statemachine.State
129128 expectedState statemachine.State
130- setupMock func (* installation.MockInstallationManager , * kubernetesinstallation.MockInstallation , types.KubernetesInstallationConfig )
129+ setupMock func (* installation.MockInstallationManager , * kubernetesinstallation.MockInstallation , types.KubernetesInstallationConfig , * store. MockStore , * metrics. MockReporter )
131130 expectedErr bool
132131 }{
133132 {
@@ -140,7 +139,8 @@ func TestConfigureInstallation(t *testing.T) {
140139 },
141140 currentState : states .StateApplicationConfigured ,
142141 expectedState : states .StateInstallationConfigured ,
143- setupMock : func (m * installation.MockInstallationManager , ki * kubernetesinstallation.MockInstallation , config types.KubernetesInstallationConfig ) {
142+
143+ setupMock : func (m * installation.MockInstallationManager , ki * kubernetesinstallation.MockInstallation , config types.KubernetesInstallationConfig , st * store.MockStore , mr * metrics.MockReporter ) {
144144 mock .InOrder (
145145 m .On ("ConfigureInstallation" , mock .Anything , ki , config ).Return (nil ),
146146 )
@@ -152,19 +152,49 @@ func TestConfigureInstallation(t *testing.T) {
152152 config : types.KubernetesInstallationConfig {},
153153 currentState : states .StateApplicationConfigured ,
154154 expectedState : states .StateInstallationConfigurationFailed ,
155- setupMock : func (m * installation.MockInstallationManager , ki * kubernetesinstallation.MockInstallation , config types.KubernetesInstallationConfig ) {
156- m .On ("ConfigureInstallation" , mock .Anything , ki , config ).Return (errors .New ("validation error" ))
155+ setupMock : func (m * installation.MockInstallationManager , ki * kubernetesinstallation.MockInstallation , config types.KubernetesInstallationConfig , st * store.MockStore , mr * metrics.MockReporter ) {
156+ mock .InOrder (
157+ m .On ("ConfigureInstallation" , mock .Anything , ki , config ).Return (errors .New ("validation error" )),
158+ st .KubernetesInstallationMockStore .On ("GetStatus" ).Return (types.Status {Description : "validation error" }, nil ),
159+ mr .On ("ReportInstallationFailed" , mock .Anything , errors .New ("validation error" )),
160+ )
157161 },
158162 expectedErr : true ,
159163 },
160164 {
161- name : "invalid state transition" ,
162- config : types.KubernetesInstallationConfig {
163- AdminConsolePort : 9000 ,
165+ name : "set config error on retry from already configured" ,
166+ config : types.KubernetesInstallationConfig {},
167+ currentState : states .StateInstallationConfigured ,
168+ expectedState : states .StateInstallationConfigurationFailed ,
169+ setupMock : func (m * installation.MockInstallationManager , ki * kubernetesinstallation.MockInstallation , config types.KubernetesInstallationConfig , st * store.MockStore , mr * metrics.MockReporter ) {
170+ mock .InOrder (
171+ m .On ("ConfigureInstallation" , mock .Anything , ki , config ).Return (errors .New ("validation error" )),
172+ st .KubernetesInstallationMockStore .On ("GetStatus" ).Return (types.Status {Description : "validation error" }, nil ),
173+ mr .On ("ReportInstallationFailed" , mock .Anything , errors .New ("validation error" )),
174+ )
164175 },
176+ expectedErr : true ,
177+ },
178+ {
179+ name : "set config error on retry from that failed to configure" ,
180+ config : types.KubernetesInstallationConfig {},
181+ currentState : states .StateInstallationConfigurationFailed ,
182+ expectedState : states .StateInstallationConfigurationFailed ,
183+ setupMock : func (m * installation.MockInstallationManager , ki * kubernetesinstallation.MockInstallation , config types.KubernetesInstallationConfig , st * store.MockStore , mr * metrics.MockReporter ) {
184+ mock .InOrder (
185+ m .On ("ConfigureInstallation" , mock .Anything , ki , config ).Return (errors .New ("validation error" )),
186+ st .KubernetesInstallationMockStore .On ("GetStatus" ).Return (types.Status {Description : "validation error" }, nil ),
187+ mr .On ("ReportInstallationFailed" , mock .Anything , errors .New ("validation error" )),
188+ )
189+ },
190+ expectedErr : true ,
191+ },
192+ {
193+ name : "invalid state transition" ,
194+ config : types.KubernetesInstallationConfig {},
165195 currentState : states .StateInfrastructureInstalling ,
166196 expectedState : states .StateInfrastructureInstalling ,
167- setupMock : func (m * installation.MockInstallationManager , ki * kubernetesinstallation.MockInstallation , config types.KubernetesInstallationConfig ) {
197+ setupMock : func (m * installation.MockInstallationManager , ki * kubernetesinstallation.MockInstallation , config types.KubernetesInstallationConfig , st * store. MockStore , mr * metrics. MockReporter ) {
168198 },
169199 expectedErr : true ,
170200 },
@@ -177,13 +207,17 @@ func TestConfigureInstallation(t *testing.T) {
177207 sm := NewStateMachine (WithCurrentState (tt .currentState ))
178208
179209 mockManager := & installation.MockInstallationManager {}
210+ metricsReporter := & metrics.MockReporter {}
211+ mockStore := & store.MockStore {}
180212
181- tt .setupMock (mockManager , mockInstallation , tt .config )
213+ tt .setupMock (mockManager , mockInstallation , tt .config , mockStore , metricsReporter )
182214
183215 controller , err := NewInstallController (
184216 WithInstallation (mockInstallation ),
185217 WithStateMachine (sm ),
186218 WithInstallationManager (mockManager ),
219+ WithStore (mockStore ),
220+ WithMetricsReporter (metricsReporter ),
187221 WithReleaseData (getTestReleaseData (& kotsv1beta1.Config {})),
188222 )
189223 require .NoError (t , err )
@@ -193,8 +227,6 @@ func TestConfigureInstallation(t *testing.T) {
193227 assert .Error (t , err )
194228 } else {
195229 assert .NoError (t , err )
196-
197- assert .NotEqual (t , tt .currentState , sm .CurrentState (), "state should have changed and should not be %s" , tt .currentState )
198230 }
199231
200232 assert .Eventually (t , func () bool {
@@ -203,6 +235,10 @@ func TestConfigureInstallation(t *testing.T) {
203235 assert .False (t , sm .IsLockAcquired (), "state machine should not be locked after configuration" )
204236
205237 mockManager .AssertExpectations (t )
238+ metricsReporter .AssertExpectations (t )
239+ mockStore .KubernetesInfraMockStore .AssertExpectations (t )
240+ mockStore .KubernetesInstallationMockStore .AssertExpectations (t )
241+ mockStore .AppConfigMockStore .AssertExpectations (t )
206242 mockInstallation .AssertExpectations (t )
207243 })
208244 }
@@ -301,7 +337,6 @@ func TestSetupInfra(t *testing.T) {
301337 mock .InOrder (
302338 fm .On ("Install" , mock .Anything , ki ).Return (nil ),
303339 // TODO: we are not yet reporting
304- // mr.On("ReportInstallationSucceeded", mock.Anything),
305340 )
306341 },
307342 expectedErr : nil ,
@@ -313,9 +348,8 @@ func TestSetupInfra(t *testing.T) {
313348 setupMocks : func (ki kubernetesinstallation.Installation , im * installation.MockInstallationManager , fm * infra.MockInfraManager , mr * metrics.MockReporter , st * store.MockStore , am * appconfig.MockAppConfigManager ) {
314349 mock .InOrder (
315350 fm .On ("Install" , mock .Anything , ki ).Return (errors .New ("install error" )),
316- st .LinuxInfraMockStore .On ("GetStatus" ).Return (types.Status {Description : "install error" }, nil ),
317- // TODO: we are not yet reporting
318- // mr.On("ReportInstallationFailed", mock.Anything, errors.New("install error")),
351+ st .KubernetesInfraMockStore .On ("GetStatus" ).Return (types.Status {Description : "install error" }, nil ),
352+ mr .On ("ReportInstallationFailed" , mock .Anything , errors .New ("install error" )),
319353 )
320354 },
321355 expectedErr : nil ,
@@ -327,7 +361,7 @@ func TestSetupInfra(t *testing.T) {
327361 setupMocks : func (ki kubernetesinstallation.Installation , im * installation.MockInstallationManager , fm * infra.MockInfraManager , mr * metrics.MockReporter , st * store.MockStore , am * appconfig.MockAppConfigManager ) {
328362 mock .InOrder (
329363 fm .On ("Install" , mock .Anything , ki ).Return (errors .New ("install error" )),
330- st .LinuxInfraMockStore .On ("GetStatus" ).Return (nil , assert .AnError ),
364+ st .KubernetesInfraMockStore .On ("GetStatus" ).Return (nil , assert .AnError ),
331365 )
332366 },
333367 expectedErr : nil ,
@@ -339,9 +373,8 @@ func TestSetupInfra(t *testing.T) {
339373 setupMocks : func (ki kubernetesinstallation.Installation , im * installation.MockInstallationManager , fm * infra.MockInfraManager , mr * metrics.MockReporter , st * store.MockStore , am * appconfig.MockAppConfigManager ) {
340374 mock .InOrder (
341375 fm .On ("Install" , mock .Anything , ki ).Panic ("this is a panic" ),
342- st .LinuxInfraMockStore .On ("GetStatus" ).Return (types.Status {Description : "this is a panic" }, nil ),
343- // TODO: we are not yet reporting
344- // mr.On("ReportInstallationFailed", mock.Anything, errors.New("this is a panic")),
376+ st .KubernetesInfraMockStore .On ("GetStatus" ).Return (types.Status {Description : "this is a panic" }, nil ),
377+ mr .On ("ReportInstallationFailed" , mock .Anything , errors .New ("this is a panic" )),
345378 )
346379 },
347380 expectedErr : nil ,
0 commit comments