我一直在使用gcloud和gsutil一段时间,但现在我突然发现任何gsutil命令我得到错误:
Traceback (most recent call last):
File "/Users/julian/google-cloud-sdk/bin/bootstrapping/gsutil.py", line 12, in
import bootstrapping
File "/Users/julian/google-cloud-sdk/bin/bootstrapping/bootstrapping.py", line 22, in
from googlecloudsdk.core.credentials import store as c_store
File "/Users/julian/google-cloud-sdk/lib/googlecloudsdk/core/credentials/store.py", line 27, in
from googlecloudsdk.core import http
File "/Users/julian/google-cloud-sdk/lib/googlecloudsdk/core/http.py", line 31, in
from googlecloudsdk.core.resource import session_capturer
File "/Users/julian/google-cloud-sdk/lib/googlecloudsdk/core/resource/session_capturer.py", line 32, in
from googlecloudsdk.core.resource import yaml_printer
File "/Users/julian/google-cloud-sdk/lib/googlecloudsdk/core/resource/yaml_printer.py", line 17, in
from googlecloudsdk.core.resource import resource_printer_base
File "/Users/julian/google-cloud-sdk/lib/googlecloudsdk/core/resource/resource_printer_base.py", line 38, in
from googlecloudsdk.core.resource import resource_projector
File "/Users/julian/google-cloud-sdk/lib/googlecloudsdk/core/resource/resource_projector.py", line 34, in
from google.protobuf import json_format as protobuf_encoding … 我在常规mvc控制器中有一个方法,它检查用户的身份以查看用户应该指向哪个页面.但是,针对此方法构建单元测试会引发"对象引用未设置"错误,因为当方法作为测试的一部分运行时,User始终为null.
public ActionResult Index()
{
if (User.Identity.IsAuthenticated)
{
if (User.IsInRole("Administrator"))
{
return RedirectToAction("Console");
}
ViewBag.StatusMessage = "You are logged in but do not have sufficient permissions.";
}
else
{
ViewBag.StatusMessage = "Please log in";
}
return View();
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试过在Writing Unit Test中为ASP.NET Web API中使用User.Identity.Name的方法提供的各种解决方案.这些通常在单元测试的主体内使用类似下面的内容:
var identity = new GenericIdentity("UserName");
Thread.CurrentPrincipal = new GenericPrincipal(identity, null);
var controller = new FooController();
Run Code Online (Sandbox Code Playgroud)
如果Controller是ApiController,这种方法可以正常工作 - 即WebApi项目的控制器,但它似乎不适用于常规的Web mvc控制器.User对象保持为null.怎么解决?