chore: refresh gramsrv public release
This commit is contained in:
parent
75cebe8dbf
commit
70b6820474
1274 changed files with 378751 additions and 59919 deletions
|
|
@ -1,9 +1,11 @@
|
|||
package rpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/gotd/td/tg"
|
||||
"github.com/gotd/td/tgerr"
|
||||
)
|
||||
|
||||
func TestStorageFileTypePrefersMagicOverMime(t *testing.T) {
|
||||
|
|
@ -19,6 +21,33 @@ func TestStorageFileTypeFallsBackToMime(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestUploadGetFileRejectsInvalidRanges(t *testing.T) {
|
||||
r := &Router{deps: Deps{Files: &fakeFiles{}}}
|
||||
location := &tg.InputDocumentFileLocation{ID: 42}
|
||||
tests := []struct {
|
||||
name string
|
||||
offset int64
|
||||
limit int
|
||||
}{
|
||||
{name: "negative offset", offset: -1, limit: 1},
|
||||
{name: "zero limit", offset: 0, limit: 0},
|
||||
{name: "negative limit", offset: 0, limit: -1},
|
||||
{name: "too large limit", offset: 0, limit: maxUploadGetFileChunkLimit + 1},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, err := r.onUploadGetFile(context.Background(), &tg.UploadGetFileRequest{
|
||||
Location: location,
|
||||
Offset: tt.offset,
|
||||
Limit: tt.limit,
|
||||
})
|
||||
if !tgerr.Is(err, "LIMIT_INVALID") {
|
||||
t.Fatalf("err = %v, want LIMIT_INVALID", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileLocationKeyUsesDocumentID(t *testing.T) {
|
||||
key, ok := fileLocationKey(&tg.InputDocumentFileLocation{
|
||||
ID: 1382305375846410902,
|
||||
|
|
@ -32,3 +61,67 @@ func TestFileLocationKeyUsesDocumentID(t *testing.T) {
|
|||
t.Fatalf("key = %q, want %q", key, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileLocationKeyMapsLegacyAndroidPhotoLocations(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
location tg.InputFileLocationClass
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "plain small avatar",
|
||||
location: &tg.InputFileLocation{VolumeID: -3999, LocalID: int('a')},
|
||||
want: "photo:3999:a",
|
||||
},
|
||||
{
|
||||
name: "plain big avatar",
|
||||
location: &tg.InputFileLocation{VolumeID: -3999, LocalID: int('c')},
|
||||
want: "photo:3999:c",
|
||||
},
|
||||
{
|
||||
name: "plain animated avatar video",
|
||||
location: &tg.InputFileLocation{VolumeID: -3999, LocalID: int('u')},
|
||||
want: "photo:3999:u",
|
||||
},
|
||||
{
|
||||
name: "photo legacy with id",
|
||||
location: &tg.InputPhotoLegacyFileLocation{ID: 4001, VolumeID: -3999, LocalID: int('a')},
|
||||
want: "photo:4001:a",
|
||||
},
|
||||
{
|
||||
name: "peer legacy big",
|
||||
location: &tg.InputPeerPhotoFileLocationLegacy{VolumeID: -4002, LocalID: int('a'), Big: true, Peer: &tg.InputPeerSelf{}},
|
||||
want: "photo:4002:c",
|
||||
},
|
||||
{
|
||||
name: "document thumb",
|
||||
location: &tg.InputFileLocation{VolumeID: -1129957402753368786, LocalID: 1000 + int('m')},
|
||||
want: "doc:1129957402753368786:m",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
key, ok := fileLocationKey(tt.location)
|
||||
if !ok {
|
||||
t.Fatal("fileLocationKey returned !ok")
|
||||
}
|
||||
if key != tt.want {
|
||||
t.Fatalf("key = %q, want %q", key, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileLocationKeyRejectsUnknownLegacyLocations(t *testing.T) {
|
||||
tests := []tg.InputFileLocationClass{
|
||||
&tg.InputFileLocation{VolumeID: 3999, LocalID: int('a')},
|
||||
&tg.InputFileLocation{VolumeID: -3999, LocalID: 7},
|
||||
&tg.InputPhotoLegacyFileLocation{VolumeID: -3999, LocalID: 7},
|
||||
}
|
||||
for _, location := range tests {
|
||||
if key, ok := fileLocationKey(location); ok {
|
||||
t.Fatalf("fileLocationKey(%T) = %q, true; want false", location, key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue