(new): v1.2 release
Golang lint / lint (push) Successful in 11m32s

This commit is contained in:
2026-08-19 14:58:25 +03:00
parent f03a081ed6
commit 29b208eeec
79 changed files with 7301 additions and 2060 deletions
+57
View File
@@ -252,3 +252,60 @@ func TestDecodePayloadStrictRejectsMismatchedType(t *testing.T) {
t.Fatalf("expected ErrPayloadTypeMismatch, got %v", err)
}
}
func TestInlineKeyboardValidation(t *testing.T) {
if err := NewInlineKeyboardButton("missing action").Validate(); !errors.Is(err, ErrInlineKeyboardButtonAction) {
t.Fatalf("expected ErrInlineKeyboardButtonAction, got %v", err)
}
long := strings.Repeat("я", 33)
button := NewInlineKeyboardButton("long").SetCallbackDataCompact(long)
if err := button.Validate(); !errors.Is(err, ErrCallbackDataLength) {
t.Fatalf("expected ErrCallbackDataLength, got %v", err)
}
keyboard := NewInlineKeyboardCompact(1).AddButton(button)
if _, err := keyboard.GetValidated(); !errors.Is(err, ErrCallbackDataLength) {
t.Fatalf("expected validated keyboard to reject callback data, got %v", err)
}
}
func TestCallbackDataEncodeValidatedBoundaries(t *testing.T) {
tests := []struct {
name string
command string
wantLen int
wantErr error
}{
{name: "one byte", command: "", wantLen: 1},
{name: "64 bytes", command: strings.Repeat("a", 63), wantLen: 64},
{name: "65 bytes", command: strings.Repeat("a", 64), wantErr: ErrCallbackDataLength},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
encoded, err := (CallbackData{Command: tt.command}).EncodeValidated(BotPayloadCompact)
if !errors.Is(err, tt.wantErr) {
t.Fatalf("expected %v, got %v", tt.wantErr, err)
}
if err == nil && len([]byte(encoded)) != tt.wantLen {
t.Fatalf("encoded length = %d, want %d", len([]byte(encoded)), tt.wantLen)
}
})
}
if _, err := (CallbackData{Command: "ok"}).EncodeValidated(BotPayloadType("unknown")); !errors.Is(err, ErrInvalidPayloadType) {
t.Fatalf("expected ErrInvalidPayloadType, got %v", err)
}
}
func TestInlineKeyboardLoweredMaxRowStillWraps(t *testing.T) {
keyboard := NewInlineKeyboardJSON(3).
AddURLButton("A", "https://example.test/a").
AddURLButton("B", "https://example.test/b").
SetMaxRow(1).
AddURLButton("C", "https://example.test/c")
markup := keyboard.Get()
if len(markup.InlineKeyboard) != 2 || len(markup.InlineKeyboard[0]) != 2 || len(markup.InlineKeyboard[1]) != 1 {
t.Fatalf("lowered maxRow stopped automatic wrapping: %#v", markup.InlineKeyboard)
}
}