@@ -26,6 +26,7 @@ func TestService_CreateResource(t *testing.T) {
26
26
setup func (t * testing.T ) * core.Service
27
27
res resource.Resource
28
28
want * resource.Resource
29
+ options []core.Options
29
30
wantErr error
30
31
}{
31
32
{
@@ -278,6 +279,41 @@ func TestService_CreateResource(t *testing.T) {
278
279
},
279
280
wantErr : nil ,
280
281
},
282
+ {
283
+ name : "AlreadyExistsWithDryRun" ,
284
+ setup : func (t * testing.T ) * core.Service {
285
+ t .Helper ()
286
+ mod := & mocks.ModuleService {}
287
+ mod .EXPECT ().
288
+ PlanAction (mock .Anything , mock .Anything , mock .Anything ).
289
+ Return (& resource.Resource {
290
+ Kind : "mock" ,
291
+ Name : "child" ,
292
+ Project : "project" ,
293
+ State : resource.State {Status : resource .StatusCompleted },
294
+ }, nil ).Once ()
295
+
296
+ resourceRepo := & mocks.ResourceStore {}
297
+
298
+ return core .New (resourceRepo , mod , deadClock , defaultSyncBackoff , defaultMaxRetries )
299
+ },
300
+ res : resource.Resource {
301
+ Kind : "mock" ,
302
+ Name : "child" ,
303
+ Project : "project" ,
304
+ },
305
+ want : & resource.Resource {
306
+ URN : "orn:entropy:mock:project:child" ,
307
+ Kind : "mock" ,
308
+ Name : "child" ,
309
+ Project : "project" ,
310
+ State : resource.State {Status : resource .StatusCompleted },
311
+ CreatedAt : frozenTime ,
312
+ UpdatedAt : frozenTime ,
313
+ },
314
+ options : []core.Options {core .WithDryRun (true )},
315
+ wantErr : nil ,
316
+ },
281
317
}
282
318
283
319
for _ , tt := range tests {
@@ -286,7 +322,7 @@ func TestService_CreateResource(t *testing.T) {
286
322
t .Parallel ()
287
323
svc := tt .setup (t )
288
324
289
- got , err := svc .CreateResource (context .Background (), tt .res )
325
+ got , err := svc .CreateResource (context .Background (), tt .res , tt . options ... )
290
326
if tt .wantErr != nil {
291
327
assert .Error (t , err )
292
328
assert .True (t , errors .Is (err , tt .wantErr ))
@@ -310,12 +346,25 @@ func TestService_UpdateResource(t *testing.T) {
310
346
CreatedAt : frozenTime ,
311
347
}
312
348
349
+ testResourceForDryRun := resource.Resource {
350
+ URN : "orn:entropy:mock:project:childtwo" ,
351
+ Kind : "mock" ,
352
+ Name : "childtwo" ,
353
+ Project : "project" ,
354
+ State : resource.State {Status : resource .StatusCompleted },
355
+ Spec : resource.Spec {
356
+ Configs : []byte (`{"foo": "bar-old"}` ),
357
+ },
358
+ CreatedAt : frozenTime ,
359
+ }
360
+
313
361
tests := []struct {
314
362
name string
315
363
setup func (t * testing.T ) * core.Service
316
364
urn string
317
365
update resource.UpdateRequest
318
366
want * resource.Resource
367
+ options []core.Options
319
368
wantErr error
320
369
}{
321
370
{
@@ -472,6 +521,57 @@ func TestService_UpdateResource(t *testing.T) {
472
521
},
473
522
wantErr : nil ,
474
523
},
524
+ {
525
+ name : "SuccessWithDryRun" ,
526
+ setup : func (t * testing.T ) * core.Service {
527
+ t .Helper ()
528
+ mod := & mocks.ModuleService {}
529
+ mod .EXPECT ().
530
+ PlanAction (mock .Anything , mock .Anything , mock .Anything ).
531
+ Return (& resource.Resource {
532
+ URN : "orn:entropy:mock:project:childtwo" ,
533
+ Kind : "mock" ,
534
+ Name : "childtwo" ,
535
+ Project : "project" ,
536
+ Spec : resource.Spec {
537
+ Configs : []byte (`{"foo": "bar"}` ),
538
+ },
539
+ State : resource.State {Status : resource .StatusPending },
540
+ CreatedAt : frozenTime ,
541
+ }, nil ).Once ()
542
+ mod .EXPECT ().
543
+ GetOutput (mock .Anything , mock .Anything ).
544
+ Return (nil , nil ).
545
+ Once ()
546
+
547
+ resourceRepo := & mocks.ResourceStore {}
548
+ resourceRepo .EXPECT ().
549
+ GetByURN (mock .Anything , "orn:entropy:mock:project:childtwo" ).
550
+ Return (& testResourceForDryRun , nil ).Once ()
551
+
552
+ return core .New (resourceRepo , mod , deadClock , defaultSyncBackoff , defaultMaxRetries )
553
+ },
554
+ urn : "orn:entropy:mock:project:childtwo" ,
555
+ update : resource.UpdateRequest {
556
+ Spec : resource.Spec {Configs : []byte (`{"foo": "bar"}` )},
557
+ Labels : map [string ]string {"created_by" : "test_user" , "group" : "test_group" },
558
+ },
559
+ want : & resource.Resource {
560
+ URN : "orn:entropy:mock:project:childtwo" ,
561
+ Kind : "mock" ,
562
+ Name : "childtwo" ,
563
+ Project : "project" ,
564
+ CreatedAt : frozenTime ,
565
+ UpdatedAt : frozenTime ,
566
+ State : resource.State {Status : resource .StatusPending },
567
+ Labels : map [string ]string {"created_by" : "test_user" , "group" : "test_group" },
568
+ Spec : resource.Spec {
569
+ Configs : []byte (`{"foo": "bar"}` ),
570
+ },
571
+ },
572
+ options : []core.Options {core .WithDryRun (true )},
573
+ wantErr : nil ,
574
+ },
475
575
}
476
576
477
577
for _ , tt := range tests {
@@ -480,7 +580,7 @@ func TestService_UpdateResource(t *testing.T) {
480
580
t .Parallel ()
481
581
svc := tt .setup (t )
482
582
483
- got , err := svc .UpdateResource (context .Background (), tt .urn , tt .update )
583
+ got , err := svc .UpdateResource (context .Background (), tt .urn , tt .update , tt . options ... )
484
584
if tt .wantErr != nil {
485
585
assert .Error (t , err )
486
586
assert .True (t , errors .Is (err , tt .wantErr ))
@@ -641,6 +741,7 @@ func TestService_ApplyAction(t *testing.T) {
641
741
urn string
642
742
action module.ActionRequest
643
743
want * resource.Resource
744
+ options []core.Options
644
745
wantErr error
645
746
}{
646
747
{
@@ -771,6 +872,54 @@ func TestService_ApplyAction(t *testing.T) {
771
872
},
772
873
wantErr : nil ,
773
874
},
875
+ {
876
+ name : "SuccessWithDryRun" ,
877
+ setup : func (t * testing.T ) * core.Service {
878
+ t .Helper ()
879
+ mod := & mocks.ModuleService {}
880
+ mod .EXPECT ().
881
+ PlanAction (mock .Anything , mock .Anything , sampleAction ).
882
+ Return (& resource.Resource {
883
+ URN : "orn:entropy:mock:foo:bar" ,
884
+ Kind : "mock" ,
885
+ Project : "foo" ,
886
+ Name : "bar" ,
887
+ State : resource.State {Status : resource .StatusPending },
888
+ }, nil ).Once ()
889
+ mod .EXPECT ().
890
+ GetOutput (mock .Anything , mock .Anything ).
891
+ Return (nil , nil ).
892
+ Once ()
893
+
894
+ resourceRepo := & mocks.ResourceStore {}
895
+ resourceRepo .EXPECT ().
896
+ GetByURN (mock .Anything , "orn:entropy:mock:foo:bar" ).
897
+ Return (& resource.Resource {
898
+ URN : "orn:entropy:mock:foo:bar" ,
899
+ Kind : "mock" ,
900
+ Project : "foo" ,
901
+ Name : "bar" ,
902
+ CreatedAt : frozenTime ,
903
+ State : resource.State {Status : resource .StatusCompleted },
904
+ }, nil ).
905
+ Once ()
906
+
907
+ return core .New (resourceRepo , mod , deadClock , defaultSyncBackoff , defaultMaxRetries )
908
+ },
909
+ urn : "orn:entropy:mock:foo:bar" ,
910
+ action : sampleAction ,
911
+ want : & resource.Resource {
912
+ URN : "orn:entropy:mock:foo:bar" ,
913
+ Kind : "mock" ,
914
+ Project : "foo" ,
915
+ Name : "bar" ,
916
+ State : resource.State {Status : resource .StatusPending },
917
+ CreatedAt : frozenTime ,
918
+ UpdatedAt : frozenTime ,
919
+ },
920
+ wantErr : nil ,
921
+ options : []core.Options {core .WithDryRun (true )},
922
+ },
774
923
}
775
924
776
925
for _ , tt := range tests {
@@ -779,7 +928,7 @@ func TestService_ApplyAction(t *testing.T) {
779
928
t .Parallel ()
780
929
svc := tt .setup (t )
781
930
782
- got , err := svc .ApplyAction (context .Background (), tt .urn , tt .action )
931
+ got , err := svc .ApplyAction (context .Background (), tt .urn , tt .action , tt . options ... )
783
932
if tt .wantErr != nil {
784
933
assert .Error (t , err )
785
934
assert .True (t , errors .Is (err , tt .wantErr ), cmp .Diff (tt .want , err ))
0 commit comments