[go-nuts] Re: JSON Compare

2023-09-19 Thread Maxime Soulé
Hi,

You can have a look at go-testdeep [1] and its JSON [2] operator.
go-testddep is tailored for tests, but it provides EqDeeplyError [3] 
function that can perhaps be useful in your use case.

json1 := json.RawMessage(`{"foo":{"a":1}}`)
json2 := json.RawMessage(`{"foo":{"b":8}}`)
err := td.EqDeeplyError(json1, td.JSON(json2))

→ https://go.dev/play/p/6dtEB5lZOBG

Regards,

Max.

[1]: https://go-testdeep.zetta.rocks/
[2]: https://go-testdeep.zetta.rocks/operators/json/
[3]: https://pkg.go.dev/github.com/maxatome/go-testdeep/td#EqDeeplyError

Le lundi 18 septembre 2023 à 12:14:43 UTC+2, Corin Lawson a écrit :

> What makes you say the existing packages are not maintained?  They may 
> simply be complete?
>
> On Friday, 15 September 2023 at 5:05:10 am UTC+10 Sapna Jayavel wrote:
>
>> I am implementing a method find difference between two JSON objects and 
>> it has to drill down recursively. My usecase has very large nested JSON 
>> objects. Response should have the data that has changed between two JSON 
>> and position of the object. Do we have any Go package to support this?
>>
>> I looked at couple of packages available out there but seems ones are not 
>> currently maintained.
>>
>

-- 
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/30ea284b-254d-4fe7-b514-4762fd00b43an%40googlegroups.com.


[go-nuts] Re: testing whether two maps are the same object

2023-07-19 Thread Maxime Soulé
Hi,

If you are in tests context, you can have a look at go-testdeep [1] and its 
Shallow operator [2] like in: https://go.dev/play/p/kNItQmDOJDy

Regards,

Max.
[1]: https://github.com/maxatome/go-testdeep/
[2]: https://go-testdeep.zetta.rocks/operators/shallow/

Le mardi 18 juillet 2023 à 17:55:57 UTC+2, Jochen Voss a écrit :

> Thanks Jason, I get your point about DeepEqual now :)
>
> On Tuesday, 18 July 2023 at 16:52:51 UTC+1 Jason Phillips wrote:
>
>> Also note: reflect.DeepEqual doesn't *just* compare the contents of the 
>> map. It only compares contents if the maps aren't "the same map object". 
>> From the documentation:
>>
>> > Map values are deeply equal when all of the following are true: they 
>> are both nil or both non-nil, they have the same length, and either they 
>> are the same map object or their corresponding keys (matched using Go 
>> equality) map to deeply equal values.
>>
>> Comparing if they're "the same map object" is done in the way described 
>> earlier, which seems exactly what you're looking for.
>>
>> On Tuesday, July 18, 2023 at 11:44:53 AM UTC-4 Jason Phillips wrote:
>>
>>> reflect.Value.UnsafePointer() is probably not safer than using unsafe 
>>> directly, assuming you're using unsafe in a way that doesn't break the 
>>> rules. Reflect is doing effectively the same unsafe.Pointer conversion 
>>> under the hood [1]. It's certainly easier on the eyes, in my opinion, 
>>> though.
>>>
>>> [1] - 
>>> https://cs.opensource.google/go/go/+/refs/tags/go1.20.6:src/reflect/value.go;l=103
>>>
>>> On Tuesday, July 18, 2023 at 11:25:42 AM UTC-4 Stephen Illingworth wrote:
>>>

 I like that. I think it's is quite a smart way of doing it,

 I don't think you need to check both maps when choosing a key. Once 
 you've found a candidate key in one map, you can test the other map and if 
 it *does* exist then the two maps aren't equal. You've then saved the 
 insertion and deletion step. I would also prefer to use rand.Int() rather 
 than a linear search. 

 https://go.dev/play/p/ftBGgQMuvvC


 On Tuesday, 18 July 2023 at 15:35:38 UTC+1 Jochen Voss wrote:

> Dear all,
>
> To implement the "eq" operator in a simple PostScript interpreter, I 
> need to determine whether two maps are the same object.
>
> This can be done by adding a new element to one map, and checking 
> whether the new entry also appears in the second map, but as you can 
> imagine, the resulting code is quite ugly.  See 
> https://go.dev/play/p/AfembYDt3en for an implementation of this idea.
>
> Is there a better way?
>
> Many thanks,
> Jochen
>
>

-- 
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/bd04bff9-5d1b-42c6-99b5-e0fd3cc8102dn%40googlegroups.com.


[go-nuts] Re: golang.org/x/exp/jsonrpc2 bugs

2022-10-10 Thread Maxime Soulé
Hi Jason,

I didn't realized this repo followed the same rules as golang/go.

Thank for your help and sorry for the noise.

Regards,

Max.

Le lundi 10 octobre 2022 à 18:53:43 UTC+2, Jason Phillips a écrit :

