obs-status-service: Add a command line option to run in test mode #113

Open
opened 2026-01-20 11:36:45 +01:00 by dgarcia · 0 comments

It could be nice to have an optional argument for the obs-status-service tool, to be able to run the service and develop without the need of a Redis server.

It could be a new argument --test-run, for example:

go run . --debug --no-tls  --test-run

To do this we will need to "mock" the redis.Client in the redis.go file. Right now there are only two calls to the redisClient, so it should be easy to mock:

  • HGetAll, that returns a map[string]string for a query key like result.PROJECT/REPO/ARCH.
data, err := redisClient.HGetAll(context.Background(), key).Result()
  • ScanType, that returns a list of keys []string like result.PROJECT/REPO/ARCH.
data, cursor, err = redisClient.ScanType(ctx, cursor, "", 1000, "hash").Result()

So for to summarize, we can mock the redis client implementing two functions, the ScanType that returns a list of mock projects, for example:

projects := []string{
    "result.devel:languages:python:Factory/openSUSE_Tumbleweed/x86_64",
    "result.devel:Factory:git-workflow/openSUSE_Tumbleweed/x86_64",
}

And the HGetAll result could be mocked like:

data := map[string](map[string]string) {
    "result.devel:languages:python:Factory/openSUSE_Tumbleweed/x86_64": map[string]string{
        "python313": "succeeded",
        "python314": "failed",
    },
    "result.devel:Factory:git-workflow/openSUSE_Tumbleweed/x86_64": map[string]string{
        "autogits": "succeeded",
    },
}
It could be nice to have an optional argument for the `obs-status-service` tool, to be able to run the service and develop without the need of a Redis server. It could be a new argument `--test-run`, for example: ```bash go run . --debug --no-tls --test-run ``` To do this we will need to "mock" the `redis.Client` in the `redis.go` file. Right now there are only two calls to the redisClient, so it should be easy to mock: * [HGetAll](https://src.opensuse.org/git-workflow/autogits/src/branch/main/obs-status-service/redis.go#L37), that returns a `map[string]string` for a query key like `result.PROJECT/REPO/ARCH`. ```go data, err := redisClient.HGetAll(context.Background(), key).Result() ``` * [ScanType](https://src.opensuse.org/git-workflow/autogits/src/branch/main/obs-status-service/redis.go#L203), that returns a list of keys `[]string` like `result.PROJECT/REPO/ARCH`. ```go data, cursor, err = redisClient.ScanType(ctx, cursor, "", 1000, "hash").Result() ``` So for to summarize, we can mock the redis client implementing two functions, the `ScanType` that returns a list of mock projects, for example: ```go projects := []string{ "result.devel:languages:python:Factory/openSUSE_Tumbleweed/x86_64", "result.devel:Factory:git-workflow/openSUSE_Tumbleweed/x86_64", } ``` And the `HGetAll` result could be mocked like: ```go data := map[string](map[string]string) { "result.devel:languages:python:Factory/openSUSE_Tumbleweed/x86_64": map[string]string{ "python313": "succeeded", "python314": "failed", }, "result.devel:Factory:git-workflow/openSUSE_Tumbleweed/x86_64": map[string]string{ "autogits": "succeeded", }, } ```
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: git-workflow/autogits#113