MCPcopy Create free account
hub / github.com/golang/appengine / TestUsers

Function TestUsers

aetest/instance_test.go:80–119  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

78}
79
80func TestUsers(t *testing.T) {
81 // Only run the test if APPENGINE_DEV_APPSERVER is explicitly set.
82 if os.Getenv("APPENGINE_DEV_APPSERVER") == "" {
83 t.Skip("APPENGINE_DEV_APPSERVER not set")
84 }
85
86 inst, err := NewInstance(nil)
87 if err != nil {
88 t.Fatalf("NewInstance: %v", err)
89 }
90 defer inst.Close()
91
92 req, err := inst.NewRequest("GET", "http://example.com/page", nil)
93 if err != nil {
94 t.Fatalf("NewRequest: %v", err)
95 }
96 ctx := appengine.NewContext(req)
97
98 if user := user.Current(ctx); user != nil {
99 t.Errorf("user.Current initially %v, want nil", user)
100 }
101
102 u := &user.User{
103 Email: "gopher@example.com",
104 Admin: true,
105 }
106 Login(u, req)
107
108 if got := user.Current(ctx); got.Email != u.Email {
109 t.Errorf("user.Current: %v, want %v", got, u)
110 }
111 if admin := user.IsAdmin(ctx); !admin {
112 t.Errorf("user.IsAdmin: %t, want true", admin)
113 }
114
115 Logout(req)
116 if user := user.Current(ctx); user != nil {
117 t.Errorf("user.Current after logout %v, want nil", user)
118 }
119}

Callers

nothing calls this directly

Calls 8

NewRequestMethod · 0.95
NewContextFunction · 0.92
CurrentFunction · 0.92
IsAdminFunction · 0.92
NewInstanceFunction · 0.70
LoginFunction · 0.70
LogoutFunction · 0.70
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…