Re: [go-nuts] Unit testing AMQP/build flags for tests

2019-11-18 Thread burak serdar
On Mon, Nov 18, 2019 at 10:24 PM Shane H  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.


Re: [go-nuts] Unit testing AMQP/build flags for tests

2019-11-18 Thread Shane H


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.

-- 
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.


Re: [go-nuts] Unit testing AMQP/build flags for tests

2019-11-18 Thread burak serdar
On Mon, Nov 18, 2019 at 10:00 PM Shane H  wrote:
>
> I'm trying to unit test some code (pasted below). I've struggled to find a 
> way to mock the amqp.Connection, so have decided to go the monkey patching 
> route.
>
> The test 'works' but only if I use the following incantation
> go test -gcflags=-l
>
> So, my next step is to ensure that -gcflags is set to prevent inlining when 
> this test is executed.
> My /thought/ was to check os.Getenv("GO_GCFLAGS"), but as I was kindly 
> reminded, executng the tests and compiling the tests are two different things.
> My next brilliant idea was to use a build tag to ensure that the test file is 
> only built when the flags are set as I desire. But 
> https://golang.org/pkg/go/build/ doesn't offer any ideas where gcflags might 
> be checked, or what tag to use.
>
> So, I throw myself at the mercy of golang-nuts to (gently) point me in the 
> right direction (I completely understand that there may be an easier way to 
> do this, but I cannot see that path)


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}()
   ...
}


>
> ```
> ### Code to test
> // MQ -
> type MQ struct {
> conn  *amqp.Connection
> Retry int
> URI   string
> }
>
> // Connect -
> func (mq *MQ) Connect() (err error) {
> // Retry MUST be > 0
> if mq.Retry == 0 {
> log.Print("Cannot use a Retry of zero, this process will to default retry to 
> 1")
> mq.Retry = 1
> }
>
> // Note: Even though amqp.ParseURI(uri) will validate the URI formed, check 
> here that the minimum required exists
> if mq.URI == "" {
> log.Printf("No Message Queue URI configured")
> }
>
> for {
> for i := 0; i < mq.Retry; i++ {
> mq.conn, err = amqp.Dial(mq.URI)
> if err == nil {
> // Successful connection
> log.Printf("Successfully connected to RabbitMQ")
> return nil
> }
> time.Sleep(1 * time.Second)
> }
> // Log that there is a problem connecting to the RabbitMQ service that needs 
> urgent attention
> backoff := time.Duration(mq.Retry*rand.Intn(10)) * time.Second
> log.Printf("ALERT: Trouble connecting to RabbitMQ, error: %v, going to 
> re-enter retry loop in %s seconds", err, backoff.String())
> time.Sleep(backoff)
> }
> }
>
> ### Test Code
> func TestConnect(t *testing.T) {
> testcases := map[string]struct {
> retry int
> uri   string
> err   error
> }{
> "Happy Path": {retry: 1, uri: "amqp://localhost:5672/%2f"},
> }
> for name, tc := range testcases {
> t.Run(name, func(t *testing.T) {
> // Monkeypatch amqp to return the nil and the error
> fakeRabbitConnection := func(msg string) (*amqp.Connection, error) {
> return nil, tc.err // I only want the error to have meaning, therefore the 
> connection can be nil (which also saves me having to create a mock)
> }
> patch := monkey.Patch(amqp.Dial, fakeRabbitConnection)
> defer patch.Unpatch()
> mq := rabbit.MQ{Retry: tc.retry, URI: tc.uri}
> output := mq.Connect()
> fmt.Println(output) // TODO
> })
> }
> }
> ```
>
> --
> 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/133174cd-e5ef-4e65-bfe0-e626914803bb%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/CAMV2RqqEp_T%2BM6qtu4Fw8ff%2BNRMq0QDtSOsYKUbmz-k72_U%3DWA%40mail.gmail.com.


[go-nuts] Unit testing AMQP/build flags for tests

2019-11-18 Thread Shane H
I'm trying to unit test some code (pasted below). I've struggled to find a 
way to mock the amqp.Connection, so have decided to go the monkey patching 
route.

The test 'works' but only if I use the following incantation 
go test -gcflags=-l

So, my next step is to ensure that -gcflags is set to prevent inlining when 
this test is executed. 
My /thought/ was to check os.Getenv("GO_GCFLAGS"), but as I was kindly 
reminded, executng the tests and compiling the tests are two different 
things.
My next brilliant idea was to use a build tag to ensure that the test file 
is only built when the flags are set as I desire. 
But https://golang.org/pkg/go/build/ doesn't offer any ideas where gcflags 
might be checked, or what tag to use.

