-
Notifications
You must be signed in to change notification settings - Fork 137
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
Refactoring db package for unit tests #247
Conversation
Signed-off-by: Gaurav Gahlot <[email protected]>
Signed-off-by: Gaurav Gahlot <[email protected]>
Signed-off-by: Gaurav Gahlot <[email protected]>
Signed-off-by: Gaurav Gahlot <[email protected]>
Signed-off-by: Gaurav Gahlot <[email protected]>
0b37807
to
b27f6a4
Compare
b27f6a4
to
fac8852
Compare
Signed-off-by: Gaurav Gahlot <[email protected]>
653d178
to
6d9a03d
Compare
grpc-server/tinkerbell.go
Outdated
if len(req.GetActionName()) == 0 { | ||
return nil, status.Errorf(codes.InvalidArgument, "action_name is invalid") | ||
} | ||
fmt.Printf("Received action status: %s\n", req) |
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.
Instead of fmt
we should use log.
grpc-server/tinkerbell.go
Outdated
fmt.Printf("Received action status: %s\n", req) | ||
wfContext, err := s.db.GetWorkflowContexts(context, wfID) | ||
if err != nil { | ||
return nil, status.Errorf(codes.InvalidArgument, "workflow context not found for workflow %s", wfID) |
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.
this error statement seems to be valid with my above comment on same point. May be we can refine the statement and update it here as well.
grpc-server/tinkerbell.go
Outdated
return true | ||
} | ||
} | ||
} else { |
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.
not necessary but we can combine this else --> else if
Signed-off-by: Gaurav Gahlot <[email protected]>
grpc-server/grpc_server.go
Outdated
@@ -51,9 +50,9 @@ func SetupGRPC(ctx context.Context, log log.Logger, facility string, errCh chan< | |||
} | |||
logger = log | |||
metrics.SetupMetrics(facility, logger) | |||
db := db.ConnectDB(logger) | |||
instance := db.Connect(logger) |
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 the variable name should be changed since it is of type TinkDB
which already has a field name instance
which is a bit confusing.
Signed-off-by: Gaurav Gahlot <[email protected]>
08a671a
to
d364cfa
Compare
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
## Description The PR restructures mocking based on the suggestion by @gianarb in this [thread](#247 (comment)). ## Why is this needed To write more flexible and|or reusable mocks. ## How Has This Been Tested? The changes include unit tests only. ## Coverage ``` ➜ go test -coverprofile coverage.out ➜ go tool cover -func coverage.out | grep tinkerbell.go github.com/tinkerbell/tink/grpc-server/tinkerbell.go:29: GetWorkflowContexts 0.0% github.com/tinkerbell/tink/grpc-server/tinkerbell.go:49: GetWorkflowContextList 100.0% github.com/tinkerbell/tink/grpc-server/tinkerbell.go:72: GetWorkflowActions 100.0% github.com/tinkerbell/tink/grpc-server/tinkerbell.go:81: ReportActionStatus 100.0% github.com/tinkerbell/tink/grpc-server/tinkerbell.go:138: UpdateWorkflowData 100.0% github.com/tinkerbell/tink/grpc-server/tinkerbell.go:155: GetWorkflowData 100.0% github.com/tinkerbell/tink/grpc-server/tinkerbell.go:168: GetWorkflowMetadata 100.0% github.com/tinkerbell/tink/grpc-server/tinkerbell.go:177: GetWorkflowDataVersion 100.0% github.com/tinkerbell/tink/grpc-server/tinkerbell.go:185: getWorkflowsForWorker 100.0% github.com/tinkerbell/tink/grpc-server/tinkerbell.go:196: getWorkflowActions 100.0% github.com/tinkerbell/tink/grpc-server/tinkerbell.go:206: isApplicableToSend 100.0% github.com/tinkerbell/tink/grpc-server/tinkerbell.go:233: isLastAction 100.0% ``` ## How are existing users impacted? What migration steps/scripts do we need? No impact. ## Checklist: I have: - [ ] updated the documentation and/or roadmap (if required) - [x] added unit or e2e tests - [ ] provided instructions on how to upgrade
Description
Changes include:
db
packagedatabase
interfaceWhy is this needed
For mocking database calls to write unit tests for gRPC server.
How are existing users impacted? What migration steps/scripts do we need?
No impact.
How Has This Been Tested?
I have tested the changes by executing an end-to-end workflow.