mirror of
https://github.com/kopia/kopia.git
synced 2026-03-27 02:21:59 -04:00
Cleanups: - use non-format variants of Log/Print with no additional args; - fold in Fprintf call with no args into the following one; - add missing arg placeholder in format strings; - use require.Positive instead of Greater(..., 0); - rename function to fillWithZeros to avoid collision with builtin clear; - define type for context key to avoid collisions.
54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
//go:build darwin || (linux && amd64)
|
|
// +build darwin linux,amd64
|
|
|
|
package framework
|
|
|
|
import (
|
|
"context"
|
|
|
|
petname "github.com/dustinkirkland/golang-petname"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const nameLen int = 2
|
|
|
|
type clientKeyT struct{}
|
|
|
|
var clientKey clientKeyT
|
|
|
|
// Client is a unique client for use in multiclient robustness tests.
|
|
type Client struct {
|
|
ID string
|
|
}
|
|
|
|
func init() {
|
|
petname.NonDeterministicMode()
|
|
}
|
|
|
|
func newClient() *Client {
|
|
return &Client{
|
|
ID: petname.Generate(nameLen, "-") + "-" + uuid.NewString(),
|
|
}
|
|
}
|
|
|
|
// NewClientContext returns a copy of ctx with a new client.
|
|
func NewClientContext(ctx context.Context) context.Context {
|
|
return context.WithValue(ctx, clientKey, newClient())
|
|
}
|
|
|
|
// NewClientContexts returns copies of ctx with n new clients.
|
|
func NewClientContexts(ctx context.Context, n int) []context.Context {
|
|
ctxs := make([]context.Context, n)
|
|
for i := range ctxs {
|
|
ctxs[i] = NewClientContext(ctx) //nolint:fatcontext
|
|
}
|
|
|
|
return ctxs
|
|
}
|
|
|
|
// UnwrapContext returns a client from the given context.
|
|
func UnwrapContext(ctx context.Context) *Client {
|
|
c, _ := ctx.Value(clientKey).(*Client)
|
|
return c
|
|
}
|