In the Golang project under test, there's a method that loads a JSON config file into a variable. Its code is like this:
// Load the JSON config file
func Load(configFile string, outputObj interface{}) *errors.ErrorSt {
var err error
// Read the config file
jsonBytes, err := ioutil.ReadFile(configFile)
if err != nil {
fmt.Println(err.Error())
return errors.File().AddDetails(err.Error())
}
// Parse the config
if err := json.Unmarshal(jsonBytes, outputObj); err != nil {
return errors.JSON().AddDetails("Could not parse" + configFile + ": " + err.Error())
}
return nil
}
I wish to test it but I don't know if I should create fake JSON file for the test cases, or just mock the whole function. My Java background has me leaning towards the latter.
Exploring that, I found the testify
framework I'm using has a package for mocking methods, but what I'm attempting to mock doesn't belong to interfaces (the pitfalls of non-OOP languages!!)