Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Improvement #16

Open
reisraff opened this issue Mar 27, 2019 · 0 comments
Open

API Improvement #16

reisraff opened this issue Mar 27, 2019 · 0 comments

Comments

@reisraff
Copy link

reisraff commented Mar 27, 2019

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(&notification) // 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant