本文整理汇总了Golang中github.com/tsuru/gandalf/user.Remove函数的典型用法代码示例。如果您正苦于以下问题:Golang Remove函数的具体用法?Golang Remove怎么用?Golang Remove使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Remove函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestAddKeyShouldNotAcceptRepeatedKeysForDifferentUsers
func (s *S) TestAddKeyShouldNotAcceptRepeatedKeysForDifferentUsers(c *gocheck.C) {
usr, err := user.New("Frodo", map[string]string{"keyname": rawKey})
c.Assert(err, gocheck.IsNil)
defer user.Remove(usr.Name)
usr2, err := user.New("tempo", nil)
c.Assert(err, gocheck.IsNil)
defer user.Remove(usr2.Name)
b := strings.NewReader(fmt.Sprintf(`{"keyname": %q}`, rawKey))
recorder, request := post(fmt.Sprintf("/user/%s/key?:name=%s", usr2.Name, usr2.Name), b, c)
AddKey(recorder, request)
got := readBody(recorder.Body, c)
expected := "Key already exists.\n"
c.Assert(got, gocheck.Equals, expected)
c.Assert(recorder.Code, gocheck.Equals, http.StatusConflict)
}
开发者ID:rochacon,项目名称:gandalf,代码行数:15,代码来源:handler_test.go
示例2: RemoveUser
func RemoveUser(w http.ResponseWriter, r *http.Request) {
name := r.URL.Query().Get(":name")
if err := user.Remove(name); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
fmt.Fprintf(w, "User \"%s\" successfully removed\n", name)
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:8,代码来源:handler.go
示例3: TestRemoveKeyShouldRemoveKeyFromAuthorizedKeysFile
func (s *S) TestRemoveKeyShouldRemoveKeyFromAuthorizedKeysFile(c *gocheck.C) {
u, err := user.New("Gandalf", map[string]string{"keyname": rawKey})
c.Assert(err, gocheck.IsNil)
defer user.Remove(u.Name)
url := "/user/Gandalf/key/keyname?:keyname=keyname&:name=Gandalf"
recorder, request := del(url, nil, c)
RemoveKey(recorder, request)
content := s.authKeysContent(c)
c.Assert(content, gocheck.Equals, "")
}
开发者ID:rochacon,项目名称:gandalf,代码行数:10,代码来源:handler_test.go
示例4: TestRemoveKeyGivesExpectedSuccessResponse
func (s *S) TestRemoveKeyGivesExpectedSuccessResponse(c *gocheck.C) {
u, err := user.New("Gandalf", map[string]string{"keyname": rawKey})
c.Assert(err, gocheck.IsNil)
defer user.Remove(u.Name)
url := "/user/Gandalf/key/keyname?:keyname=keyname&:name=Gandalf"
recorder, request := del(url, nil, c)
RemoveKey(recorder, request)
c.Assert(recorder.Code, gocheck.Equals, 200)
b := readBody(recorder.Body, c)
c.Assert(b, gocheck.Equals, `Key "keyname" successfully removed`)
}
开发者ID:rochacon,项目名称:gandalf,代码行数:11,代码来源:handler_test.go
示例5: removeUser
func removeUser(w http.ResponseWriter, r *http.Request) {
name := r.URL.Query().Get(":name")
if err := user.Remove(name); err != nil {
status := http.StatusInternalServerError
if err == user.ErrUserNotFound {
status = http.StatusNotFound
}
http.Error(w, err.Error(), status)
return
}
fmt.Fprintf(w, "User \"%s\" successfully removed\n", name)
}
开发者ID:ricardodani,项目名称:gandalf,代码行数:12,代码来源:handler.go
示例6: TestListKeysWithoutKeysGivesEmptyJSON
func (s *S) TestListKeysWithoutKeysGivesEmptyJSON(c *gocheck.C) {
u, err := user.New("Gandalf", map[string]string{})
c.Assert(err, gocheck.IsNil)
defer user.Remove(u.Name)
url := "/user/Gandalf/keys?:name=Gandalf"
request, err := http.NewRequest("GET", url, nil)
c.Assert(err, gocheck.IsNil)
recorder := httptest.NewRecorder()
ListKeys(recorder, request)
c.Assert(recorder.Code, gocheck.Equals, 200)
b := readBody(recorder.Body, c)
c.Assert(b, gocheck.Equals, "{}")
}
开发者ID:rochacon,项目名称:gandalf,代码行数:13,代码来源:handler_test.go
示例7: TestRemoveKeyRemovesKeyFromDatabase
func (s *S) TestRemoveKeyRemovesKeyFromDatabase(c *gocheck.C) {
u, err := user.New("Gandalf", map[string]string{"keyname": rawKey})
c.Assert(err, gocheck.IsNil)
defer user.Remove(u.Name)
url := "/user/Gandalf/key/keyname?:keyname=keyname&:name=Gandalf"
recorder, request := del(url, nil, c)
RemoveKey(recorder, request)
conn, err := db.Conn()
c.Assert(err, gocheck.IsNil)
defer conn.Close()
count, err := conn.Key().Find(bson.M{"name": "keyname", "username": "Gandalf"}).Count()
c.Assert(err, gocheck.IsNil)
c.Assert(count, gocheck.Equals, 0)
}
开发者ID:rochacon,项目名称:gandalf,代码行数:14,代码来源:handler_test.go
示例8: TestListKeysGivesExpectedSuccessResponse
func (s *S) TestListKeysGivesExpectedSuccessResponse(c *gocheck.C) {
keys := map[string]string{"key1": rawKey, "key2": otherKey}
u, err := user.New("Gandalf", keys)
c.Assert(err, gocheck.IsNil)
defer user.Remove(u.Name)
url := "/user/Gandalf/keys?:name=Gandalf"
request, err := http.NewRequest("GET", url, nil)
c.Assert(err, gocheck.IsNil)
recorder := httptest.NewRecorder()
ListKeys(recorder, request)
c.Assert(recorder.Code, gocheck.Equals, 200)
body, err := ioutil.ReadAll(recorder.Body)
c.Assert(err, gocheck.IsNil)
var data map[string]string
err = json.Unmarshal(body, &data)
c.Assert(err, gocheck.IsNil)
c.Assert(data, gocheck.DeepEquals, keys)
}
开发者ID:rochacon,项目名称:gandalf,代码行数:18,代码来源:handler_test.go
示例9: TestAddKey
func (s *S) TestAddKey(c *gocheck.C) {
usr, err := user.New("Frodo", map[string]string{})
c.Assert(err, gocheck.IsNil)
defer user.Remove(usr.Name)
b := strings.NewReader(fmt.Sprintf(`{"keyname": %q}`, rawKey))
recorder, request := post(fmt.Sprintf("/user/%s/key?:name=%s", usr.Name, usr.Name), b, c)
AddKey(recorder, request)
got := readBody(recorder.Body, c)
expected := "Key(s) successfully created"
c.Assert(got, gocheck.Equals, expected)
c.Assert(recorder.Code, gocheck.Equals, 200)
var k user.Key
conn, err := db.Conn()
c.Assert(err, gocheck.IsNil)
defer conn.Close()
err = conn.Key().Find(bson.M{"name": "keyname", "username": usr.Name}).One(&k)
c.Assert(err, gocheck.IsNil)
c.Assert(k.Body, gocheck.Equals, keyBody)
c.Assert(k.Comment, gocheck.Equals, keyComment)
}
开发者ID:rochacon,项目名称:gandalf,代码行数:20,代码来源:handler_test.go
注:本文中的github.com/tsuru/gandalf/user.Remove函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论