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

Open
mmarhin wants to merge 3 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
Dismissed
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.
dgarcia approved these changes 2026-02-11 12:37:17 +01:00
Dismissed
dgarcia left a comment
First-time contributor

LGTM

LGTM
dgarcia requested changes 2026-02-11 14:00:25 +01:00
dgarcia left a comment
First-time contributor

One improvement that we can do here is to use the current existing testing files instead of hardcoding the values.

We've two json files (factory.results.json.bz2 and gcc15.results.json.bz2) already in the repository with sample data like:

[
 {
 "Project": "openSUSE:Factory",
 "Repository": "standard",
 "Arch": "x86_64",
 "Status": [
   {
    "Package": "python313",
    "Code": "succeeded",
    ...
   },
   ...
 ]
 },
 ...
]

So what can we do is to unzip those files, maybe just the factory.results.json.bz2, like what we are doing right now in main_test.go, and iterate over the BuildResult array to build the mock return.

One improvement that we can do here is to use the current existing testing files instead of hardcoding the values. We've two json files (`factory.results.json.bz2` and `gcc15.results.json.bz2`) already in the repository with sample data like: ```json [ { "Project": "openSUSE:Factory", "Repository": "standard", "Arch": "x86_64", "Status": [ { "Package": "python313", "Code": "succeeded", ... }, ... ] }, ... ] ``` So what can we do is to unzip those files, maybe just the `factory.results.json.bz2`, like what we are doing right now in `main_test.go`, and iterate over the `BuildResult` array to build the mock return.
mmarhin added 1 commit 2026-02-19 12:02:43 +01:00
refactor: Load mock data from factory.results.json.bz2 instead of hardcoded values
Some checks failed
go-generate-check / go-generate-check (pull_request) Has been cancelled
eaf34d739e
- Read and decompress factory.results.json.bz2 in NewMockRedis()
- Iterate over BuildResult array to populate mock data structure
- Remove hardcoded test values
- Update RedisMock() to use the new constructor
Author
First-time contributor

Changes implemented:

  • Removed hardcoded mock data and replaced it with dynamic loading from factory.results.json.bz2.
  • Implemented NewMockRedis() constructor that:
    • Opens and decompresses the bz2 file (same approach as main_test.go).
    • Parses the JSON into []*common.BuildResult.
    • Iterates over the BuildResult array to build the mock data structure.
    • Populates data map with format: result.PROJECT/REPO/ARCH -> {package: "code:details"}.
  • Updated RedisMock() to call the new constructor.
  • Now the mock contains all real packages from the test file instead of just 2 hardcoded ones.
Changes implemented: - Removed hardcoded mock data and replaced it with dynamic loading from `factory.results.json.bz2`. - Implemented `NewMockRedis()` constructor that: - Opens and decompresses the bz2 file (same approach as `main_test.go`). - Parses the JSON into `[]*common.BuildResult`. - Iterates over the BuildResult array to build the mock data structure. - Populates `data` map with format: `result.PROJECT/REPO/ARCH -> {package: "code:details"}`. - Updated `RedisMock()` to call the new constructor. - Now the mock contains all real packages from the test file instead of just 2 hardcoded ones.
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