I’m working on a GoLang project which will implement unit testing moving forwards.
This project uses radix library for redis connection, specifically, a global variable of type *radix.Pool
, whose type I cannot alter.
The function I need to unit test is as following:
func CheckFlag() error {
if myGlobalRadixPool == nil {
return errors.New("redis error")
}
var flag string
err := myGlobalRadixPool.Do(radix.cmd(&flag, "SET", constant.myFlagAtRedis))
if err != nil {
return err
}
if flag != "1" {
return errors.New("flag error")
}
return nil
}
How can I mock myGlobalRadixPool to create unit tests for this function?