feat: 优化批量匹配和分页默认值 (#244)
This commit is contained in:
@@ -1,12 +1,46 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"cmautobuy/admin/model"
|
||||
"cmautobuy/admin/syb"
|
||||
)
|
||||
|
||||
type batchingInnerCodeReader struct {
|
||||
batches [][]int64
|
||||
}
|
||||
|
||||
func (r *batchingInnerCodeReader) DetailListByStock(_ context.Context, ids []int64) ([]syb.StockDetail, error) {
|
||||
r.batches = append(r.batches, append([]int64(nil), ids...))
|
||||
result := make([]syb.StockDetail, 0, len(ids))
|
||||
for _, id := range ids {
|
||||
result = append(result, syb.StockDetail{ID: id})
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func TestReadInnerCodeDetails_总量不限且每批最多100(t *testing.T) {
|
||||
ids := make([]int64, 205)
|
||||
for index := range ids {
|
||||
ids[index] = int64(index + 1)
|
||||
}
|
||||
reader := &batchingInnerCodeReader{}
|
||||
details, err := readInnerCodeDetails(context.Background(), reader, ids)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(details) != len(ids) || len(reader.batches) != 3 {
|
||||
t.Fatalf("只读匹配应处理全部选择并分 3 批,details=%d batches=%d", len(details), len(reader.batches))
|
||||
}
|
||||
for index, want := range []int{100, 100, 5} {
|
||||
if len(reader.batches[index]) != want {
|
||||
t.Errorf("第 %d 批数量=%d,期望 %d", index+1, len(reader.batches[index]), want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestInnerCodeStockIDFromJSON(t *testing.T) {
|
||||
for _, raw := range []string{
|
||||
`{"stock":{"id":75104587},"detail":{"id":1}}`,
|
||||
|
||||
Reference in New Issue
Block a user