Documentation
¶
Overview ¶
Package b2sim provides an in-memory B2 wire server for blazer clients. Pass New() to b2.Transport to exercise the normal HTTP, retry, and JSON path. It is a testing aid, not a complete B2 emulator: it does not enforce application-key credentials or capabilities, retention, replication, encryption, lifecycle, CORS, or download-authorization signatures. Unsupported endpoints fail with a non-2xx response; they never silently succeed. With valid simulator authorization, b2_hide_file, b2_list_unfinished_large_files (so Writer.Resume), b2_list_parts, b2_copy_file, b2_copy_part (so Copy and Compose with copied parts), b2_download_file_by_id, b2_get_download_authorization, b2_get_bucket_notification_rules, b2_set_bucket_notification_rules, b2_update_file_retention, b2_update_file_legal_hold, b2_create_key (v4), b2_list_keys, and b2_delete_key return HTTP 501 unsupported_operation. Other unimplemented v4 endpoints also return 501; v3 endpoints return 404. Multipart part-number and minimum-size limits are enforced like B2.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Simulator ¶
type Simulator struct {
// contains filtered or unexported fields
}
Simulator is an independent, concurrency-safe in-memory B2 service. Construct it with New; the zero value is not usable. It stores bucket and file settings but does not enforce retention, replication, encryption, lifecycle, or download-authorization policies.
func New ¶
func New() *Simulator
New creates an empty simulator. No sockets or external services are used.
Example ¶
package main
import (
"context"
"fmt"
"github.com/Backblaze/blazer/b2"
"github.com/Backblaze/blazer/x/b2sim"
)
func main() {
ctx := context.Background()
sim := b2sim.New()
client, err := b2.NewClient(ctx, "example-id", "example-key", b2.Transport(sim))
if err != nil {
panic(err)
}
bucket, err := client.NewBucket(ctx, "example-bucket", nil)
if err != nil {
panic(err)
}
fmt.Println(bucket.Name())
fmt.Println(sim.Calls()["b2_create_bucket"])
}
Output: example-bucket 1