So, I throw myself at the mercy of golang-nuts to (gently) point me in the 
right direction (I completely understand that there may be an easier way to 
do this, but I cannot see that path)

```
### Code to test
// MQ -
type MQ struct {
conn  *amqp.Connection
Retry int
URI   string
}

// Connect -
func (mq *MQ) Connect() (err error) {
// Retry MUST be > 0
if mq.Retry == 0 {
log.Print("Cannot use a Retry of zero, this process will to default retry 
to 1")
mq.Retry = 1
}

// Note: Even though amqp.ParseURI(uri) will validate the URI formed, check 
here that the minimum required exists
if mq.URI == "" {
log.Printf("No Message Queue URI configured")
}

for {
for i := 0; i < mq.Retry; i++ {
mq.conn, err = amqp.Dial(mq.URI)
if err == nil {
// Successful connection
log.Printf("Successfully connected to RabbitMQ")
return nil
}
time.Sleep(1 * time.Second)
}
// Log that there is a problem connecting to the RabbitMQ service that 
needs urgent attention
backoff := time.Duration(mq.Retry*rand.Intn(10)) * time.Second
log.Printf("ALERT: Trouble connecting to RabbitMQ, error: %v, going to 
re-enter retry loop in %s seconds", err, backoff.String())
time.Sleep(backoff)
}
}

### Test Code
func TestConnect(t *testing.T) {
testcases := map[string]struct {
retry int
uri   string
err   error
}{
"Happy Path": {retry: 1, uri: "amqp://localhost:5672/%2f"},
}
for name, tc := range testcases {
t.Run(name, func(t *testing.T) {
// Monkeypatch amqp to return the nil and the error
fakeRabbitConnection := func(msg string) (*amqp.Connection, error) {
return nil, tc.err // I only want the error to have meaning, therefore the 
connection can be nil (which also saves me having to create a mock)
}
patch := monkey.Patch(amqp.Dial, fakeRabbitConnection)
defer patch.Unpatch()
mq := rabbit.MQ{Retry: tc.retry, URI: tc.uri}
output := mq.Connect()
fmt.Println(output) // TODO
})
}
}
```

-- 
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/133174cd-e5ef-4e65-bfe0-e626914803bb%40googlegroups.com.


[go-nuts] Re: SSLKEYLOGFILE pre-master secret log for TLS?

2019-11-18 Thread psanford
You can set the tls.Config.KeyLogWritter to write out that information in 
the same format: 
https://golang.org/pkg/crypto/tls/#Config.KeyLogWriter

On Saturday, November 16, 2019 at 9:36:33 AM UTC-8, Jason E. Aten wrote:
>
> I have wss websocket client that I need to decrypt the packets from in 
> WireShark to establish time of delivery--to troubleshoot a slowdown.
>
> Similar to the Chrome facility for dumping the TLS pre-master secret using 
> the env variable SSLKEYLOGFILE, which
> WireShark can then utilize, do the Go TLS libraries have a way of logging 
> the secret that was used?
>
>

-- 
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/99d6fe8e-834d-43b3-9e73-96518bb9e388%40googlegroups.com.


Re: [go-nuts] Golang and EOL of Windows 7 (Windows Server 2008)

2019-11-18 Thread Ian Lance Taylor
On Mon, Nov 18, 2019 at 10:13 AM 'Pier-Hugues Pellerin' via
golang-nuts  wrote:
>
> I've been trying to find information about how the Go team deals with EOL of 
> a specific platform.
> I am working on products that currently support Windows 7 and were users will 
> not move quickly out of the
> platform.
>
> Since the EOL of Windows 7 (and Windows Server 2008) is scheduled for January 
> 14, 2020,  I would like to know if there is any
> plan to remove that platform and if so is there a target version for that 
> removal?
>
> I've looked at the Github tracker, but I haven't found anything related to 
> that.

Our general policy is that Go stops supporting a platform when the
vendor stops providing security patches for the platform.  We don't
actively break old platforms, but we stop testing against them, and we
stop rejecting changes that break them, and so they do tend to break
in newer versions of Go.

I don't think we've discussed when we will stop supporting Windows 7.

If you want to stick to an old platform, it's probably best to not
upgrade to newer versions of Go.

Ian

