go-mocket
go-mocket copied to clipboard
API Improvement
I'd like to propose a new API, take a look at this example:
import "testing"
import mocket "github.com/selvatico/go-mocket"
import "app/app/entity"
func TestDelete(t *testing.T) {
var expectedId int = 1
notification := entity.Notification{}
notification.SetId(expectedId)
notificationService := GetNotificationService()
definitions := map[string]interface{}{
"type": "update",
"table": "notifications",
"set": map[string]interface{}{"deleted_at": mocket.Any},
"where": map[string]interface{}{"id": expectedId},
}
query := mocket.NewQueryMock(definitions) // create the query mock
mocket.WatchQuery(query) // start the watcher
notificationService.Delete(¬ification) // Trigger query
// assertion, it can be made of two ways
// it can be:
mocket.assertWasCalled(query, t) // assert it was called
// or:
if mocket.assertWasCalled(query) == false {
t.Fail()
}
}
I think this is more readable, and easy to write.