-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add bitwise decoder logic #71
Conversation
@stapelberg Please review when you have a chance, thank you. |
I tested this change in my e2e testing.
|
Looks good. Can you also add a unit test please? |
@stapelberg Adding a unit test is not straight forward in this scenario, as to test it, a rule really needs to be programmed and then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
2913459
to
e5f83eb
Compare
@stapelberg any chance you could merge it please? |
@stapelberg could you please merge it? |
expr/bitwise_test.go
Outdated
data, err := tt.bw.marshal() | ||
if err != nil { | ||
t.Errorf("Test \"%s\" failed to marshal Bitwise struct with error: %+v", tt.name, err) | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of t.Errorf+continue and prefixing each error with the tests name, please use subtests with t.Fatalf: http://blog.golang.org/subtests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not seem to be addressed yet? I don’t see you using a subtest even in the latest changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check diff again. it has all been done. Not sure why you do not see it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t see a subtest (t.Run), even after clearing my browser cache. Looking into your branch, I don’t see it either: https://github.com/sbezverk/nftables/blob/add_bitwise_decoder/expr/bitwise_test.go
Did you forget to push a commit, or misunderstand what I meant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/sbezverk/nftables/blob/add_bitwise_decoder/expr/bitwise_test.go#L36
for _, tt := range tests {
nbw := Bitwise{}
data, err := tt.bw.marshal()
if err != nil {
t.Fatalf("Test \"%s\" failed to marshal Bitwise struct with error: %+v", tt.name, err)
}
I tried force push, but it says no changes. Not sure what else can be done..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In your code excerpt, I don’t see t.Run either?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I thought your comment was just about Errorf/continue vs Fatalf.
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= | ||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= | ||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= | ||
github.com/jsimonetti/rtnetlink v0.0.0-20190606172950-9527aa82566a/go.mod h1:Oz+70psSo5OFh8DBl0Zv2ACw7Esh6pPUphlvZG9x7uw= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used? Can you run go mod tidy
please? Alternatively, try reverting your changes to go.sum and rebuild.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
run go mod tidy
go mod tidy
go: downloading github.com/jsimonetti/rtnetlink v0.0.0-20190606172950-9527aa82566a
go: extracting github.com/jsimonetti/rtnetlink v0.0.0-20190606172950-9527aa82566a
"golang.org/x/sys/unix" | ||
) | ||
|
||
func TestBitwise(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you mark this test as parallelizable by calling t.Parallel()
as first statement please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
expr/bitwise_test.go
Outdated
DestRegister: 2, | ||
Len: 4, | ||
Xor: []byte{0x0, 0x0, 0x0, 0x0}, | ||
Mask: []byte{0xff, 0xff, 0x0, 0x0}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this how one matches a /16 IPv4 subnet mask? If so, add a comment please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
@stapelberg comments are addressed in the latest revision, PTAL. |
Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
expr/bitwise_test.go
Outdated
nbw := Bitwise{} | ||
data, err := tt.bw.marshal() | ||
if err != nil { | ||
t.Fatalf("Test \"%s\" failed to marshal Bitwise struct with error: %+v", tt.name, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and below: prefixing the test name manually is now superfluous with subtests, which automatically include the test name.
Please use something like:
t.Fatalf("marshal: %v", err)
Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
Signed-off-by: Serguei Bezverkhi sbezverk@cisco.com
This PR partially implements: #70