Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

fix: fix kafka proxy tests #14

Merged
merged 4 commits into from
Jul 8, 2021
Merged

Conversation

smoya
Copy link
Collaborator

@smoya smoya commented Jul 7, 2021

Description

Tests were failing silently as no error happens when decoding goes wrong. This is on purpose so we do not break the basic proxy functionality (clients can still communicate to the brokers).

This change fixes the payloads in the tests and changes log levels to rely by now on them, so tests will fail if decoding goes wrong.

@smoya smoya requested review from fmvilas and magicmatatjahu July 7, 2021 14:40
@@ -53,12 +63,12 @@ func TestRequestKeyHandler_Handle(t *testing.T) {
}{
{
name: "Valid message",
request: []byte{0, 0, 0, 7, 0, 16, 99, 111, 110, 115, 111, 108, 101, 45, 112, 114, 111, 100, 117, 99, 101, 114, 255, 255, 0, 1}, // payload: 'valid message'
request: []byte{0, 0, 5, 220, 0, 0, 0, 1, 0, 4, 100, 101, 109, 111, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 81, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 69, 255, 255, 255, 255, 2, 42, 190, 231, 201, 0, 0, 0, 0, 0, 0, 0, 0, 1, 122, 129, 58, 51, 194, 0, 0, 1, 122, 129, 58, 51, 194, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 1, 38, 0, 0, 0, 1, 26, 118, 97, 108, 105, 100, 32, 109, 101, 115, 115, 97, 103, 101, 0}, // payload: 'valid message'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we provide the exact request body in tests and then convert it to bytes? At the moment I don't see which message is valid/invalid.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, but at this moment we do not have a proper encoder.
Encoder/Decoder code comes from Sarama library and at this stage I only copied (yes, I had to copy because their interfaces are not public) the decoder logic, which is the only thing we need in our app by now.

I would postpone the encoding logic for later once the project turns to a more mature stage. There will be several request headers and message versions to support.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I understand, but you can extend the request body as comment with a "shape" of valid/invalid message? Then it will be easy to check if tests passed or not by changes or by bug in changes 😅

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont get what you mean.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@magicmatatjahu Look at my last commit. Not sure if this is what you meant but I hope it looks more clear now.
Ideally, we would be doing this through the ProduceRequest struct, but the cons are all of the ones I mentioned in my previous message.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, have an error in the test, but fixing anyway

Copy link
Collaborator

@magicmatatjahu magicmatatjahu Jul 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I had this situation 😅

image

So yeah, the comment was for describing the shape of bytes. Ok, we can stay with the last commit :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So please fix the lint error and I will accept.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, I ended up creating a very handmade encoder that only works for tests. Enjoy checking the bytes back and forth dance 😆 . Btw, I ended up using some "magic" bytes so I simplify the work, otherwise, I will be spending a lot of time.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I feel responsible for your efforts. I only had problem with these bytes and I don't like stop you (because it's only a test), so I accept changes 🚀 Good job!

@smoya smoya requested a review from magicmatatjahu July 8, 2021 16:33
Copy link
Collaborator

@magicmatatjahu magicmatatjahu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@smoya smoya merged commit a3e8448 into asyncapi-archived-repos:master Jul 8, 2021
@smoya smoya deleted the fix-tests branch July 8, 2021 18:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants