2020-12-26 15:32:45 +00:00
|
|
|
package mock
|
|
|
|
|
|
|
|
import (
|
2021-10-12 12:55:53 +01:00
|
|
|
"go-micro.dev/v4/client"
|
2020-12-26 15:32:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Response sets the response methods for a service
|
|
|
|
func Response(service string, response []MockResponse) client.Option {
|
|
|
|
return func(o *client.Options) {
|
2021-12-05 12:55:54 +01:00
|
|
|
r, ok := responseFromContext(o.Context)
|
2020-12-26 15:32:45 +00:00
|
|
|
if !ok {
|
|
|
|
r = make(map[string][]MockResponse)
|
|
|
|
}
|
|
|
|
r[service] = response
|
2021-12-05 12:55:54 +01:00
|
|
|
o.Context = newResponseContext(o.Context, r)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Subscriber sets the subscribers service
|
|
|
|
func Subscriber(topic string, subscriber MockSubscriber) client.Option {
|
|
|
|
return func(o *client.Options) {
|
|
|
|
r, ok := subscriberFromContext(o.Context)
|
|
|
|
if !ok {
|
|
|
|
r = make(map[string]MockSubscriber)
|
|
|
|
}
|
|
|
|
r[topic] = subscriber
|
|
|
|
o.Context = newSubscriberContext(o.Context, r)
|
2020-12-26 15:32:45 +00:00
|
|
|
}
|
|
|
|
}
|