You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iggy.apache.org by hg...@apache.org on 2026/09/29 09:09:52 UTC
(iggy) branch master updated: test(go): cover session and user command serialization (#4334)
This is an automated email from the ASF dual-hosted git repository.
hubcio pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iggy.git
The following commit(s) were added to refs/heads/master by this push:
new caebce72a test(go): cover session and user command serialization (#4334)
caebce72a is described below
commit caebce72a38f55b6bf44378228e9dc718148d479
Author: Goutam Adwant <86...@users.noreply.github.com>
AuthorDate: Tue Sep 29 02:09:47 2026 -0700
test(go): cover session and user command serialization (#4334)
---
foreign/go/internal/command/session_test.go | 33 +++++++++++++
foreign/go/internal/command/user_test.go | 75 +++++++++++++++++++++++++++++
2 files changed, 108 insertions(+)
diff --git a/foreign/go/internal/command/session_test.go b/foreign/go/internal/command/session_test.go
index 664623229..85bd3c054 100644
--- a/foreign/go/internal/command/session_test.go
+++ b/foreign/go/internal/command/session_test.go
@@ -18,6 +18,7 @@
package command
import (
+ "bytes"
"encoding/binary"
"testing"
@@ -49,3 +50,35 @@ func TestSerialize_LoginUser_ContainsVersion(t *testing.T) {
t.Errorf("Version mismatch. Expected: %q, Got: %q", iggcon.Version, version)
}
}
+
+// The live TCP client uses VSR login; this covers only the legacy command's wire format.
+func TestLegacyLoginWithPersonalAccessTokenMarshalBinary(t *testing.T) {
+ request := &LoginWithPersonalAccessToken{Token: "abc123"}
+ if got := request.Code(); got != 44 {
+ t.Fatalf("LoginWithPersonalAccessToken code = %d, want 44", got)
+ }
+
+ got, err := request.MarshalBinary()
+ if err != nil {
+ t.Fatal(err)
+ }
+ want := []byte{6, 'a', 'b', 'c', '1', '2', '3'}
+ if !bytes.Equal(got, want) {
+ t.Fatalf("LoginWithPersonalAccessToken body = %v, want %v", got, want)
+ }
+}
+
+func TestLogoutUserMarshalBinary(t *testing.T) {
+ request := &LogoutUser{}
+ if got := request.Code(); got != 39 {
+ t.Fatalf("LogoutUser code = %d, want 39", got)
+ }
+
+ got, err := request.MarshalBinary()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(got) != 0 {
+ t.Fatalf("LogoutUser body = %v, want empty", got)
+ }
+}
diff --git a/foreign/go/internal/command/user_test.go b/foreign/go/internal/command/user_test.go
index c1d9cd4c6..e929a51e2 100644
--- a/foreign/go/internal/command/user_test.go
+++ b/foreign/go/internal/command/user_test.go
@@ -207,3 +207,78 @@ func TestSerialize_UpdatePermissions_WithPermissions(t *testing.T) {
t.Errorf("permissions payload mismatch")
}
}
+
+func TestUserIdentifierCommandsMarshalBinary(t *testing.T) {
+ numericID, err := iggcon.NewIdentifier(uint32(0x01020304))
+ if err != nil {
+ t.Fatal(err)
+ }
+ namedID, err := iggcon.NewIdentifier("admin")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ for _, test := range []struct {
+ name string
+ request Command
+ code Code
+ want []byte
+ }{
+ {"GetUser numeric", &GetUser{Id: numericID}, 31, []byte{1, 4, 4, 3, 2, 1}},
+ {"GetUser named", &GetUser{Id: namedID}, 31, []byte{2, 5, 'a', 'd', 'm', 'i', 'n'}},
+ {"DeleteUser numeric", &DeleteUser{Id: numericID}, 34, []byte{1, 4, 4, 3, 2, 1}},
+ {"DeleteUser named", &DeleteUser{Id: namedID}, 34, []byte{2, 5, 'a', 'd', 'm', 'i', 'n'}},
+ } {
+ t.Run(test.name, func(t *testing.T) {
+ if got := test.request.Code(); got != test.code {
+ t.Fatalf("command code = %d, want %d", got, test.code)
+ }
+ got, err := test.request.MarshalBinary()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !bytes.Equal(got, test.want) {
+ t.Fatalf("command body = %v, want %v", got, test.want)
+ }
+ })
+ }
+}
+
+func TestGetUsersMarshalBinary(t *testing.T) {
+ request := &GetUsers{}
+ if got := request.Code(); got != 32 {
+ t.Fatalf("GetUsers code = %d, want 32", got)
+ }
+
+ got, err := request.MarshalBinary()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(got) != 0 {
+ t.Fatalf("GetUsers body = %v, want empty", got)
+ }
+}
+
+func TestChangePasswordMarshalBinary(t *testing.T) {
+ userID, err := iggcon.NewIdentifier(uint32(0x01020304))
+ if err != nil {
+ t.Fatal(err)
+ }
+ request := &ChangePassword{
+ UserID: userID,
+ CurrentPassword: "old",
+ NewPassword: "n3w!",
+ }
+ if got := request.Code(); got != 37 {
+ t.Fatalf("ChangePassword code = %d, want 37", got)
+ }
+
+ got, err := request.MarshalBinary()
+ if err != nil {
+ t.Fatal(err)
+ }
+ want := []byte{1, 4, 4, 3, 2, 1, 3, 'o', 'l', 'd', 4, 'n', '3', 'w', '!'}
+ if !bytes.Equal(got, want) {
+ t.Fatalf("ChangePassword body = %v, want %v", got, want)
+ }
+}