plgd-dev / go-coap

Implementation of CoAP Server & Client in Go
https://coap.technology
Apache License 2.0
448 stars 116 forks source link

fix comment on function SetObserve #391

Closed AryanGodara closed 2 years ago

AryanGodara commented 2 years ago

Signed-off-by: aryan aryangodara03@gmail.com With reference to issue #384

AryanGodara commented 2 years ago

@Danielius1922 , Should I fix the issues, to pass the lint test? I'm asking before implementing, since it can complicate the PR, by making those other chanes to the code, if it's not necessary. But if needed, I'll be glad to do it.

Danielius1922 commented 2 years ago

@Danielius1922 , Should I fix the issues, to pass the lint test? I'm asking before implementing, since it can complicate the PR, by making those other chanes to the code, if it's not necessary. But if needed, I'll be glad to do it.

Hey, thanks for the fix, I think I've fixed those and other issues in PR #390, so it's already done. Thus nothing here needs to be done, I'll merge.

AryanGodara commented 2 years ago

@Danielius1922 , I had a request. I use this library go-coap in my code for coap-adapter. And I want to create unit tests for coap-handler function. So, does this library offer mocking features, kind of like the httptest.NewServer() for http. I was thinking of writing a mock-coap server, but that is way out of my league for now, and I kind of only have 2 weeks to finish the task Or maybe you could suggest a better way to write tests for coap-handlers using go-coap.

Danielius1922 commented 2 years ago

@Danielius1922 , I had a request. I use this library go-coap in my code for coap-adapter. And I want to create unit tests for coap-handler function. So, does this library offer mocking features, kind of like the httptest.NewServer() for http. I was thinking of writing a mock-coap server, but that is way out of my league for now, and I kind of only have 2 weeks to finish the task Or maybe you could suggest a better way to write tests for coap-handlers using go-coap.

No mocking features like those offered by httptest are available currently. I've looked at the source of the httptest library and it's powerful yet small (only 3 implementation files), so creating something like that is possible. We've talked about this with @jkralik and we both agree it would be a nice enhancement, but it's unlikely we will get to it any time soon, the plan is to finish v3 first and then we can look into new features.

So currently the only way I can think of doing what you need is: create a newServer function that makes a coap server running on localhost on some port in a separate go-routine with selected uri handlers. Then call newServer at the start of each client test case. But this is basically the implementation of httptest equivalent. If you go that way you might as well contribute it here, I might have some time to help (usually I have few hours on a Friday to spare).

(Not much of a help I know, sorry. BTW nice avatar, I hope HxH doesn't end up unfinished like Berserk.)

AryanGodara commented 2 years ago

@Danielius1922 , I had a request. I use this library go-coap in my code for coap-adapter. And I want to create unit tests for coap-handler function. So, does this library offer mocking features, kind of like the httptest.NewServer() for http. I was thinking of writing a mock-coap server, but that is way out of my league for now, and I kind of only have 2 weeks to finish the task Or maybe you could suggest a better way to write tests for coap-handlers using go-coap.

No mocking features like those offered by httptest are available currently. I've looked at the source of the httptest library and it's powerful yet small (only 3 implementation files), so creating something like that is possible. We've talked about this with @jkralik and we both agree it would be a nice enhancement, but it's unlikely we will get to it any time soon, the plan is to finish v3 first and then we can look into new features.

So currently the only way I can think of doing what you need is: create a newServer function that makes a coap server running on localhost on some port in a separate go-routine with selected uri handlers. Then call newServer at the start of each client test case. But this is basically the implementation of httptest equivalent. If you go that way you might as well contribute it here, I might have some time to help (usually I have few hours on a Friday to spare).

(Not much of a help I know, sorry. BTW nice avatar, I hope HxH doesn't end up unfinished like Berserk.)

Thanks for the reply @Danielius1922 . I'll try to implement this, and will update if I get to this task of creating a mock server. But since this is a big task, I can't promise any timeline. I'll have to get to it in my free time, when I'm not working on the main tasks.

(I too hope I get to see the entire HxH story 😄)