On Mon, Nov 18, 2019 at 10:24 PM Shane H <shane....@gmail.com> wrote:
>
>
>
> On Tuesday, November 19, 2019 at 4:11:52 PM UTC+11, burak serdar wrote:
>>
>>
>>
>> This is what I usually do in these situations:
>>
>> var amqpDial=amqp.Dial
>>  func (mq *MQ) Connect() (err error) {
>>   ...
>>    mq.conn, err = amqpDial(mq.URI)
>>   ...
>> }
>>
>> func TestConnect(t *testing.T) {
>>     amqpDial=fakeDial
>>     defer func() {amqpDial=amqp.Dial}()
>>    ...
>> }
>>
>>
> This works, the only drawback is that I have to choose between making  
> amqpDial an exported (I want to say symbol here) variable, or have the test 
> in the same package (as opposed to a _test pkg)
>
> I've gone with the latter, put these tests into the same package, thanks.

Instead of exporting the variable, you can export a setter function,
something like:

func SetAMQPDialerForTest(f func) {
...
}

The name is explicit, it can only be used for setting, and iirc, the
linker removes it when it is not used (i.e. when not testing).

>
> --
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/d6a6e01c-00df-47f7-94ac-a37e00cb73d7%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAMV2RqpjKUQPX5zPdk3B%2BOZSivsp_UCA3abNdcx4%3D%2BS0hT9mQQ%40mail.gmail.com.

Reply via email to