-
Notifications
You must be signed in to change notification settings - Fork 706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added tests for environments handler #4175
Conversation
Signed-off-by: Freedisch <[email protected]>
Signed-off-by: Freedisch <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: freedisch <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Freedisch , proposed changes looks good to me. Just a small request,
You defined a struct called MockEnvironmentOperator
, but you didn't use it. In all your test code, instead of using operator := &environments.Operator{}
Please use mock operator.
Signed-off-by: freedisch <[email protected]>
…into environment_test
Signed-off-by: freedisch <[email protected]>
@namkyu1999, I have completed the necessary changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take a look at my comments, please!
chaoscenter/graphql/server/pkg/environment/handler/handler_test.go
Outdated
Show resolved
Hide resolved
"go.mongodb.org/mongo-driver/mongo" | ||
) | ||
|
||
type MockEnvironmentOperator struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about mocking the Mongo Operator instead of mocking the Environment Operator? This allows you to write test cases that are flexible to future changes in the Environment Operator. How do you think?
import (
dbMocks "github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/database/mongodb/mocks"
dbOperationsEnvironment "github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/database/mongodb/environments"
)
mongodbMockOperator := new(dbMocks.MongoOperator)
environmentOperator := dbOperationsEnvironment.NewEnvironmentOperator(mongodbMockOperator)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I could stick with Environment Operator since I already updated the handler to consider an environment Mockoperator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, thanks
…t.go Co-authored-by: Namkyu Park <[email protected]> Signed-off-by: Magnim BATALE <[email protected]>
Signed-off-by: freedisch <[email protected]>
Signed-off-by: freedisch <[email protected]>
Signed-off-by: freedisch <[email protected]>
@namkyu1999 Could review this PR again? |
chaoscenter/graphql/server/pkg/environment/handler/handler_test.go
Outdated
Show resolved
Hide resolved
// Inside the dbOperationsEnvironment package | ||
|
||
type EnvironmentOperatorInterface interface { | ||
InsertEnvironment(ctx context.Context, env Environment) error | ||
GetEnvironments(ctx context.Context, query bson.D) ([]Environment, error) | ||
UpdateEnvironment(ctx context.Context, query bson.D, update bson.D) error | ||
GetEnvironment(query bson.D) (Environment, error) | ||
GetAggregateEnvironments(pipeline mongo.Pipeline) (*mongo.Cursor, error) | ||
GetEnvironmentDetails(ctx context.Context, environmentID string, projectID string) (Environment, error) | ||
GetEnvironmentWithProjectID(projectID string) ([]*Environment, error) | ||
} | ||
|
||
// InsertEnvironment takes details of a chaos_environment and inserts into the database collection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, we don't need this code if we adopt below code
import (
dbMocks "github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/database/mongodb/mocks"
dbOperationsEnvironment "github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/database/mongodb/environments"
)
mongodbMockOperator := new(dbMocks.MongoOperator)
environmentOperator := dbOperationsEnvironment.NewEnvironmentOperator(mongodbMockOperator)
we don't also need MockEnvironmentOperator
struct and relevant functions in chaoscenter/graphql/server/pkg/environment/handler/handler_test.go
if we adopt the above.
I think reducing unnecessary code is a great way to make open source understandable to many people.
How do you think @Saranya-jena @gdsoumya @Freedisch ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sense. I updated the code to reflect it
Signed-off-by: freedisch <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀 @Freedisch
chaoscenter/graphql/server/pkg/environment/handler/handler_test.go
Outdated
Show resolved
Hide resolved
chaoscenter/graphql/server/pkg/environment/handler/handler_test.go
Outdated
Show resolved
Hide resolved
chaoscenter/graphql/server/pkg/environment/handler/handler_test.go
Outdated
Show resolved
Hide resolved
chaoscenter/graphql/server/pkg/environment/handler/handler_test.go
Outdated
Show resolved
Hide resolved
chaoscenter/graphql/server/pkg/environment/handler/handler_test.go
Outdated
Show resolved
Hide resolved
chaoscenter/graphql/server/pkg/environment/handler/handler_test.go
Outdated
Show resolved
Hide resolved
…t.go Co-authored-by: Namkyu Park <[email protected]> Signed-off-by: Magnim BATALE <[email protected]>
…t.go Co-authored-by: Namkyu Park <[email protected]> Signed-off-by: Magnim BATALE <[email protected]>
…t.go Co-authored-by: Namkyu Park <[email protected]> Signed-off-by: Magnim BATALE <[email protected]>
Signed-off-by: freedisch <[email protected]>
Proposed changes:
Added testcases for environments handler https://github.com/litmuschaos/litmus/blob/master/chaoscenter/graphql/server/pkg/environment/handler/handler.go
this follows the previous PR #4159
Types of changes
What types of changes does your code introduce to Litmus? Put an
x
in the boxes that applyChecklist
Put an
x
in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.Dependency
Special notes for your reviewer: