-
Notifications
You must be signed in to change notification settings - Fork 1
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
Refactor controller code #41
base: main
Are you sure you want to change the base?
Conversation
⬇️ Go test coverage decreased from 71.2% to 71.0% compared to fe0e695 (1 ignored files)
|
func (m *MockRepo) DropTable(tableName string) error { | ||
return nil | ||
} | ||
func (m *MockRepo) ExtractTableNamesFromQuery(query string) []string { |
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 also leaks the abstraction because it returns table names. Also, we will have to copy it for each implementation of Repository
.
What do you think about the following?
We can fix this with a Query
interface:
type Query interface {
SQLQueryString() string
GetKinds() []string
}
and a concrete implementation SQLQuery
. The GetKinds()
method can contain the logic for ExtractTableNamesFromQuery()
.
We can update Repository.Query()
to accept a Query
as its arguments. The implementation of Query()
in SQLiteRepository
can call SQLQueryString()
to get the string to use.
err := repo.DropTable(tableName) | ||
if err != nil { | ||
// if the table does not exist, return nil | ||
if err.Error() == "table does not exist: "+tableName { |
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.
If you are able to change DropTable
to be DeleteAll
, then you can eliminate this case: DeleteAll
will return success even if there is nothing to delete.
This PR aims to refactor DynamicReconciler.go
The reason for changing other files is to make the targeted file (DynamicReconciler.go) testable. The other files were mainly changed to do dependency injection for DynamicReconciler.
The main refactoring for other files inside controller package will be done in the future PRs