micro / micro

An API first development platform
https://micro.dev
Apache License 2.0
12.13k stars 1.05k forks source link

[Question] How can i test publish message ? #1378

Closed Jinof closed 3 years ago

Jinof commented 4 years ago

Versions: go-micro v2.9.1 micro v2.9.3

When i am trying to test publish message, i can not found a way to achieve it, because micro will read command go test .'s flag. Here is the error: 👇🏽

flag provided but not defined: -test.testlogfile

And my code is below 👇🏽:

var p micro.Publisher

func TestSms_Send(t *testing.T) {
    msg := &sms.Event{
        Phone:     "phone number",
        PhoneCode: "1111",
    }
    err := p.Publish(context.Background(), msg)
    if err != nil {
        t.Fatal(err)
    }
    t.Log("Publish success")
}

func init()  {
    service := micro.NewService()
    service.Init()

    p = micro.NewPublisher(pkg.Topic, service.Client())
}
crazybber commented 3 years ago

check this :https://github.com/micro/services/tree/master/test/pubsub

Jinof commented 3 years ago

So I can not use go test to test pubsub right? But write a single function to test seems to be an easy way to solve it.