lundi 1 août 2016

Unit test different flag values

I have the following go lang code:

func getConfigFile() string {
    var configFile string
    flag.StringVar(&configFile, "config", "", "File containing configuration")
    flag.Parse()
    configFile
}

This function is used elsewhere in my code, and I'd like to unit test what happens here when the user provides different values for the config argument (the config file name is used else where). Is there a way to tell the flag package to return different values for the config argument while under test?

Aucun commentaire:

Enregistrer un commentaire