-- 
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/CAOyqgcXt%3DLPS%3DnO_C6UJYH-%2B8BZ6R2P2JJW4ySJucwQ0M_iX8g%40mail.gmail.com.


Re: [go-nuts] Golang and EOL of Windows 7 (Windows Server 2008)

2019-11-18 Thread Tyler Compton
As a data point, Go stopped supporting Windows XP in Go 1.10. That's 4
years after Microsoft officially ended support for the operating system. I
don't think that's a hard rule, and it will probably depend on what version
Go's main Windows contributors use.

Relevant issue: https://golang.org/issues/23380

On Mon, Nov 18, 2019 at 10:12 AM 'Pier-Hugues Pellerin' via golang-nuts <
golang-nuts@googlegroups.com> wrote:

>
> Hello everyone,
>
> I've been trying to find information about how the Go team deals with EOL
> of a specific platform.
> I am working on products that currently support Windows 7 and were users
> will not move quickly out of the
> platform.
>
> Since the EOL of Windows 7 (and Windows Server 2008) is scheduled for
> January 14, 2020,  I would like to know if there is any
> plan to remove that platform and if so is there a target version for that
> removal?
>
> I've looked at the Github tracker, but I haven't found anything related to
> that.
>
> Thanks
>
> PH
>
>
> --
> 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/c10234c5-943b-4061-85c9-a5cf06202372%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/CAA%3DXfu2a1fY8tsjqPN7rPfRpv_Zh3q2mKqJFQKQig9uuPYma9A%40mail.gmail.com.


[go-nuts] Golang and EOL of Windows 7 (Windows Server 2008)

2019-11-18 Thread 'Pier-Hugues Pellerin' via golang-nuts

Hello everyone,

I've been trying to find information about how the Go team deals with EOL 
of a specific platform.
I am working on products that currently support Windows 7 and were users 
will not move quickly out of the
platform.

Since the EOL of Windows 7 (and Windows Server 2008) is scheduled for 
January 14, 2020,  I would like to know if there is any
plan to remove that platform and if so is there a target version for that 
removal?

I've looked at the Github tracker, but I haven't found anything related to 
that.

Thanks

PH


-- 
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/c10234c5-943b-4061-85c9-a5cf06202372%40googlegroups.com.


[go-nuts] Re: golang tool for splitting long lines

2019-11-18 Thread anderson . queiroz
Hi Sankar,

Not really, a easy trick is to use json.MarshalIndent. It helped me a lot :)

playgound: https://play.golang.org/p/nfr2ANR6pPH

type A struct {
A int
B string
C map[int]string
}

func main() {
aa := A{
A: 1,
B: "2",
C: map[int]string{3: "3"},
}

bs, _ := json.MarshalIndent(aa, "", "")
fmt.Printf("%#v\n", aa)
fmt.Println(string(bs))

}



On Friday, 15 November 2019 06:17:29 UTC+1, Sankar wrote:
>
> Hi
>
> In Javascript world I have this handy tool Prettier which will 
> automatically, reproducibly break long lines of code into multiple lines 
> (and also merge parameters into a single line if some elements are 
> removed). 
>
> Are there similar tools available for Golang ? Either as a standalone 
> program or as VSCode/Goland plugins.
>
> From https://github.com/golang/go/issues/11915 I believe that go team may 
> not address it as natively as gofmt/goimports. But are there any other 
> hacks/tools that people already use to break long lines ? 
>
> Thanks.
>
> Sankar
>

-- 
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/f8c3352f-4eaf-4278-847f-58ceab12b52c%40googlegroups.com.


[go-nuts] GopherCon Israel - Call for Papers & Free tickets

2019-11-18 Thread Miki Tebeka


Hello Gophers,

We’re getting great submission to the GopherCon Israel CFP. However, we'd 
like to have more.

We’ll raffle three FREE tickets to the conference among anyone who 
submitted a talk. Also, everyone who submitted will be invited to a talk on 
that will help them improve as speakers.

Of course, if your talk is accepted you’ll get a free ticket as well as an 
invitation to the speakers dinner where you can chat with our keynote 
speakers and fellow speakers.

If you have an idea but not sure about it, please get in touch with Miki (
m...@353solutions.com) and he’ll help you out.

Now, head over to https://www.papercall.io/gcil-2020 and submit your talk.

We also have some silver sponsorships still available, ping us at 
i...@gophercon.org.il if you’re interested.

Happy Hacking,

The GopherCon Israel Team

-- 
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/f05f93e9-c582-4fbc-9561-c34a1fc7dfb1%40googlegroups.com.