github.com/nya3jp/tast@v0.0.0-20230601000426-85c8e4d83a9b/src/go.chromium.org/tast/core/internal/testcontext/private.go (about) 1 // Copyright 2021 The ChromiumOS Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package testcontext 6 7 import ( 8 "context" 9 "time" 10 ) 11 12 // privateDataKey is the type of the key used for attaching a PrivateData 13 // to a context.Context. 14 type privateDataKey struct{} 15 16 // PrivateData contains information private to the framework. 17 type PrivateData struct { 18 // WaitUntilReady carries the value of -waituntilready flag. 19 WaitUntilReady bool 20 // WaitUntilReadyTimeout carries the value of -waituntilreadytimeout flag. 21 WaitUntilReadyTimeout time.Duration 22 } 23 24 // WithPrivateData attaches PrivateData to context.Context. 25 // This function must not be exposed to user code. 26 func WithPrivateData(ctx context.Context, pd PrivateData) context.Context { 27 return context.WithValue(ctx, privateDataKey{}, pd) 28 } 29 30 // PrivateDataFromContext extracts PrivateData from a context.Context. 31 // This function must not be exposed to user code. 32 func PrivateDataFromContext(ctx context.Context) (pd PrivateData, ok bool) { 33 pd, ok = ctx.Value(privateDataKey{}).(PrivateData) 34 return pd, ok 35 }