CodeSampleX

Пример

google.golang.org/api v0.13.0: bundler.Bundler

Проверенный пример — golang google.golang.org/api v0.13.0: bundler.Bundler. Контракт выполнен на go 1.26 · linux debian/x64 · docker и пройден.

sha256:5a58bb362360ed9424adac7b8c8a75a2f26740fd67573d5d5808f5c237cdf6d8

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда linux 24 · ubuntu · glibc 2.39 x64 go

Среды запусков проверки

Окружение Контракт Этапы Запуск
go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-10-20

Кейс

HOW
Цель
verify google.golang.org/api/support/bundler.Bundler in pkg:golang/google.golang.org/api@v0.13.0
Пакеты
Символы
  • google.golang.org/api/support/bundler.Bundler
Создан
2026-10-20T19:01:28Z

Контракт

  1. Bundler batches items and invokes handler when BundleCountThreshold is reached
  2. Bundler invokes handler when bundle bytes reach BundleByteThreshold
  3. Bundler.Flush forces processing of all pending buffered items and blocks until handler completes
  4. Bundler.Add returns ErrOversizedItem when item size exceeds BundleByteLimit
  5. Bundler.Add returns ErrOverflow when total buffered bytes exceed BufferedByteLimit
  6. Bundler.AddWait blocks when BufferedByteLimit is exceeded and returns ctx.Err() if context is canceled

Файлы

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • sample.go
  • spec.json
  • test/contract.go

Скачать артефакт с исходным кодом (tar.gz)

Исходный код

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify google.golang.org/api/support/bundler.Bundler in pkg:golang/google.golang.org/api@v0.13.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/google.golang.org/api@v0.13.0
Demonstrate these symbols/APIs:
  - google.golang.org/api/support/bundler.Bundler

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:413abcb5f478923e9afe5997cf8a6bd365f4e68fdd2518ea1486f763245c52fc","contract":["Bundler batches items and invokes handler when BundleCountThreshold is reached","Bundler invokes handler when bundle bytes reach BundleByteThreshold","Bundler.Flush forces processing of all pending buffered items and blocks until handler completes","Bundler.Add returns ErrOversizedItem when item size exceeds BundleByteLimit","Bundler.Add returns ErrOverflow when total buffered bytes exceed BufferedByteLimit","Bundler.AddWait blocks when BufferedByteLimit is exceeded and returns ctx.Err() if context is canceled"],"goal":"verify google.golang.org/api/support/bundler.Bundler in pkg:golang/google.golang.org/api@v0.13.0","kind":"HOW","packages":["pkg:golang/google.golang.org/api@v0.13.0"],"schemaVersion":1,"symbols":["google.golang.org/api/support/bundler.Bundler"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/google.golang.org/api@v0.13.0"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/api@v0.13.0","symbols":["google.golang.org/api/support/bundler.Bundler"],"verifierAdapter":"golang@1"}
go.mod
module example.com/bundler-sample

go 1.24

require google.golang.org/api v0.13.0

require golang.org/x/sync v0.0.0-20190423024810-112230192c58 // indirect
go.sum
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
google.golang.org/api v0.13.0 h1:Q3Ui3V3/CVinFWFiW39Iw0kMuVrRzYX0wN6OPFp0lTA=
google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
sample.go
package sample

import (
	"context"
	"time"

	"google.golang.org/api/support/bundler"
)

// ItemBundler wraps bundler.Bundler for string items.
type ItemBundler struct {
	*bundler.Bundler
}

// NewItemBundler creates a Bundler for string items with a specified count threshold.
func NewItemBundler(countThreshold int, handler func([]string)) *ItemBundler {
	b := bundler.NewBundler("", func(items interface{}) {
		handler(items.([]string))
	})
	b.BundleCountThreshold = countThreshold
	b.DelayThreshold = 10 * time.Minute
	return &ItemBundler{Bundler: b}
}

// NewByteBundler creates a Bundler configured with byte limit and byte threshold.
func NewByteBundler(byteLimit, byteThreshold int, handler func([]string)) *ItemBundler {
	b := bundler.NewBundler("", func(items interface{}) {
		handler(items.([]string))
	})
	b.BundleByteLimit = byteLimit
	b.BundleByteThreshold = byteThreshold
	b.DelayThreshold = 10 * time.Minute
	return &ItemBundler{Bundler: b}
}

// NewMemoryLimitedBundler creates a Bundler configured with BufferedByteLimit.
func NewMemoryLimitedBundler(bufferedByteLimit int, handler func([]string)) *ItemBundler {
	b := bundler.NewBundler("", func(items interface{}) {
		handler(items.([]string))
	})
	b.BufferedByteLimit = bufferedByteLimit
	b.DelayThreshold = 10 * time.Minute
	return &ItemBundler{Bundler: b}
}

// AddString adds a string item with given byte weight.
func (b *ItemBundler) AddString(item string, size int) error {
	return b.Add(item, size)
}

// AddWaitString adds a string item with given byte weight waiting for space.
func (b *ItemBundler) AddWaitString(ctx context.Context, item string, size int) error {
	return b.AddWait(ctx, item, size)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify google.golang.org/api/support/bundler.Bundler in pkg:golang/google.golang.org/api@v0.13.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/google.golang.org/api@v0.13.0"
  ],
  "symbols": [
    "google.golang.org/api/support/bundler.Bundler"
  ]
}
test/contract.go
package main

