Compare commits
1 Commits
| Author | SHA256 | Date | |
|---|---|---|---|
| d563763f63 |
@@ -243,16 +243,20 @@ func main() {
|
||||
disableTls := flag.Bool("no-tls", false, "Disable TLS")
|
||||
ObsUrl = flag.String("obs-url", obsUrlDef, "OBS API endpoint for package buildlog information")
|
||||
debug := flag.Bool("debug", false, "Enable debug logging")
|
||||
testRun := flag.Bool("test-run", false, "Run service in test mode without Redis")
|
||||
flag.Parse()
|
||||
|
||||
if *debug {
|
||||
common.SetLoggingLevel(common.LogLevelDebug)
|
||||
}
|
||||
|
||||
if redisUrl := os.Getenv("REDIS"); len(redisUrl) > 0 {
|
||||
RedisConnect(redisUrl)
|
||||
if *testRun {
|
||||
redisClient = &MockRedisClient{}
|
||||
common.LogInfo("Running in TEST MODE (mock Redis)")
|
||||
} else if redisURL := os.Getenv("REDIS"); redisURL != "" {
|
||||
RedisConnect(redisURL)
|
||||
} else {
|
||||
common.LogError("REDIS needs to contains URL of the OBS Redis instance with login information")
|
||||
common.LogError("REDIS environment variable is required unless --test-run is used")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -11,10 +11,15 @@ import (
|
||||
"src.opensuse.org/autogits/common"
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
var RepoStatus []*common.BuildResult = []*common.BuildResult{}
|
||||
var RepoStatusLock *sync.RWMutex = &sync.RWMutex{}
|
||||
|
||||
var redisClient *redis.Client
|
||||
var redisClient RedisClient
|
||||
|
||||
func RedisConnect(RedisUrl string) {
|
||||
opts, err := redis.ParseURL(RedisUrl)
|
||||
|
||||
53
obs-status-service/redismock.go
Normal file
53
obs-status-service/redismock.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
// MockRedisClient implements RedisClient interface
|
||||
// and provides static data for local development (--test-run).
|
||||
type MockRedisClient struct{}
|
||||
|
||||
// ScanType mocks redisClient.ScanType
|
||||
func (m *MockRedisClient) ScanType(
|
||||
ctx context.Context,
|
||||
cursor uint64,
|
||||
match string,
|
||||
count int64,
|
||||
keyType string,
|
||||
) *redis.ScanCmd {
|
||||
|
||||
keys := []string{
|
||||
"result.devel:languages:python:Factory/openSUSE_Tumbleweed/x86_64",
|
||||
"result.devel:Factory:git-workflow/openSUSE_Tumbleweed/x86_64",
|
||||
}
|
||||
|
||||
// cmdable is nil because this is a mock
|
||||
cmd := redis.NewScanCmd(ctx, nil, "SCAN")
|
||||
cmd.SetVal(keys, 0)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// HGetAll mocks redisClient.HGetAll
|
||||
func (m *MockRedisClient) HGetAll(
|
||||
ctx context.Context,
|
||||
key string,
|
||||
) *redis.MapStringStringCmd {
|
||||
|
||||
data := map[string]map[string]string{
|
||||
"result.devel:languages:python:Factory/openSUSE_Tumbleweed/x86_64": {
|
||||
"python313": "succeeded",
|
||||
"python314": "failed",
|
||||
},
|
||||
"result.devel:Factory:git-workflow/openSUSE_Tumbleweed/x86_64": {
|
||||
"autogits": "succeeded",
|
||||
},
|
||||
}
|
||||
|
||||
// cmdable is nil because this is a mock
|
||||
cmd := redis.NewMapStringStringCmd(ctx, nil, "HGETALL")
|
||||
cmd.SetVal(data[key])
|
||||
return cmd
|
||||
}
|
||||
Reference in New Issue
Block a user