> Are these existing known bugs or did you open a ticket on the Go bug 
> tracker? If there are already tickets for these known bugs, you should 
> mention the ticket number in your code review. If there aren't tickets, you 
> should probably start by opening a ticket and then linking to your changes.
>
> As for your feature/improvement, it's also generally best to discuss such 
> things as an issue or on the go-dev mailing list before digging in, if only 
> so you don't waste time working on things that may not be accepted.
>
> Here's a link to Go's contribution guide if you haven't seen it: 
> https://go.dev/doc/contribute
>
> On Monday, October 10, 2022 at 11:32:15 AM UTC-4 zept...@gmail.com wrote:
>
>> Hi Gophers!
>>
>> Does anyone know if the jsonrpc2 sub-directory of golang.org/x/exp is 
>> still maintained?
>>
>> If yes, perhaps could you point me to the right person? as there are 2 
>> pending bug fixes that do not seem to arouse somebody curiosity :)
>>
>> https://go-review.googlesource.com/c/exp/+/412334
>> https://go-review.googlesource.com/c/exp/+/436888
>>
>> As I am here, I also proposed a slight improvement to expose errors 
>> content to the caller:
>>
>> https://go-review.googlesource.com/c/exp/+/415615
>>
>> Thanks for your help.
>>
>> Regards,
>>
>> Max.
>>
>

-- 
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/485bea7b-35e2-4354-a584-0dbcfd71629bn%40googlegroups.com.


[go-nuts] golang.org/x/exp/jsonrpc2 bugs

2022-10-10 Thread Maxime Soulé
Hi Gophers!

Does anyone know if the jsonrpc2 sub-directory of golang.org/x/exp is still 
maintained?

If yes, perhaps could you point me to the right person? as there are 2 
pending bug fixes that do not seem to arouse somebody curiosity :)

https://go-review.googlesource.com/c/exp/+/412334
https://go-review.googlesource.com/c/exp/+/436888

As I am here, I also proposed a slight improvement to expose errors content 
to the caller:

https://go-review.googlesource.com/c/exp/+/415615

Thanks for your help.

Regards,

Max.

-- 
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/6cd447cb-fe57-4aaf-9c42-7cce9154bb56n%40googlegroups.com.


[go-nuts] New go1.19 doc comments

2022-08-07 Thread Maxime Soulé
Hi,

I just enhanced go-testdeep documentation to use the new go 1.19 links & 
list features.

The result is pretty good → 
https://pkg.go.dev/github.com/maxatome/go-testdeep/td

In the post 
https://dev.to/maxatome/large-repo-switched-to-new-go119-doc-comments-4i2m 
I list a few remarks & ideas, I copy below:

It seems that pkg.go.dev hasn't handled [links] in lists yet. I say "yet", 
because the last version of godoc 
 handles them properly. So I 
suppose it will be fixed soon.

Struct fields links work for standard packages, but not for local/current 
one. For example [http.Cookie.Raw] produces a link to the Raw field of 
Cookie in net/http package (example ), 
but in go-testdeep td 
 package 
[ContextConfig.RootName] remains intact and so is not changed into a link, 
even when using the last version of godoc.

Links are not handled in var or const comments when a single keyword groups 
several declarations.

[x] could be a builtin pointing to https://pkg.go.dev/builtin#x, like error 
 for example, for all native types, as we 
see them in signatures.

It could be cool to have shortcut reference links global to the package, 
perhaps in the package doc itself. It would avoid to declare in each 
comment the same shortcut again and again.

It can be interesting that the shortcut reference links accept indirect 
URLs. For example, in td 
 I often talk about 
Cmp* functions. Each time, I would like to reference Cmp 
 function (the 
first one of the Cmp* serie). To do it, I have to set the full URL in the 
shortcut:
// [Cmp*]: https://pkg.go.dev/github.com/maxatome/go-testdeep/td#Cmp 

while simply using:
// [Cmp*]: Cmp 

would avoid referencing pkg.go.dev as [Cmp] does elsewhere.

Be that as it may, thanks for the features!

++

Max.

-- 
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/c9035a16-9f9e-46fe-ba0f-e0d6457ef3e6n%40googlegroups.com.


[go-nuts] Re: New to Unit Testing - Testing HTTP requests and response codes

2021-08-18 Thread Maxime Soulé
Hi,

You can have a look at tdhttp [1] included in go-testdeep [2] module.

++

Max.

1. 
https://pkg.go.dev/github.com/maxatome/go-testdeep/helpers/tdhttp#hdr-TestAPI
2. https://go-testdeep.zetta.rocks/

Le mardi 17 août 2021 à 22:14:44 UTC+2, Beginner a écrit :

> Hey, so I am pretty new to Golang and Unit tests as a whole. Right now I 
> am trying to create some tests for this section of code. I want to test in 
> the case of an unexpected HTTP response but I don't know how or where to 
> begin. I am new to mocking and for my previous tests created mocks to test 
> the good case (with help from my coworker). Can anyone give me advice? What 
> resources to read that tackle HTTP requests unit testing, etc. I really 
> want to understand what's going on and don't want to depend on someone 24/7.
>
> ```
> case http.StatusCreated:
> //This part is tested 
> default:
> responseBody, err := ioutil.ReadAll(resp.Body)
> if err != nil {
> logger.Errorf("Unexpected HTTP response status %v, 
> unable to read response body", resp.StatusCode)
> } else {
> logger.Errorf("Unexpected HTTP response status %v, 
> response body: %s", resp.StatusCode, string(responseBody))
> }
>
> return "", ErrUnknownStatusCodeResponse
> }```
>

-- 
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/5a0f5a0a-8d1c-401d-b098-3c1eda881680n%40googlegroups.com.