Implement initial test-run option (#113) #118
Reference in New Issue
Block a user
Delete Branch "mmarhin/autogits:initial-test-run"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Changes introduced:
--test-runflag inmain.go.RedisMockinredis.gowith static data.HGetAllandScanTypefunctions to return sample data forpython313andautogits.This allows running the service locally using:
go run . --debug --no-tls --test-runFixes #113
It's a good start, but maybe we can move the mock code to a new file, something like
redismock.go, so theredis.gofile 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:
So,
*redis.Clientimplements that interface by default and our newMockRedistype should just implement those new methods and the global variable inredis.gocould be changed to use the interface:And just initialize accordingly depending on the
test-runflag.Thanks for the feedback and the guidance on using interfaces!
I have refactored the code to implement the
RedisClientinterface strategy as requested.Summary of changes:
RedisClientinterface inredis.go.redismock.go.redis.goto remove the boolean flags and conditional logic, relying on the interface polymorphism instead.LGTM
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.bz2andgcc15.results.json.bz2) already in the repository with sample data like:So what can we do is to unzip those files, maybe just the
factory.results.json.bz2, like what we are doing right now inmain_test.go, and iterate over theBuildResultarray to build the mock return.Changes implemented:
factory.results.json.bz2.NewMockRedis()constructor that:main_test.go).[]*common.BuildResult.datamap with format:result.PROJECT/REPO/ARCH -> {package: "code:details"}.RedisMock()to call the new constructor.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.