import (
	"context"
	"fmt"
	"os"
	"reflect"
	"sync"
	"time"

	sample "example.com/bundler-sample"
	"google.golang.org/api/support/bundler"
)

func main() {
	if err := runTests(); err != nil {
		fmt.Fprintf(os.Stderr, "Contract test failed: %v\n", err)
		os.Exit(1)
	}
	fmt.Println("PASS: google.golang.org/api/support/bundler.Bundler contract passed")
}

func runTests() error {
	// 1. Bundler batches items and invokes handler when BundleCountThreshold is reached
	{
		var mu sync.Mutex
		var batches [][]string
		batchChan := make(chan []string, 1)

		b := sample.NewItemBundler(3, func(items []string) {
			mu.Lock()
			copied := append([]string(nil), items...)
			batches = append(batches, copied)
			mu.Unlock()
			batchChan <- copied
		})

		if err := b.AddString("item-1", 1); err != nil {
			return fmt.Errorf("test 1: AddString item-1: %w", err)
		}
		if err := b.AddString("item-2", 1); err != nil {
			return fmt.Errorf("test 1: AddString item-2: %w", err)
		}

		select {
		case <-batchChan:
			return fmt.Errorf("test 1: handler called before BundleCountThreshold reached")
		case <-time.After(50 * time.Millisecond):
		}

		if err := b.AddString("item-3", 1); err != nil {
			return fmt.Errorf("test 1: AddString item-3: %w", err)
		}

		select {
		case batch := <-batchChan:
			expected := []string{"item-1", "item-2", "item-3"}
			if !reflect.DeepEqual(batch, expected) {
				return fmt.Errorf("test 1: expected batch %v, got %v", expected, batch)
			}
		case <-time.After(2 * time.Second):
			return fmt.Errorf("test 1: timed out waiting for batch handler")
		}
	}

	// 2. Bundler invokes handler when bundle bytes reach BundleByteThreshold
	{
		batchChan := make(chan []string, 1)
		b := sample.NewByteBundler(0, 10, func(items []string) {
			batchChan <- append([]string(nil), items...)
		})

		if err := b.AddString("short-1", 4); err != nil {
			return fmt.Errorf("test 2: AddString short-1: %w", err)
		}

		select {
		case <-batchChan:
			return fmt.Errorf("test 2: handler called before BundleByteThreshold reached")
		case <-time.After(50 * time.Millisecond):
		}

		if err := b.AddString("short-2", 6); err != nil {
			return fmt.Errorf("test 2: AddString short-2: %w", err)
		}

		select {
		case batch := <-batchChan:
			expected := []string{"short-1", "short-2"}
			if !reflect.DeepEqual(batch, expected) {
				return fmt.Errorf("test 2: expected batch %v, got %v", expected, batch)
			}
		case <-time.After(2 * time.Second):
			return fmt.Errorf("test 2: timed out waiting for byte-triggered batch")
		}
	}

	// 3. Bundler.Flush forces processing of all pending buffered items and blocks until handler completes
	{
		var mu sync.Mutex
		var flushed []string
		handlerDone := false

		b := sample.NewItemBundler(10, func(items []string) {
			time.Sleep(50 * time.Millisecond)
			mu.Lock()
			flushed = append(flushed, items...)
			handlerDone = true
			mu.Unlock()
		})

		if err := b.AddString("pending-1", 1); err != nil {
			return fmt.Errorf("test 3: AddString pending-1: %w", err)
		}
		if err := b.AddString("pending-2", 1); err != nil {
			return fmt.Errorf("test 3: AddString pending-2: %w", err)
		}

		b.Flush()

		mu.Lock()
		done := handlerDone
		count := len(flushed)
		mu.Unlock()

		if !done || count != 2 {
			return fmt.Errorf("test 3: expected handler to complete synchronously on Flush, done=%v, count=%d", done, count)
		}
	}

	// 4. Bundler.Add returns ErrOversizedItem when item size exceeds BundleByteLimit
	{
		b := sample.NewByteBundler(8, 5, func(items []string) {})
		err := b.AddString("oversized", 9)
		if err != bundler.ErrOversizedItem {
			return fmt.Errorf("test 4: expected ErrOversizedItem, got %v", err)
		}
	}

	// 5. Bundler.Add returns ErrOverflow when total buffered bytes exceed BufferedByteLimit
	{
		b := sample.NewMemoryLimitedBundler(10, func(items []string) {})
		err := b.AddString("overflowing", 15)
		if err != bundler.ErrOverflow {
			return fmt.Errorf("test 5: expected ErrOverflow, got %v", err)
		}
	}

	// 6. Bundler.AddWait blocks when BufferedByteLimit is exceeded and returns ctx.Err() if context is canceled
	{
		b := sample.NewMemoryLimitedBundler(10, func(items []string) {})
		ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond)
		defer cancel()

		err := b.AddWaitString(ctx, "blocking-item", 15)
		if err != context.DeadlineExceeded {
			return fmt.Errorf("test 6: expected context.DeadlineExceeded when AddWait blocks past BufferedByteLimit, got %v", err)
		}
	}

	return nil
}

Исходный сидер

аноним