本文整理汇总了Golang中lib/wcg.Request.IsTest方法的典型用法代码示例。如果您正苦于以下问题:Golang Request.IsTest方法的具体用法?Golang Request.IsTest怎么用?Golang Request.IsTest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib/wcg.Request
的用法示例。
在下文中一共展示了Request.IsTest方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getIEPGURLResolver
// getIEPGURLResolver returns iepgURLResolver object.
// the mock object in '__test_iepg_url_resolver' local variable in the request can be used for testing.
func getIEPGURLResolver(req *wcg.Request) *iepgURLResolver {
if req.IsTest() {
if v := req.Local("__test_iepg_url_resolver"); v != nil {
if v1, ok := v.(*iepgURLResolver); ok {
return v1
}
}
}
return defaultIEPGURLResolver
}
示例2: PushTask
// PushTask to push a task into the queue.
func (queue *PushQueue) PushTask(req *wcg.Request, urlPath string, form url.Values) error {
var queueName string
if req.IsTest() || lib.IsOnLocalGAE() {
queueName = "default"
} else {
queueName = queue.Name
}
if _, err := taskqueue.Add(gae.NewContext(req), taskqueue.NewPOSTTask(urlPath, form), queueName); err != nil {
req.Logger.Errorf("[Queue] Error adding a task (%s) into the queue (%q): %v", urlPath, queueName, err)
return err
}
return nil
}
示例3: newRemoteAPIContext
func newRemoteAPIContext(req *wcg.Request, host string) (context.Context, error) {
// TODO: migrate file to datastore?
if !lib.IsOnLocalGAE() && !req.IsTest() {
return nil, fmt.Errorf("RemoteAPI use on GAE is not supported yet.")
}
var hc *http.Client
var err error
const defaultCredentialEnvKey = "GOOGLE_APPLICATION_CREDENTIALS"
if os.Getenv(defaultCredentialEnvKey) != "" {
hc, err = google.DefaultClient(gae.NewContext(req), remoteCtxScopes...)
} else {
return nil, ErrNoRemoteAPIKeyIsConfigured
}
if err != nil {
return nil, err
}
return remote_api.NewRemoteContext(host, hc)
}
示例4: newMediaClient
func newMediaClient(req *wcg.Request) (*media.Client, error) {
const fallbackServer = "speedland-ng-dev.appspot.com"
kind := entities.OAuth2ClientSettings
if lib.IsOnLocalGAE() || req.IsTest() {
kind = kind.NewRemote(fallbackServer)
}
_, settings, err := kind.Get().Key(OAuth2ClientKey).One(req)
if err != nil {
return nil, err
}
if settings == nil {
if lib.IsOnLocalGAE() || req.IsTest() {
return nil, fmt.Errorf("OAuthClient `%s` is not configured on %s", OAuth2ClientKey, fallbackServer)
}
return nil, fmt.Errorf("OAuthClient `%s` is not configured", OAuth2ClientKey)
}
return media.NewClient(
settings.(*models.OAuth2ClientSettings).GenClient(urlfetch.NewContext(req)),
), nil
}