-
Notifications
You must be signed in to change notification settings - Fork 700
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test/mocks: added mocks for test cases (#4133)
* fix: use local mongo operator Signed-off-by: SohamRatnaparkhi <soham.ratnaparkhi@gmail.com> * feat: gitops mocks added Signed-off-by: SohamRatnaparkhi <soham.ratnaparkhi@gmail.com> * feat: mongo mocks added Signed-off-by: SohamRatnaparkhi <soham.ratnaparkhi@gmail.com> * feat: chaos experiment run mocks added Signed-off-by: SohamRatnaparkhi <soham.ratnaparkhi@gmail.com> * feat: infra mocks added Signed-off-by: SohamRatnaparkhi <soham.ratnaparkhi@gmail.com> * feat: chaos experiment mocks added Signed-off-by: SohamRatnaparkhi <soham.ratnaparkhi@gmail.com> --------- Signed-off-by: SohamRatnaparkhi <soham.ratnaparkhi@gmail.com> Co-authored-by: Amit Kumar Das <amit.das@harness.io> Co-authored-by: Namkyu Park <53862866+namkyu1999@users.noreply.github.com> Co-authored-by: Saranya Jena <saranya.jena@harness.io>
- Loading branch information
1 parent
ba00736
commit ff599d4
Showing
8 changed files
with
354 additions
and
25 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
chaoscenter/graphql/server/pkg/chaos_experiment/model/mocks/service.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package mocks | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model" | ||
store "github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/data-store" | ||
dbChaosExperiment "github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/database/mongodb/chaos_experiment" | ||
"github.com/stretchr/testify/mock" | ||
"go.mongodb.org/mongo-driver/bson" | ||
) | ||
|
||
type ChaosExperimentService struct { | ||
mock.Mock | ||
} | ||
|
||
func (m *ChaosExperimentService) ProcessExperiment(workflow *model.ChaosExperimentRequest, projectID string, revID string) (*model.ChaosExperimentRequest, *dbChaosExperiment.ChaosExperimentType, error) { | ||
args := m.Called(workflow, projectID, revID) | ||
return args.Get(0).(*model.ChaosExperimentRequest), args.Get(1).(*dbChaosExperiment.ChaosExperimentType), args.Error(2) | ||
} | ||
|
||
func (m *ChaosExperimentService) ProcessExperimentCreation(ctx context.Context, input *model.ChaosExperimentRequest, username string, projectID string, wfType *dbChaosExperiment.ChaosExperimentType, revisionID string, r *store.StateData) error { | ||
args := m.Called(ctx, input, username, projectID, wfType, revisionID, r) | ||
return args.Error(0) | ||
} | ||
|
||
func (m *ChaosExperimentService) ProcessExperimentUpdate(workflow *model.ChaosExperimentRequest, username string, wfType *dbChaosExperiment.ChaosExperimentType, revisionID string, updateRevision bool, projectID string, r *store.StateData) error { | ||
args := m.Called(workflow, username, wfType, revisionID, updateRevision, projectID, r) | ||
return args.Error(0) | ||
} | ||
|
||
func (m *ChaosExperimentService) ProcessExperimentDelete(query bson.D, workflow dbChaosExperiment.ChaosExperimentRequest, username string, r *store.StateData) error { | ||
args := m.Called(query, workflow, username, r) | ||
return args.Error(0) | ||
} |
99 changes: 99 additions & 0 deletions
99
chaoscenter/graphql/server/pkg/chaos_infrastructure/model/mocks/service.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package mocks | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model" | ||
store "github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/data-store" | ||
dbChaosInfra "github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/database/mongodb/chaos_infrastructure" | ||
"github.com/stretchr/testify/mock" | ||
"go.mongodb.org/mongo-driver/bson" | ||
) | ||
|
||
type InfraService struct { | ||
mock.Mock | ||
} | ||
|
||
func (s *InfraService) RegisterInfra(c context.Context, projectID string, input model.RegisterInfraRequest) (*model.RegisterInfraResponse, error) { | ||
args := s.Called(c, projectID, input) | ||
return args.Get(0).(*model.RegisterInfraResponse), args.Error(1) | ||
} | ||
|
||
func (s *InfraService) ConfirmInfraRegistration(request model.InfraIdentity, r store.StateData) (*model.ConfirmInfraRegistrationResponse, error) { | ||
args := s.Called(request, r) | ||
return args.Get(0).(*model.ConfirmInfraRegistrationResponse), args.Error(1) | ||
} | ||
|
||
func (s *InfraService) VerifyInfra(identity model.InfraIdentity) (*dbChaosInfra.ChaosInfra, error) { | ||
args := s.Called(identity) | ||
return args.Get(0).(*dbChaosInfra.ChaosInfra), args.Error(1) | ||
} | ||
|
||
func (s *InfraService) DeleteInfra(ctx context.Context, projectID string, infraId string, r store.StateData) (string, error) { | ||
args := s.Called(ctx, projectID, infraId, r) | ||
return args.String(0), args.Error(1) | ||
} | ||
|
||
func (s *InfraService) ListInfras(projectID string, request *model.ListInfraRequest) (*model.ListInfraResponse, error) { | ||
args := s.Called(projectID, request) | ||
return args.Get(0).(*model.ListInfraResponse), args.Error(1) | ||
} | ||
|
||
func (s *InfraService) GetInfraDetails(ctx context.Context, infraID string, projectID string) (*model.Infra, error) { | ||
args := s.Called(ctx, infraID, projectID) | ||
return args.Get(0).(*model.Infra), args.Error(1) | ||
} | ||
|
||
func (s *InfraService) SendInfraEvent(eventType, eventName, description string, infra model.Infra, r store.StateData) { | ||
s.Called(eventType, eventName, description, infra, r) | ||
} | ||
|
||
func (s *InfraService) GetManifest(token string) ([]byte, int, error) { | ||
args := s.Called(token) | ||
return args.Get(0).([]byte), args.Int(1), args.Error(2) | ||
} | ||
|
||
func (s *InfraService) GetManifestWithInfraID(infraID string, accessKey string) ([]byte, error) { | ||
args := s.Called(infraID, accessKey) | ||
return args.Get(0).([]byte), args.Error(1) | ||
} | ||
|
||
func (s *InfraService) GetInfra(ctx context.Context, projectID string, infraID string) (*model.Infra, error) { | ||
args := s.Called(ctx, projectID, infraID) | ||
return args.Get(0).(*model.Infra), args.Error(1) | ||
} | ||
|
||
func (s *InfraService) GetInfraStats(ctx context.Context, projectID string) (*model.GetInfraStatsResponse, error) { | ||
args := s.Called(ctx, projectID) | ||
return args.Get(0).(*model.GetInfraStatsResponse), args.Error(1) | ||
} | ||
|
||
func (s *InfraService) GetVersionDetails() (*model.InfraVersionDetails, error) { | ||
args := s.Called() | ||
return args.Get(0).(*model.InfraVersionDetails), args.Error(1) | ||
} | ||
|
||
func (s *InfraService) QueryServerVersion(ctx context.Context) (*model.ServerVersionResponse, error) { | ||
args := s.Called(ctx) | ||
return args.Get(0).(*model.ServerVersionResponse), args.Error(1) | ||
} | ||
|
||
func (s *InfraService) PodLog(request model.PodLog, r store.StateData) (string, error) { | ||
args := s.Called(request, r) | ||
return args.String(0), args.Error(1) | ||
} | ||
|
||
func (s *InfraService) KubeObj(request model.KubeObjectData, r store.StateData) (string, error) { | ||
args := s.Called(request, r) | ||
return args.String(0), args.Error(1) | ||
} | ||
|
||
func (s *InfraService) UpdateInfra(query bson.D, update bson.D) error { | ||
args := s.Called(query, update) | ||
return args.Error(0) | ||
} | ||
|
||
func (s *InfraService) GetDBInfra(infraID string) (dbChaosInfra.ChaosInfra, error) { | ||
args := s.Called(infraID) | ||
return args.Get(0).(dbChaosInfra.ChaosInfra), args.Error(1) | ||
} |
28 changes: 28 additions & 0 deletions
28
chaoscenter/graphql/server/pkg/choas_experiment_run/model/mocks/service.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package mocks | ||
|
||
import ( | ||
"context" | ||
|
||
types "github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/choas_experiment_run" | ||
store "github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/data-store" | ||
dbChaosExperiment "github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/database/mongodb/chaos_experiment" | ||
dbChaosExperimentRun "github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/database/mongodb/chaos_experiment_run" | ||
"github.com/stretchr/testify/mock" | ||
"go.mongodb.org/mongo-driver/bson" | ||
) | ||
|
||
type ChaosExperimentRunService struct { | ||
mock.Mock | ||
} | ||
|
||
// ProcessExperimentRunDelete mocks the ProcessExperimentRunDelete of chaos-experiment-run service | ||
func (c *ChaosExperimentRunService) ProcessExperimentRunDelete(ctx context.Context, query bson.D, workflowRunID *string, experimentRun dbChaosExperimentRun.ChaosExperimentRun, workflow dbChaosExperiment.ChaosExperimentRequest, username string, r *store.StateData) error { | ||
args := c.Called(ctx, query, workflowRunID, experimentRun, workflow, username, r) | ||
return args.Error(0) | ||
} | ||
|
||
// ProcessCompletedExperimentRun mocks the ProcessCompletedExperimentRun of chaos-experiment-run service | ||
func (c *ChaosExperimentRunService) ProcessCompletedExperimentRun(execData types.ExecutionData, wfID string, runID string) (types.ExperimentRunMetrics, error) { | ||
args := c.Called(execData, wfID, runID) | ||
return args.Get(0).(types.ExperimentRunMetrics), args.Error(1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.