chengxilo commented on code in PR #3015:
URL: https://github.com/apache/iggy/pull/3015#discussion_r2984634096


##########
foreign/go/contracts/users_test.go:
##########


Review Comment:
   I'm sorry that I keep asking you to modify your code.
   
   However, your changes actually doesn't address the problem. If in the future 
I swaped the position of `ManageServers` and `ManageUsers` when encoding, this 
test won't know I am wrong.
   
   
   To better desribe the problem, consider you have this struct.
   
   ```go
   Foo {
       A bool,
       B bool,
       C bool,
   }
   ```
   
   You wrot a function to encode it.
   
   ```go
   func (f Foo) MarshalBinary() ([]byte, error) {
       return []byte{
           boolToByte(f.A), 
           boolToByte(f.B), 
           boolToByte(f.C),
       }
   }
   ```
   
   You wrote a test and here is your test case:
   ```go
   input: Foo {
       A: true,
       B: false,
       C: true
   }
   want: []byte {1, 0, 1}
   ```
   And you can get a []byte {1, 0, 1}, you are 100% correct.
   
   However, if I write the function like this:
   
   ```go
   func (f Foo) MarshalBinary() ([]byte, error) {
       return []byte{
           boolToByte(f.C), 
           boolToByte(f.B), 
           boolToByte(f.A),
       }
   }
   ```
   
   I will still get []byte {1, 0, 1}, I can still pass the test, but actually 
it's wrong.
   
   So you probably want to make sure every single field are correctly encoded.
   
   Consider  make a bigger test case:
   ```go
   { 
       input: Foo {
           A: true
       },
       want: []byte{1,0,0}
   },
   {
       input: Foo {
           B: true
       },
       want: []byte{0,1,0}
   },
   {
       input: Foo {
           C: true
       },
       want: []byte{0,0,1}
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to