Implement initial test-run option (#113) #118

Open
mmarhin wants to merge 2 commits from mmarhin/autogits:initial-test-run into main
First-time contributor

Changes introduced:

  • Added --test-run flag in main.go.
  • Implemented RedisMock in redis.go with static data.
  • Mocked HGetAll and ScanType functions to return sample data for python313 and autogits.

This allows running the service locally using:
go run . --debug --no-tls --test-run

Fixes #113

Changes introduced: - Added `--test-run` flag in `main.go`. - Implemented `RedisMock` in `redis.go` with static data. - Mocked `HGetAll` and `ScanType` functions to return sample data for `python313` and `autogits`. This allows running the service locally using: `go run . --debug --no-tls --test-run` Fixes #113
mmarhin added 1 commit 2026-01-24 17:53:53 +01:00
Implement initial test-run option (#113)
Some checks failed
go-generate-check / go-generate-check (pull_request) Has been cancelled
88def03d5e
dgarcia requested changes 2026-01-27 10:49:35 +01:00
dgarcia left a comment
First-time contributor

It's a good start, but maybe we can move the mock code to a new file, something like redismock.go, so the redis.go file doesn't change too much.

And we can try to implement this in a more advanced way, we can try to make use of the go interfaces, so we can define a new struct, that implements the same interface than the redisClient.

We don't need to implement all the redisClient interfaces, just the two functions that we are using:

type RedisClient interface {
	HGetAll(ctx context.Context, key string) *redis.MapStringStringCmd
	ScanType(ctx context.Context, cursor uint64, match string, count int64, keyType string) *redis.ScanCmd
 }

So, *redis.Client implements that interface by default and our new MockRedis type should just implement those new methods and the global variable in redis.go could be changed to use the interface:

var redisClient RedisClient

And just initialize accordingly depending on the test-run flag.

It's a good start, but maybe we can move the mock code to a new file, something like `redismock.go`, so the `redis.go` file doesn't change too much. And we can try to implement this in a more advanced way, we can try to make use of the go interfaces, so we can define a new struct, that implements the same interface than the redisClient. We don't need to implement all the redisClient interfaces, just the two functions that we are using: ```go type RedisClient interface { HGetAll(ctx context.Context, key string) *redis.MapStringStringCmd ScanType(ctx context.Context, cursor uint64, match string, count int64, keyType string) *redis.ScanCmd } ``` So, `*redis.Client` implements that interface by default and our new `MockRedis` type should just implement those new methods and the global variable in `redis.go` could be changed to use the interface: ```go var redisClient RedisClient ``` And just initialize accordingly depending on the `test-run` flag.
mmarhin added 1 commit 2026-01-28 23:41:48 +01:00
refactor: Implement RedisClient interface for mocking strategy
Some checks failed
go-generate-check / go-generate-check (pull_request) Has been cancelled
1728c346f3
Author
First-time contributor

Thanks for the feedback and the guidance on using interfaces!

I have refactored the code to implement the RedisClient interface strategy as requested.

Summary of changes:

  • Defined the RedisClient interface in redis.go.
  • Moved the mock implementation to a new file redismock.go.
  • Refactored redis.go to remove the boolean flags and conditional logic, relying on the interface polymorphism instead.
Thanks for the feedback and the guidance on using interfaces! I have refactored the code to implement the `RedisClient` interface strategy as requested. **Summary of changes:** - Defined the `RedisClient` interface in `redis.go`. - Moved the mock implementation to a new file `redismock.go`. - Refactored `redis.go` to remove the boolean flags and conditional logic, relying on the interface polymorphism instead.
Some checks failed
go-generate-check / go-generate-check (pull_request) Has been cancelled
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u initial-test-run:mmarhin-initial-test-run
git checkout mmarhin-initial-test-run
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: git-workflow/autogits#118