mardi 23 décembre 2014

How to test deferred Go statements?

How can I test doStuff function? (Playground: http://ift.tt/1sWgNAd)



package main

import "fmt"

func doStuff() {
defer unlock()
lock()
// some
// task
// here
}

func lock() {
fmt.Println("locked")
}

func unlock() {
fmt.Println("unlocked")
}


In other words: how to test code that uses defer statements? What general strategies should be used to test deferred calls? If there are no general practice, how to test this specific code?


Aucun commentaire:

Enregistrer un commentaire