1- package interactor
1+ package interactor_test
22
33import (
44 "context"
77
88 "github.com/AlekSi/pointer"
99 "github.com/golang/mock/gomock"
10- "go.uber.org/zap"
1110
11+ i "github.com/gitploy-io/gitploy/internal/interactor"
1212 "github.com/gitploy-io/gitploy/internal/interactor/mock"
1313 "github.com/gitploy-io/gitploy/model/ent"
1414 "github.com/gitploy-io/gitploy/model/ent/deployment"
@@ -17,14 +17,6 @@ import (
1717 "github.com/gitploy-io/gitploy/pkg/e"
1818)
1919
20- func newMockDeploymentInteractor (store Store , scm SCM ) * DeploymentInteractor {
21- return & DeploymentInteractor {
22- store : store ,
23- scm : scm ,
24- log : zap .L (),
25- }
26- }
27-
2820func TestInteractor_IsApproved (t * testing.T ) {
2921 t .Run ("Return false when a review is rejected." , func (t * testing.T ) {
3022 ctrl := gomock .NewController (t )
@@ -44,10 +36,13 @@ func TestInteractor_IsApproved(t *testing.T) {
4436 },
4537 }, nil )
4638
47- i := newMockDeploymentInteractor (store , scm )
39+ it := i .NewInteractor (& i.InteractorConfig {
40+ Store : store ,
41+ SCM : scm ,
42+ })
4843
4944 expected := false
50- if ret := i .IsApproved (context .Background (), & ent.Deployment {}); ret != expected {
45+ if ret := it .IsApproved (context .Background (), & ent.Deployment {}); ret != expected {
5146 t .Fatalf ("IsApproved = %v, wanted %v" , ret , expected )
5247 }
5348 })
@@ -75,9 +70,12 @@ func TestInteractor_Deploy(t *testing.T) {
7570 store := mock .NewMockStore (ctrl )
7671 scm := mock .NewMockSCM (ctrl )
7772
78- i := newMockDeploymentInteractor (store , scm )
73+ it := i .NewInteractor (& i.InteractorConfig {
74+ Store : store ,
75+ SCM : scm ,
76+ })
7977
80- _ , err := i .Deploy (context .Background (), & ent.User {}, & ent.Repo {}, input .d , input .e )
78+ _ , err := it .Deploy (context .Background (), & ent.User {}, & ent.Repo {}, input .d , input .e )
8179 if ! e .HasErrorCode (err , e .ErrorCodeEntityUnprocessable ) {
8280 t .Fatalf ("Deploy' error = %v, wanted ErrorCodeDeploymentLocked" , err )
8381 }
@@ -93,9 +91,12 @@ func TestInteractor_Deploy(t *testing.T) {
9391 HasLockOfRepoForEnv (ctx , gomock .AssignableToTypeOf (& ent.Repo {}), "" ).
9492 Return (true , nil )
9593
96- i := newMockDeploymentInteractor (store , scm )
94+ it := i .NewInteractor (& i.InteractorConfig {
95+ Store : store ,
96+ SCM : scm ,
97+ })
9798
98- _ , err := i .Deploy (context .Background (), & ent.User {}, & ent.Repo {}, & ent.Deployment {}, & extent.Env {})
99+ _ , err := it .Deploy (context .Background (), & ent.User {}, & ent.Repo {}, & ent.Deployment {}, & extent.Env {})
99100 if ! e .HasErrorCode (err , e .ErrorCodeDeploymentLocked ) {
100101 t .Fatalf ("Deploy' error = %v, wanted ErrorCodeDeploymentLocked" , err )
101102 }
@@ -159,9 +160,12 @@ func TestInteractor_Deploy(t *testing.T) {
159160 EXPECT ().
160161 CreateDeploymentStatus (ctx , gomock .AssignableToTypeOf (& ent.DeploymentStatus {}))
161162
162- i := newMockDeploymentInteractor (store , scm )
163+ it := i .NewInteractor (& i.InteractorConfig {
164+ Store : store ,
165+ SCM : scm ,
166+ })
163167
164- d , err := i .Deploy (context .Background (), & ent.User {}, & ent.Repo {}, input .d , input .e )
168+ d , err := it .Deploy (context .Background (), & ent.User {}, & ent.Repo {}, input .d , input .e )
165169 if err != nil {
166170 t .Fatalf ("Deploy returns a error: %s" , err )
167171 }
@@ -243,9 +247,12 @@ func TestInteractor_Deploy(t *testing.T) {
243247 CreateEvent (ctx , gomock .AssignableToTypeOf (& ent.Event {})).
244248 Return (& ent.Event {}, nil )
245249
246- i := newMockDeploymentInteractor (store , scm )
250+ it := i .NewInteractor (& i.InteractorConfig {
251+ Store : store ,
252+ SCM : scm ,
253+ })
247254
248- d , err := i .Deploy (context .Background (), & ent.User {}, & ent.Repo {}, input .d , input .e )
255+ d , err := it .Deploy (context .Background (), & ent.User {}, & ent.Repo {}, input .d , input .e )
249256 if err != nil {
250257 t .Errorf ("Deploy returns a error: %s" , err )
251258 t .FailNow ()
@@ -281,9 +288,12 @@ func TestInteractor_DeployToRemote(t *testing.T) {
281288 store := mock .NewMockStore (ctrl )
282289 scm := mock .NewMockSCM (ctrl )
283290
284- i := newMockDeploymentInteractor (store , scm )
291+ it := i .NewInteractor (& i.InteractorConfig {
292+ Store : store ,
293+ SCM : scm ,
294+ })
285295
286- _ , err := i .DeployToRemote (context .Background (), & ent.User {}, & ent.Repo {}, input .d , input .e )
296+ _ , err := it .DeployToRemote (context .Background (), & ent.User {}, & ent.Repo {}, input .d , input .e )
287297 if ! e .HasErrorCode (err , e .ErrorCodeDeploymentStatusInvalid ) {
288298 t .Fatalf ("CreateRemoteDeployment error = %v, wanted ErrorCodeDeploymentStatusInvalid" , err )
289299 }
@@ -345,9 +355,12 @@ func TestInteractor_DeployToRemote(t *testing.T) {
345355 EXPECT ().
346356 CreateDeploymentStatus (ctx , gomock .AssignableToTypeOf (& ent.DeploymentStatus {}))
347357
348- i := newMockDeploymentInteractor (store , scm )
358+ it := i .NewInteractor (& i.InteractorConfig {
359+ Store : store ,
360+ SCM : scm ,
361+ })
349362
350- d , err := i .DeployToRemote (context .Background (), & ent.User {}, & ent.Repo {}, input .d , input .e )
363+ d , err := it .DeployToRemote (context .Background (), & ent.User {}, & ent.Repo {}, input .d , input .e )
351364 if err != nil {
352365 t .Errorf ("CreateRemoteDeployment returns a error: %s" , err )
353366 t .FailNow ()
0 commit comments