I'd like to create an in-memory filesystem for testing in golang
Contrived Use case: Although Go has packages to achieve this, I would like to use this as a simple example for what I want to do
func GetProcessSessionId(pid int) (int, error) {
sessionidFile := fmt.Sprintf("/proc/%v/sessionid", pid)
dat, err := ioutil.ReadFile(sessionidFile)
if err != nil {
return 0, err
}
return strconv.Atoi(string(dat))
}
Now assume that I have many functions that gather information about processes and want to test them all by having a file system that contains multiple processes in the /proc directory. What would be a good way to structure my project to be able to do this?
Is there a good way to leverage the updates in Go 1.16 with the new io/fs package https://golang.org/pkg/io/fs/ or embedded files?
Am I taking the wrong approach and should think about testing another way?
Aucun commentaire:
Enregistrer un commentaire