@@ -17,9 +17,9 @@ import (
17
17
"github.com/replicatedhq/ship/pkg/templates"
18
18
"github.com/replicatedhq/ship/pkg/test-mocks/lifecycle"
19
19
planner2 "github.com/replicatedhq/ship/pkg/test-mocks/planner"
20
- "github.com/replicatedhq/ship/pkg/test-mocks/state"
21
20
"github.com/replicatedhq/ship/pkg/testing/logger"
22
21
"github.com/replicatedhq/ship/pkg/testing/matchers"
22
+ "github.com/spf13/afero"
23
23
"github.com/spf13/viper"
24
24
"github.com/stretchr/testify/require"
25
25
)
@@ -333,16 +333,18 @@ func TestV2CompleteStep(t *testing.T) {
333
333
},
334
334
},
335
335
}
336
- mc := gomock .NewController (t )
337
- fakeState := state .NewMockManager (mc )
336
+
338
337
testLogger := & logger.TestLogger {T : t }
338
+ fs := afero.Afero {Fs : afero .NewMemMapFs ()}
339
+ realState := state2 .NewManager (testLogger , fs , viper .New ())
340
+ mc := gomock .NewController (t )
339
341
messenger := lifecycle .NewMockMessenger (mc )
340
342
renderer := lifecycle .NewMockRenderer (mc )
341
343
mockPlanner := planner2 .NewMockPlanner (mc )
342
344
v2 := & NavcycleRoutes {
343
- BuilderBuilder : templates .NewBuilderBuilder (testLogger , viper .New (), fakeState ),
345
+ BuilderBuilder : templates .NewBuilderBuilder (testLogger , viper .New (), realState ),
344
346
Logger : testLogger ,
345
- StateManager : fakeState ,
347
+ StateManager : realState ,
346
348
Messenger : messenger ,
347
349
Renderer : renderer ,
348
350
Planner : mockPlanner ,
@@ -352,14 +354,6 @@ func TestV2CompleteStep(t *testing.T) {
352
354
StepProgress : & daemontypes.ProgressMap {},
353
355
}
354
356
355
- fakeState .EXPECT ().TryLoad ().Return (state2.VersionedState {
356
- V1 : & state2.V1 {
357
- Lifecycle : & state2.Lifeycle {
358
- StepsCompleted : make (map [string ]interface {}),
359
- },
360
- },
361
- }, nil ).AnyTimes ()
362
-
363
357
if test .OnExecute != nil {
364
358
v2 .StepExecutor = test .OnExecute
365
359
}
@@ -379,10 +373,6 @@ func TestV2CompleteStep(t *testing.T) {
379
373
380
374
// send request
381
375
for _ , testCase := range test .POSTS {
382
- if testCase .ExpectState != nil && testCase .ExpectState .Test != nil {
383
- fakeState .EXPECT ().Save (testCase .ExpectState ).Return (nil )
384
- }
385
-
386
376
resp , err := http .Post (fmt .Sprintf ("%s%s" , addr , testCase .POST ), "application/json" , strings .NewReader ("" ))
387
377
req .NoError (err )
388
378
req .Equal (testCase .ExpectStatus , resp .StatusCode )
@@ -398,6 +388,15 @@ func TestV2CompleteStep(t *testing.T) {
398
388
bodyForDebug = []byte (err .Error ())
399
389
}
400
390
req .Empty (diff , "\n expect: %s\n actual: %s\n diff: %s" , bodyForDebug , string (bytes ), strings .Join (diff , "\n " ))
391
+
392
+ if testCase .ExpectState != nil && testCase .ExpectState .Test != nil {
393
+ // there is almost certainly a better solution than this
394
+ time .Sleep (time .Duration (time .Millisecond * 500 ))
395
+
396
+ loadState , err := realState .TryLoad ()
397
+ req .NoError (err )
398
+ req .True (testCase .ExpectState .Test (loadState ), testCase .ExpectState .Describe )
399
+ }
401
400
}
402
401
}()
403
402
})
0 commit comments