From 1fd02dc9faabf4afbf9018130b93042fe7879f86 Mon Sep 17 00:00:00 2001 From: Francisco Souza Date: Mon, 9 Feb 2015 18:27:52 -0200 Subject: [PATCH] all: update gocheck import path --- Godeps/Godeps.json | 11 +- api/handler_test.go | 944 ++++++++--------- api/utils_test.go | 34 +- bin/gandalf_test.go | 186 ++-- db/conn_test.go | 60 +- fs/filesystem_test.go | 12 +- gandalftest/server_test.go | 44 +- hook/hook_test.go | 54 +- multipartzip/multipartzip_test.go | 90 +- repository/git_test.go | 58 +- repository/repository_test.go | 1574 ++++++++++++++--------------- user/key_test.go | 306 +++--- user/user_test.go | 232 ++--- 13 files changed, 1802 insertions(+), 1803 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 07a0080..22208c5 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -1,6 +1,6 @@ { "ImportPath": "github.com/tsuru/gandalf", - "GoVersion": "devel +c768a84 Wed Feb 4 10:16:38 2015 +0000", + "GoVersion": "devel +0ca4913 Sun Feb 8 23:38:50 2015 +0000", "Packages": [ "./..." ], @@ -54,6 +54,10 @@ "Comment": "0.9.0-431-ga83fbc0", "Rev": "a83fbc036f0a4e68e188486d70a13850bf91a2d0" }, + { + "ImportPath": "gopkg.in/check.v1", + "Rev": "64131543e7896d5bcc6bd5a76287eb75ea96c673" + }, { "ImportPath": "gopkg.in/mgo.v2", "Rev": "dc255bb679efa273b6544a03261c4053505498a4" @@ -61,11 +65,6 @@ { "ImportPath": "gopkg.in/yaml.v1", "Rev": "4914593b9558e85597f08346c798aea8f6fb899f" - }, - { - "ImportPath": "launchpad.net/gocheck", - "Comment": "87", - "Rev": "gustavo@niemeyer.net-20130302024745-6ikofwq2c03h7giu" } ] } diff --git a/api/handler_test.go b/api/handler_test.go index 992a716..cac2db3 100644 --- a/api/handler_test.go +++ b/api/handler_test.go @@ -1,4 +1,4 @@ -// Copyright 2014 gandalf authors. All rights reserved. +// Copyright 2015 gandalf authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -23,8 +23,8 @@ import ( "github.com/tsuru/gandalf/multipartzip" "github.com/tsuru/gandalf/repository" "github.com/tsuru/gandalf/user" + "gopkg.in/check.v1" "gopkg.in/mgo.v2/bson" - "launchpad.net/gocheck" ) type bufferCloser struct { @@ -33,212 +33,212 @@ type bufferCloser struct { func (b bufferCloser) Close() error { return nil } -func get(url string, b io.Reader, c *gocheck.C) (*httptest.ResponseRecorder, *http.Request) { +func get(url string, b io.Reader, c *check.C) (*httptest.ResponseRecorder, *http.Request) { return request("GET", url, b, c) } -func post(url string, b io.Reader, c *gocheck.C) (*httptest.ResponseRecorder, *http.Request) { +func post(url string, b io.Reader, c *check.C) (*httptest.ResponseRecorder, *http.Request) { return request("POST", url, b, c) } -func put(url string, b io.Reader, c *gocheck.C) (*httptest.ResponseRecorder, *http.Request) { +func put(url string, b io.Reader, c *check.C) (*httptest.ResponseRecorder, *http.Request) { return request("PUT", url, b, c) } -func del(url string, b io.Reader, c *gocheck.C) (*httptest.ResponseRecorder, *http.Request) { +func del(url string, b io.Reader, c *check.C) (*httptest.ResponseRecorder, *http.Request) { return request("DELETE", url, b, c) } -func request(method, url string, b io.Reader, c *gocheck.C) (*httptest.ResponseRecorder, *http.Request) { +func request(method, url string, b io.Reader, c *check.C) (*httptest.ResponseRecorder, *http.Request) { request, err := http.NewRequest(method, url, b) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) request.Header.Set("Content-Type", "application/json") recorder := httptest.NewRecorder() return recorder, request } -func readBody(b io.Reader, c *gocheck.C) string { +func readBody(b io.Reader, c *check.C) string { body, err := ioutil.ReadAll(b) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) return string(body) } -func (s *S) authKeysContent(c *gocheck.C) string { +func (s *S) authKeysContent(c *check.C) string { authKeysPath := path.Join(os.Getenv("HOME"), ".ssh", "authorized_keys") f, err := fs.Filesystem().OpenFile(authKeysPath, os.O_RDWR|os.O_EXCL, 0755) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) content, err := ioutil.ReadAll(f) return string(content) } -func (s *S) TestMaxMemoryValueShouldComeFromGandalfConf(c *gocheck.C) { +func (s *S) TestMaxMemoryValueShouldComeFromGandalfConf(c *check.C) { config.Set("api:request:maxMemory", 1024) oldMaxMemory := maxMemory maxMemory = 0 defer func() { maxMemory = oldMaxMemory }() - c.Assert(maxMemoryValue(), gocheck.Equals, uint(1024)) + c.Assert(maxMemoryValue(), check.Equals, uint(1024)) } -func (s *S) TestMaxMemoryValueDontResetMaxMemory(c *gocheck.C) { +func (s *S) TestMaxMemoryValueDontResetMaxMemory(c *check.C) { config.Set("api:request:maxMemory", 1024) oldMaxMemory := maxMemory maxMemory = 359 defer func() { maxMemory = oldMaxMemory }() - c.Assert(maxMemoryValue(), gocheck.Equals, uint(359)) + c.Assert(maxMemoryValue(), check.Equals, uint(359)) } -func (s *S) TestAccessParametersShouldReturnErrorWhenInvalidJSONInput(c *gocheck.C) { +func (s *S) TestAccessParametersShouldReturnErrorWhenInvalidJSONInput(c *check.C) { b := bufferCloser{bytes.NewBufferString(``)} _, _, err := accessParameters(b) - c.Assert(err, gocheck.ErrorMatches, `^Could not parse json: .+$`) + c.Assert(err, check.ErrorMatches, `^Could not parse json: .+$`) b = bufferCloser{bytes.NewBufferString(`{`)} _, _, err = accessParameters(b) - c.Assert(err, gocheck.ErrorMatches, `^Could not parse json: .+$`) + c.Assert(err, check.ErrorMatches, `^Could not parse json: .+$`) b = bufferCloser{bytes.NewBufferString(`bang`)} _, _, err = accessParameters(b) - c.Assert(err, gocheck.ErrorMatches, `^Could not parse json: .+$`) + c.Assert(err, check.ErrorMatches, `^Could not parse json: .+$`) b = bufferCloser{bytes.NewBufferString(` `)} _, _, err = accessParameters(b) - c.Assert(err, gocheck.ErrorMatches, `^Could not parse json: .+$`) + c.Assert(err, check.ErrorMatches, `^Could not parse json: .+$`) } -func (s *S) TestAccessParametersShouldReturnErrorWhenNoUserListProvided(c *gocheck.C) { +func (s *S) TestAccessParametersShouldReturnErrorWhenNoUserListProvided(c *check.C) { b := bufferCloser{bytes.NewBufferString(`{"users": "oneuser"}`)} _, _, err := accessParameters(b) - c.Assert(err, gocheck.ErrorMatches, `^Could not parse json: json: cannot unmarshal string into Go value of type \[\]string$`) + c.Assert(err, check.ErrorMatches, `^Could not parse json: json: cannot unmarshal string into Go value of type \[\]string$`) b = bufferCloser{bytes.NewBufferString(`{"repositories": ["barad-dur"]}`)} _, _, err = accessParameters(b) - c.Assert(err, gocheck.ErrorMatches, `^It is need a user list$`) + c.Assert(err, check.ErrorMatches, `^It is need a user list$`) } -func (s *S) TestAccessParametersShouldReturnErrorWhenNoRepositoryListProvided(c *gocheck.C) { +func (s *S) TestAccessParametersShouldReturnErrorWhenNoRepositoryListProvided(c *check.C) { b := bufferCloser{bytes.NewBufferString(`{"users": ["nazgul"]}`)} _, _, err := accessParameters(b) - c.Assert(err, gocheck.ErrorMatches, `^It is need a repository list$`) + c.Assert(err, check.ErrorMatches, `^It is need a repository list$`) } -func (s *S) TestNewUser(c *gocheck.C) { +func (s *S) TestNewUser(c *check.C) { b := strings.NewReader(fmt.Sprintf(`{"name": "brain", "keys": {"keyname": %q}}`, rawKey)) recorder, request := post("/user", b, c) s.router.ServeHTTP(recorder, request) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.User().Remove(bson.M{"_id": "brain"}) defer conn.Key().Remove(bson.M{"username": "brain"}) body, err := ioutil.ReadAll(recorder.Body) - c.Assert(err, gocheck.IsNil) - c.Assert(string(body), gocheck.Equals, "User \"brain\" successfully created\n") - c.Assert(recorder.Code, gocheck.Equals, 200) + c.Assert(err, check.IsNil) + c.Assert(string(body), check.Equals, "User \"brain\" successfully created\n") + c.Assert(recorder.Code, check.Equals, 200) } -func (s *S) TestNewUserShouldSaveInDB(c *gocheck.C) { +func (s *S) TestNewUserShouldSaveInDB(c *check.C) { b := strings.NewReader(`{"name": "brain", "keys": {"content": "some id_rsa.pub key.. use your imagination!", "name": "somekey"}}`) recorder, request := post("/user", b, c) s.router.ServeHTTP(recorder, request) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.User().Remove(bson.M{"_id": "brain"}) defer conn.Key().Remove(bson.M{"username": "brain"}) var u user.User err = conn.User().Find(bson.M{"_id": "brain"}).One(&u) - c.Assert(err, gocheck.IsNil) - c.Assert(u.Name, gocheck.Equals, "brain") + c.Assert(err, check.IsNil) + c.Assert(u.Name, check.Equals, "brain") } -func (s *S) TestNewUserShouldRepassParseBodyErrors(c *gocheck.C) { +func (s *S) TestNewUserShouldRepassParseBodyErrors(c *check.C) { b := strings.NewReader("{]9afe}") recorder, request := post("/user", b, c) s.router.ServeHTTP(recorder, request) body := readBody(recorder.Body, c) expected := "Got error while parsing body: Could not parse json: invalid character ']' looking for beginning of object key string" got := strings.Replace(body, "\n", "", -1) - c.Assert(got, gocheck.Equals, expected) + c.Assert(got, check.Equals, expected) } -func (s *S) TestNewUserShouldRequireUserName(c *gocheck.C) { +func (s *S) TestNewUserShouldRequireUserName(c *check.C) { b := strings.NewReader(`{"name": ""}`) recorder, request := post("/user", b, c) s.router.ServeHTTP(recorder, request) body := readBody(recorder.Body, c) expected := "Got error while creating user: Validation Error: user name is not valid" got := strings.Replace(body, "\n", "", -1) - c.Assert(got, gocheck.Equals, expected) + c.Assert(got, check.Equals, expected) } -func (s *S) TestNewUserWihoutKeys(c *gocheck.C) { +func (s *S) TestNewUserWihoutKeys(c *check.C) { b := strings.NewReader(`{"name": "brain"}`) recorder, request := post("/user", b, c) s.router.ServeHTTP(recorder, request) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.User().Remove(bson.M{"_id": "brain"}) - c.Assert(recorder.Code, gocheck.Equals, 200) + c.Assert(recorder.Code, check.Equals, 200) } -func (s *S) TestGetRepository(c *gocheck.C) { +func (s *S) TestGetRepository(c *check.C) { r := repository.Repository{Name: "onerepo"} conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() err = conn.Repository().Insert(&r) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Repository().Remove(bson.M{"_id": r.Name}) recorder, request := get("/repository/onerepo", nil, c) s.router.ServeHTTP(recorder, request) body, err := ioutil.ReadAll(recorder.Body) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) var data map[string]interface{} err = json.Unmarshal(body, &data) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) expected := map[string]interface{}{ "name": r.Name, "public": r.IsPublic, "ssh_url": r.ReadWriteURL(), "git_url": r.ReadOnlyURL(), } - c.Assert(data, gocheck.DeepEquals, expected) + c.Assert(data, check.DeepEquals, expected) } -func (s *S) TestGetRepositoryWithNamespace(c *gocheck.C) { +func (s *S) TestGetRepositoryWithNamespace(c *check.C) { r := repository.Repository{Name: "onenamespace/onerepo"} conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() err = conn.Repository().Insert(&r) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Repository().Remove(bson.M{"_id": r.Name}) recorder, request := get("/repository/onenamespace/onerepo", nil, c) s.router.ServeHTTP(recorder, request) body, err := ioutil.ReadAll(recorder.Body) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) var data map[string]interface{} err = json.Unmarshal(body, &data) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) expected := map[string]interface{}{ "name": r.Name, "public": r.IsPublic, "ssh_url": r.ReadWriteURL(), "git_url": r.ReadOnlyURL(), } - c.Assert(data, gocheck.DeepEquals, expected) + c.Assert(data, check.DeepEquals, expected) } -func (s *S) TestGetRepositoryDoesNotExist(c *gocheck.C) { +func (s *S) TestGetRepositoryDoesNotExist(c *check.C) { recorder, request := get("/repository/doesnotexist", nil, c) s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, 500) + c.Assert(recorder.Code, check.Equals, 500) } -func (s *S) TestNewRepository(c *gocheck.C) { +func (s *S) TestNewRepository(c *check.C) { conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.Repository().Remove(bson.M{"_id": "some_repository"}) b := strings.NewReader(`{"name": "some_repository", "users": ["r2d2"]}`) @@ -246,83 +246,83 @@ func (s *S) TestNewRepository(c *gocheck.C) { s.router.ServeHTTP(recorder, request) got := readBody(recorder.Body, c) expected := "Repository \"some_repository\" successfully created\n" - c.Assert(got, gocheck.Equals, expected) + c.Assert(got, check.Equals, expected) } -func (s *S) TestNewRepositoryShouldSaveInDB(c *gocheck.C) { +func (s *S) TestNewRepositoryShouldSaveInDB(c *check.C) { b := strings.NewReader(`{"name": "myRepository", "users": ["r2d2"]}`) recorder, request := post("/repository", b, c) s.router.ServeHTTP(recorder, request) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() collection := conn.Repository() defer collection.Remove(bson.M{"_id": "myRepository"}) var p repository.Repository err = collection.Find(bson.M{"_id": "myRepository"}).One(&p) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) } -func (s *S) TestNewRepositoryShouldSaveUserIdInRepository(c *gocheck.C) { +func (s *S) TestNewRepositoryShouldSaveUserIdInRepository(c *check.C) { b := strings.NewReader(`{"name": "myRepository", "users": ["r2d2", "brain"]}`) recorder, request := post("/repository", b, c) s.router.ServeHTTP(recorder, request) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() collection := conn.Repository() defer collection.Remove(bson.M{"_id": "myRepository"}) var p repository.Repository err = collection.Find(bson.M{"_id": "myRepository"}).One(&p) - c.Assert(err, gocheck.IsNil) - c.Assert(len(p.Users), gocheck.Not(gocheck.Equals), 0) + c.Assert(err, check.IsNil) + c.Assert(len(p.Users), check.Not(check.Equals), 0) } -func (s *S) TestNewRepositoryShouldReturnErrorWhenNoUserIsPassed(c *gocheck.C) { +func (s *S) TestNewRepositoryShouldReturnErrorWhenNoUserIsPassed(c *check.C) { b := strings.NewReader(`{"name": "myRepository"}`) recorder, request := post("/repository", b, c) s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, 400) + c.Assert(recorder.Code, check.Equals, 400) body := readBody(recorder.Body, c) expected := "Validation Error: repository should have at least one user" got := strings.Replace(body, "\n", "", -1) - c.Assert(got, gocheck.Equals, expected) + c.Assert(got, check.Equals, expected) } -func (s *S) TestNewRepositoryShouldReturnErrorWhenNoParametersArePassed(c *gocheck.C) { +func (s *S) TestNewRepositoryShouldReturnErrorWhenNoParametersArePassed(c *check.C) { b := strings.NewReader("{}") recorder, request := post("/repository", b, c) s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, 400) + c.Assert(recorder.Code, check.Equals, 400) body := readBody(recorder.Body, c) expected := "Validation Error: repository name is not valid" got := strings.Replace(body, "\n", "", -1) - c.Assert(got, gocheck.Equals, expected) + c.Assert(got, check.Equals, expected) } -func (s *S) TestParseBodyShouldMapBodyJsonToGivenStruct(c *gocheck.C) { +func (s *S) TestParseBodyShouldMapBodyJsonToGivenStruct(c *check.C) { var p repository.Repository b := bufferCloser{bytes.NewBufferString(`{"name": "Dummy Repository"}`)} err := parseBody(b, &p) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) expected := "Dummy Repository" - c.Assert(p.Name, gocheck.Equals, expected) + c.Assert(p.Name, check.Equals, expected) } -func (s *S) TestParseBodyShouldMapBodyEmptyJsonToADict(c *gocheck.C) { +func (s *S) TestParseBodyShouldMapBodyEmptyJsonToADict(c *check.C) { dict := make(map[string]interface{}) b := bufferCloser{bytes.NewBufferString(`{"name": "Test", "isPublic": false, "users": []}`)} err := parseBody(b, &dict) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) expected := map[string]interface{}{ "name": "Test", "isPublic": false, "users": []interface{}{}, } - c.Assert(dict, gocheck.DeepEquals, expected) + c.Assert(dict, check.DeepEquals, expected) } -func (s *S) TestParseBodyShouldMapBodyJsonAndUpdateMap(c *gocheck.C) { +func (s *S) TestParseBodyShouldMapBodyJsonAndUpdateMap(c *check.C) { dict := map[string]interface{}{ "isPublic": false, "users": []string{"merry"}, @@ -330,398 +330,398 @@ func (s *S) TestParseBodyShouldMapBodyJsonAndUpdateMap(c *gocheck.C) { } b := bufferCloser{bytes.NewBufferString(`{"name": "Test", "users": []}`)} err := parseBody(b, &dict) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) expected := map[string]interface{}{ "name": "Test", "isPublic": false, "users": []interface{}{}, "readonlyusers": []string{"pippin"}, } - c.Assert(dict, gocheck.DeepEquals, expected) + c.Assert(dict, check.DeepEquals, expected) } -func (s *S) TestParseBodyShouldReturnErrorWhenJsonIsInvalid(c *gocheck.C) { +func (s *S) TestParseBodyShouldReturnErrorWhenJsonIsInvalid(c *check.C) { var p repository.Repository b := bufferCloser{bytes.NewBufferString("{]ja9aW}")} err := parseBody(b, &p) - c.Assert(err, gocheck.NotNil) + c.Assert(err, check.NotNil) expected := "Could not parse json: invalid character ']' looking for beginning of object key string" - c.Assert(err.Error(), gocheck.Equals, expected) + c.Assert(err.Error(), check.Equals, expected) } -func (s *S) TestParseBodyShouldReturnErrorWhenBodyIsEmpty(c *gocheck.C) { +func (s *S) TestParseBodyShouldReturnErrorWhenBodyIsEmpty(c *check.C) { var p repository.Repository b := bufferCloser{bytes.NewBufferString("")} err := parseBody(b, &p) - c.Assert(err, gocheck.NotNil) - c.Assert(err, gocheck.ErrorMatches, `^Could not parse json:.*$`) + c.Assert(err, check.NotNil) + c.Assert(err, check.ErrorMatches, `^Could not parse json:.*$`) } -func (s *S) TestParseBodyShouldReturnErrorWhenResultParamIsNotAPointer(c *gocheck.C) { +func (s *S) TestParseBodyShouldReturnErrorWhenResultParamIsNotAPointer(c *check.C) { var p repository.Repository b := bufferCloser{bytes.NewBufferString(`{"name": "something"}`)} err := parseBody(b, p) - c.Assert(err, gocheck.NotNil) + c.Assert(err, check.NotNil) expected := "parseBody function cannot deal with struct. Use pointer" - c.Assert(err.Error(), gocheck.Equals, expected) + c.Assert(err.Error(), check.Equals, expected) } -func (s *S) TestNewRepositoryShouldReturnErrorWhenBodyIsEmpty(c *gocheck.C) { +func (s *S) TestNewRepositoryShouldReturnErrorWhenBodyIsEmpty(c *check.C) { b := strings.NewReader("") recorder, request := post("/repository", b, c) s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, 400) + c.Assert(recorder.Code, check.Equals, 400) } -func (s *S) TestGrantAccessUpdatesReposDocument(c *gocheck.C) { +func (s *S) TestGrantAccessUpdatesReposDocument(c *check.C) { u, err := user.New("pippin", map[string]string{}) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.User().Remove(bson.M{"_id": "pippin"}) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) r := repository.Repository{Name: "onerepo"} err = conn.Repository().Insert(&r) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Repository().Remove(bson.M{"_id": r.Name}) r2 := repository.Repository{Name: "otherepo"} err = conn.Repository().Insert(&r2) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Repository().Remove(bson.M{"_id": r2.Name}) b := bytes.NewBufferString(fmt.Sprintf(`{"repositories": ["%s", "%s"], "users": ["%s"]}`, r.Name, r2.Name, u.Name)) rec, req := post("/repository/grant", b, c) s.router.ServeHTTP(rec, req) var repos []repository.Repository err = conn.Repository().Find(bson.M{"_id": bson.M{"$in": []string{r.Name, r2.Name}}}).All(&repos) - c.Assert(err, gocheck.IsNil) - c.Assert(rec.Code, gocheck.Equals, 200) + c.Assert(err, check.IsNil) + c.Assert(rec.Code, check.Equals, 200) for _, repo := range repos { - c.Assert(repo.Users, gocheck.DeepEquals, []string{u.Name}) + c.Assert(repo.Users, check.DeepEquals, []string{u.Name}) } } -func (s *S) TestGrantAccessReadOnlyUpdatesReposDocument(c *gocheck.C) { +func (s *S) TestGrantAccessReadOnlyUpdatesReposDocument(c *check.C) { u, err := user.New("pippin", map[string]string{}) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.User().Remove(bson.M{"_id": "pippin"}) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) r := repository.Repository{Name: "onerepo"} err = conn.Repository().Insert(&r) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Repository().Remove(bson.M{"_id": r.Name}) r2 := repository.Repository{Name: "otherepo"} err = conn.Repository().Insert(&r2) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Repository().Remove(bson.M{"_id": r2.Name}) b := bytes.NewBufferString(fmt.Sprintf(`{"repositories": ["%s", "%s"], "users": ["%s"]}`, r.Name, r2.Name, u.Name)) rec, req := post("/repository/grant?readonly=yes", b, c) s.router.ServeHTTP(rec, req) var repos []repository.Repository err = conn.Repository().Find(bson.M{"_id": bson.M{"$in": []string{r.Name, r2.Name}}}).All(&repos) - c.Assert(err, gocheck.IsNil) - c.Assert(rec.Code, gocheck.Equals, 200) + c.Assert(err, check.IsNil) + c.Assert(rec.Code, check.Equals, 200) for _, repo := range repos { - c.Assert(repo.ReadOnlyUsers, gocheck.DeepEquals, []string{u.Name}) + c.Assert(repo.ReadOnlyUsers, check.DeepEquals, []string{u.Name}) } } -func (s *S) TestRevokeAccessUpdatesReposDocument(c *gocheck.C) { +func (s *S) TestRevokeAccessUpdatesReposDocument(c *check.C) { r := repository.Repository{Name: "onerepo", Users: []string{"Umi", "Luke"}} conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() err = conn.Repository().Insert(&r) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Repository().Remove(bson.M{"_id": r.Name}) r2 := repository.Repository{Name: "otherepo", Users: []string{"Umi", "Luke"}} err = conn.Repository().Insert(&r2) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Repository().Remove(bson.M{"_id": r2.Name}) b := bytes.NewBufferString(fmt.Sprintf(`{"repositories": ["%s", "%s"], "users": ["Umi"]}`, r.Name, r2.Name)) rec, req := del("/repository/revoke", b, c) s.router.ServeHTTP(rec, req) var repos []repository.Repository err = conn.Repository().Find(bson.M{"_id": bson.M{"$in": []string{r.Name, r2.Name}}}).All(&repos) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) for _, repo := range repos { - c.Assert(repo.Users, gocheck.DeepEquals, []string{"Luke"}) + c.Assert(repo.Users, check.DeepEquals, []string{"Luke"}) } } -func (s *S) TestRevokeAccessReadOnlyUpdatesReposDocument(c *gocheck.C) { +func (s *S) TestRevokeAccessReadOnlyUpdatesReposDocument(c *check.C) { r := repository.Repository{Name: "onerepo", ReadOnlyUsers: []string{"Umi", "Luke"}} conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() err = conn.Repository().Insert(&r) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Repository().Remove(bson.M{"_id": r.Name}) r2 := repository.Repository{Name: "otherepo", ReadOnlyUsers: []string{"Umi", "Luke"}} err = conn.Repository().Insert(&r2) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Repository().Remove(bson.M{"_id": r2.Name}) b := bytes.NewBufferString(fmt.Sprintf(`{"repositories": ["%s", "%s"], "users": ["Umi"]}`, r.Name, r2.Name)) rec, req := del("/repository/revoke", b, c) s.router.ServeHTTP(rec, req) var repos []repository.Repository err = conn.Repository().Find(bson.M{"_id": bson.M{"$in": []string{r.Name, r2.Name}}}).All(&repos) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) for _, repo := range repos { - c.Assert(repo.ReadOnlyUsers, gocheck.DeepEquals, []string{"Luke"}) + c.Assert(repo.ReadOnlyUsers, check.DeepEquals, []string{"Luke"}) } } -func (s *S) TestAddKey(c *gocheck.C) { +func (s *S) TestAddKey(c *check.C) { usr, err := user.New("Frodo", map[string]string{}) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer user.Remove(usr.Name) b := strings.NewReader(fmt.Sprintf(`{"keyname": %q}`, rawKey)) recorder, request := post(fmt.Sprintf("/user/%s/key", usr.Name), b, c) s.router.ServeHTTP(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) + c.Assert(got, check.Equals, expected) + c.Assert(recorder.Code, check.Equals, 200) var k user.Key conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.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) + c.Assert(err, check.IsNil) + c.Assert(k.Body, check.Equals, keyBody) + c.Assert(k.Comment, check.Equals, keyComment) } -func (s *S) TestAddPostReceiveHookRepository(c *gocheck.C) { +func (s *S) TestAddPostReceiveHookRepository(c *check.C) { b := strings.NewReader(`{"repositories": ["some-repo"], "content": "some content"}`) recorder, request := post("/hook/post-receive", b, c) s.router.ServeHTTP(recorder, request) got := readBody(recorder.Body, c) expected := "hook post-receive successfully created for [some-repo]\n" - c.Assert(got, gocheck.Equals, expected) - c.Assert(recorder.Code, gocheck.Equals, 200) + c.Assert(got, check.Equals, expected) + c.Assert(recorder.Code, check.Equals, 200) file, err := fs.Filesystem().OpenFile("/tmp/repositories/some-repo.git/hooks/post-receive", os.O_RDONLY, 0755) defer file.Close() content, err := ioutil.ReadAll(file) - c.Assert(err, gocheck.IsNil) - c.Assert(string(content), gocheck.Equals, "some content") + c.Assert(err, check.IsNil) + c.Assert(string(content), check.Equals, "some content") } -func (s *S) TestAddPreReceiveHookRepository(c *gocheck.C) { +func (s *S) TestAddPreReceiveHookRepository(c *check.C) { b := strings.NewReader(`{"repositories": ["some-repo"], "content": "some content"}`) recorder, request := post("/hook/pre-receive", b, c) s.router.ServeHTTP(recorder, request) got := readBody(recorder.Body, c) expected := "hook pre-receive successfully created for [some-repo]\n" - c.Assert(got, gocheck.Equals, expected) - c.Assert(recorder.Code, gocheck.Equals, 200) + c.Assert(got, check.Equals, expected) + c.Assert(recorder.Code, check.Equals, 200) file, err := fs.Filesystem().OpenFile("/tmp/repositories/some-repo.git/hooks/pre-receive", os.O_RDONLY, 0755) defer file.Close() content, err := ioutil.ReadAll(file) - c.Assert(err, gocheck.IsNil) - c.Assert(string(content), gocheck.Equals, "some content") + c.Assert(err, check.IsNil) + c.Assert(string(content), check.Equals, "some content") } -func (s *S) TestAddUpdateReceiveHookRepository(c *gocheck.C) { +func (s *S) TestAddUpdateReceiveHookRepository(c *check.C) { b := strings.NewReader(`{"repositories": ["some-repo"], "content": "some content"}`) recorder, request := post("/hook/update", b, c) s.router.ServeHTTP(recorder, request) got := readBody(recorder.Body, c) expected := "hook update successfully created for [some-repo]\n" - c.Assert(got, gocheck.Equals, expected) - c.Assert(recorder.Code, gocheck.Equals, 200) + c.Assert(got, check.Equals, expected) + c.Assert(recorder.Code, check.Equals, 200) file, err := fs.Filesystem().OpenFile("/tmp/repositories/some-repo.git/hooks/update", os.O_RDONLY, 0755) defer file.Close() content, err := ioutil.ReadAll(file) - c.Assert(err, gocheck.IsNil) - c.Assert(string(content), gocheck.Equals, "some content") + c.Assert(err, check.IsNil) + c.Assert(string(content), check.Equals, "some content") } -func (s *S) TestAddInvalidHookRepository(c *gocheck.C) { +func (s *S) TestAddInvalidHookRepository(c *check.C) { b := strings.NewReader(`{"repositories": ["some-repo"], "content": "some content"}`) recorder, request := post("/hook/invalid-hook", b, c) s.router.ServeHTTP(recorder, request) got := readBody(recorder.Body, c) expected := "Unsupported hook, valid options are: post-receive, pre-receive or update\n" - c.Assert(got, gocheck.Equals, expected) - c.Assert(recorder.Code, gocheck.Equals, 400) + c.Assert(got, check.Equals, expected) + c.Assert(recorder.Code, check.Equals, 400) } -func (s *S) TestAddPostReceiveHook(c *gocheck.C) { +func (s *S) TestAddPostReceiveHook(c *check.C) { b := strings.NewReader(`{"content": "some content"}`) recorder, request := post("/hook/post-receive", b, c) s.router.ServeHTTP(recorder, request) got := readBody(recorder.Body, c) expected := "hook post-receive successfully created\n" - c.Assert(got, gocheck.Equals, expected) - c.Assert(recorder.Code, gocheck.Equals, 200) + c.Assert(got, check.Equals, expected) + c.Assert(recorder.Code, check.Equals, 200) file, err := fs.Filesystem().OpenFile("/home/git/bare-template/hooks/post-receive", os.O_RDONLY, 0755) defer file.Close() content, err := ioutil.ReadAll(file) - c.Assert(err, gocheck.IsNil) - c.Assert(string(content), gocheck.Equals, "some content") + c.Assert(err, check.IsNil) + c.Assert(string(content), check.Equals, "some content") } -func (s *S) TestAddPreReceiveHook(c *gocheck.C) { +func (s *S) TestAddPreReceiveHook(c *check.C) { b := strings.NewReader(`{"content": "some content"}`) recorder, request := post("/hook/pre-receive", b, c) s.router.ServeHTTP(recorder, request) got := readBody(recorder.Body, c) expected := "hook pre-receive successfully created\n" - c.Assert(got, gocheck.Equals, expected) - c.Assert(recorder.Code, gocheck.Equals, 200) + c.Assert(got, check.Equals, expected) + c.Assert(recorder.Code, check.Equals, 200) file, err := fs.Filesystem().OpenFile("/home/git/bare-template/hooks/pre-receive", os.O_RDONLY, 0755) defer file.Close() content, err := ioutil.ReadAll(file) - c.Assert(err, gocheck.IsNil) - c.Assert(string(content), gocheck.Equals, "some content") + c.Assert(err, check.IsNil) + c.Assert(string(content), check.Equals, "some content") } -func (s *S) TestAddUpdateHook(c *gocheck.C) { +func (s *S) TestAddUpdateHook(c *check.C) { b := strings.NewReader(`{"content": "some content"}`) recorder, request := post("/hook/update", b, c) s.router.ServeHTTP(recorder, request) got := readBody(recorder.Body, c) expected := "hook update successfully created\n" - c.Assert(got, gocheck.Equals, expected) - c.Assert(recorder.Code, gocheck.Equals, 200) + c.Assert(got, check.Equals, expected) + c.Assert(recorder.Code, check.Equals, 200) file, err := fs.Filesystem().OpenFile("/home/git/bare-template/hooks/update", os.O_RDONLY, 0755) defer file.Close() content, err := ioutil.ReadAll(file) - c.Assert(err, gocheck.IsNil) - c.Assert(string(content), gocheck.Equals, "some content") + c.Assert(err, check.IsNil) + c.Assert(string(content), check.Equals, "some content") } -func (s *S) TestAddInvalidHook(c *gocheck.C) { +func (s *S) TestAddInvalidHook(c *check.C) { b := strings.NewReader(`{"content": "some content"}`) recorder, request := post("/hook/invalid-hook", b, c) s.router.ServeHTTP(recorder, request) got := readBody(recorder.Body, c) expected := "Unsupported hook, valid options are: post-receive, pre-receive or update\n" - c.Assert(got, gocheck.Equals, expected) - c.Assert(recorder.Code, gocheck.Equals, 400) + c.Assert(got, check.Equals, expected) + c.Assert(recorder.Code, check.Equals, 400) } -func (s *S) TestAddPostReceiveOldFormatHook(c *gocheck.C) { +func (s *S) TestAddPostReceiveOldFormatHook(c *check.C) { b := strings.NewReader("some content") recorder, request := post("/hook/post-receive", b, c) s.router.ServeHTTP(recorder, request) got := readBody(recorder.Body, c) expected := "hook post-receive successfully created\n" - c.Assert(got, gocheck.Equals, expected) - c.Assert(recorder.Code, gocheck.Equals, 200) + c.Assert(got, check.Equals, expected) + c.Assert(recorder.Code, check.Equals, 200) file, err := fs.Filesystem().OpenFile("/home/git/bare-template/hooks/post-receive", os.O_RDONLY, 0755) defer file.Close() content, err := ioutil.ReadAll(file) - c.Assert(err, gocheck.IsNil) - c.Assert(string(content), gocheck.Equals, "some content") + c.Assert(err, check.IsNil) + c.Assert(string(content), check.Equals, "some content") } -func (s *S) TestAddPreReceiveOldFormatHook(c *gocheck.C) { +func (s *S) TestAddPreReceiveOldFormatHook(c *check.C) { b := strings.NewReader("some content") recorder, request := post("/hook/pre-receive", b, c) s.router.ServeHTTP(recorder, request) got := readBody(recorder.Body, c) expected := "hook pre-receive successfully created\n" - c.Assert(got, gocheck.Equals, expected) - c.Assert(recorder.Code, gocheck.Equals, 200) + c.Assert(got, check.Equals, expected) + c.Assert(recorder.Code, check.Equals, 200) file, err := fs.Filesystem().OpenFile("/home/git/bare-template/hooks/pre-receive", os.O_RDONLY, 0755) defer file.Close() content, err := ioutil.ReadAll(file) - c.Assert(err, gocheck.IsNil) - c.Assert(string(content), gocheck.Equals, "some content") + c.Assert(err, check.IsNil) + c.Assert(string(content), check.Equals, "some content") } -func (s *S) TestAddUpdateOldFormatHook(c *gocheck.C) { +func (s *S) TestAddUpdateOldFormatHook(c *check.C) { b := strings.NewReader("some content") recorder, request := post("/hook/update", b, c) s.router.ServeHTTP(recorder, request) got := readBody(recorder.Body, c) expected := "hook update successfully created\n" - c.Assert(got, gocheck.Equals, expected) - c.Assert(recorder.Code, gocheck.Equals, 200) + c.Assert(got, check.Equals, expected) + c.Assert(recorder.Code, check.Equals, 200) file, err := fs.Filesystem().OpenFile("/home/git/bare-template/hooks/update", os.O_RDONLY, 0755) defer file.Close() content, err := ioutil.ReadAll(file) - c.Assert(err, gocheck.IsNil) - c.Assert(string(content), gocheck.Equals, "some content") + c.Assert(err, check.IsNil) + c.Assert(string(content), check.Equals, "some content") } -func (s *S) TestAddInvalidOldFormatHook(c *gocheck.C) { +func (s *S) TestAddInvalidOldFormatHook(c *check.C) { b := strings.NewReader("some content") recorder, request := post("/hook/invalid-hook", b, c) s.router.ServeHTTP(recorder, request) got := readBody(recorder.Body, c) expected := "Unsupported hook, valid options are: post-receive, pre-receive or update\n" - c.Assert(got, gocheck.Equals, expected) - c.Assert(recorder.Code, gocheck.Equals, 400) + c.Assert(got, check.Equals, expected) + c.Assert(recorder.Code, check.Equals, 400) } -func (s *S) TestAddKeyShouldReturnErrorWhenUserDoesNotExist(c *gocheck.C) { +func (s *S) TestAddKeyShouldReturnErrorWhenUserDoesNotExist(c *check.C) { b := strings.NewReader(`{"key": "a public key"}`) recorder, request := post("/user/Frodo/key", b, c) s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, 404) + c.Assert(recorder.Code, check.Equals, 404) body, err := ioutil.ReadAll(recorder.Body) - c.Assert(err, gocheck.IsNil) - c.Assert(string(body), gocheck.Equals, "User not found\n") + c.Assert(err, check.IsNil) + c.Assert(string(body), check.Equals, "User not found\n") } -func (s *S) TestAddKeyShouldReturnProperStatusCodeWhenKeyAlreadyExists(c *gocheck.C) { +func (s *S) TestAddKeyShouldReturnProperStatusCodeWhenKeyAlreadyExists(c *check.C) { usr, err := user.New("Frodo", map[string]string{"keyname": rawKey}) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer user.Remove(usr.Name) b := strings.NewReader(fmt.Sprintf(`{"keyname": %q}`, rawKey)) recorder, request := post(fmt.Sprintf("/user/%s/key", usr.Name), b, c) s.router.ServeHTTP(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) + c.Assert(got, check.Equals, expected) + c.Assert(recorder.Code, check.Equals, http.StatusConflict) } -func (s *S) TestAddKeyShouldNotAcceptRepeatedKeysForDifferentUsers(c *gocheck.C) { +func (s *S) TestAddKeyShouldNotAcceptRepeatedKeysForDifferentUsers(c *check.C) { usr, err := user.New("Frodo", map[string]string{"keyname": rawKey}) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer user.Remove(usr.Name) usr2, err := user.New("tempo", nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer user.Remove(usr2.Name) b := strings.NewReader(fmt.Sprintf(`{"keyname": %q}`, rawKey)) recorder, request := post(fmt.Sprintf("/user/%s/key", usr2.Name), b, c) s.router.ServeHTTP(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) + c.Assert(got, check.Equals, expected) + c.Assert(recorder.Code, check.Equals, http.StatusConflict) } -func (s *S) TestAddKeyInvalidKey(c *gocheck.C) { +func (s *S) TestAddKeyInvalidKey(c *check.C) { u := user.User{Name: "Frodo"} conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() err = conn.User().Insert(&u) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.User().Remove(bson.M{"_id": "Frodo"}) b := strings.NewReader(`{"keyname":"invalid-rsa"}`) recorder, request := post(fmt.Sprintf("/user/%s/key", u.Name), b, c) s.router.ServeHTTP(recorder, request) got := readBody(recorder.Body, c) expected := "Invalid key\n" - c.Assert(got, gocheck.Equals, expected) - c.Assert(recorder.Code, gocheck.Equals, http.StatusBadRequest) + c.Assert(got, check.Equals, expected) + c.Assert(recorder.Code, check.Equals, http.StatusBadRequest) } -func (s *S) TestAddKeyShouldRequireKey(c *gocheck.C) { +func (s *S) TestAddKeyShouldRequireKey(c *check.C) { u := user.User{Name: "Frodo"} conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() err = conn.User().Insert(&u) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.User().Remove(bson.M{"_id": "Frodo"}) b := strings.NewReader(`{}`) recorder, request := post("/user/Frodo/key", b, c) @@ -729,338 +729,338 @@ func (s *S) TestAddKeyShouldRequireKey(c *gocheck.C) { body := readBody(recorder.Body, c) expected := "A key is needed" got := strings.Replace(body, "\n", "", -1) - c.Assert(got, gocheck.Equals, expected) + c.Assert(got, check.Equals, expected) } -func (s *S) TestAddKeyShouldWriteKeyInAuthorizedKeysFile(c *gocheck.C) { +func (s *S) TestAddKeyShouldWriteKeyInAuthorizedKeysFile(c *check.C) { u := user.User{Name: "Frodo"} conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() err = conn.User().Insert(&u) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.User().RemoveId("Frodo") b := strings.NewReader(fmt.Sprintf(`{"key": "%s"}`, rawKey)) recorder, request := post("/user/Frodo/key", b, c) s.router.ServeHTTP(recorder, request) defer conn.Key().Remove(bson.M{"name": "key", "username": u.Name}) - c.Assert(recorder.Code, gocheck.Equals, 200) + c.Assert(recorder.Code, check.Equals, 200) content := s.authKeysContent(c) - c.Assert(strings.HasSuffix(strings.TrimSpace(content), rawKey), gocheck.Equals, true) + c.Assert(strings.HasSuffix(strings.TrimSpace(content), rawKey), check.Equals, true) } -func (s *S) TestRemoveKeyGivesExpectedSuccessResponse(c *gocheck.C) { +func (s *S) TestRemoveKeyGivesExpectedSuccessResponse(c *check.C) { u, err := user.New("Gandalf", map[string]string{"keyname": rawKey}) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer user.Remove(u.Name) url := "/user/Gandalf/key/keyname" recorder, request := del(url, nil, c) s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, 200) + c.Assert(recorder.Code, check.Equals, 200) b := readBody(recorder.Body, c) - c.Assert(b, gocheck.Equals, `Key "keyname" successfully removed`) + c.Assert(b, check.Equals, `Key "keyname" successfully removed`) } -func (s *S) TestRemoveKeyRemovesKeyFromDatabase(c *gocheck.C) { +func (s *S) TestRemoveKeyRemovesKeyFromDatabase(c *check.C) { u, err := user.New("Gandalf", map[string]string{"keyname": rawKey}) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer user.Remove(u.Name) url := "/user/Gandalf/key/keyname" recorder, request := del(url, nil, c) s.router.ServeHTTP(recorder, request) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.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) + c.Assert(err, check.IsNil) + c.Assert(count, check.Equals, 0) } -func (s *S) TestRemoveKeyShouldRemoveKeyFromAuthorizedKeysFile(c *gocheck.C) { +func (s *S) TestRemoveKeyShouldRemoveKeyFromAuthorizedKeysFile(c *check.C) { u, err := user.New("Gandalf", map[string]string{"keyname": rawKey}) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer user.Remove(u.Name) url := "/user/Gandalf/key/keyname" recorder, request := del(url, nil, c) s.router.ServeHTTP(recorder, request) content := s.authKeysContent(c) - c.Assert(content, gocheck.Equals, "") + c.Assert(content, check.Equals, "") } -func (s *S) TestRemoveKeyShouldReturnErrorWithLineBreakAtEnd(c *gocheck.C) { +func (s *S) TestRemoveKeyShouldReturnErrorWithLineBreakAtEnd(c *check.C) { url := "/user/idiocracy/key/keyname" recorder, request := del(url, nil, c) s.router.ServeHTTP(recorder, request) b := readBody(recorder.Body, c) - c.Assert(b, gocheck.Equals, "User not found\n") + c.Assert(b, check.Equals, "User not found\n") } -func (s *S) TestListKeysGivesExpectedSuccessResponse(c *gocheck.C) { +func (s *S) TestListKeysGivesExpectedSuccessResponse(c *check.C) { keys := map[string]string{"key1": rawKey, "key2": otherKey} u, err := user.New("Gandalf", keys) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer user.Remove(u.Name) url := "/user/Gandalf/keys" request, err := http.NewRequest("GET", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, 200) + c.Assert(recorder.Code, check.Equals, 200) body, err := ioutil.ReadAll(recorder.Body) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) var data map[string]string err = json.Unmarshal(body, &data) - c.Assert(err, gocheck.IsNil) - c.Assert(data, gocheck.DeepEquals, keys) + c.Assert(err, check.IsNil) + c.Assert(data, check.DeepEquals, keys) } -func (s *S) TestListKeysWithoutKeysGivesEmptyJSON(c *gocheck.C) { +func (s *S) TestListKeysWithoutKeysGivesEmptyJSON(c *check.C) { u, err := user.New("Gandalf", map[string]string{}) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer user.Remove(u.Name) url := "/user/Gandalf/keys" request, err := http.NewRequest("GET", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, 200) + c.Assert(recorder.Code, check.Equals, 200) b := readBody(recorder.Body, c) - c.Assert(b, gocheck.Equals, "{}") + c.Assert(b, check.Equals, "{}") } -func (s *S) TestListKeysWithInvalidUserReturnsNotFound(c *gocheck.C) { +func (s *S) TestListKeysWithInvalidUserReturnsNotFound(c *check.C) { url := "/user/no-Gandalf/keys" request, err := http.NewRequest("GET", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, 404) + c.Assert(recorder.Code, check.Equals, 404) b := readBody(recorder.Body, c) - c.Assert(b, gocheck.Equals, "User not found\n") + c.Assert(b, check.Equals, "User not found\n") } -func (s *S) TestRemoveUser(c *gocheck.C) { +func (s *S) TestRemoveUser(c *check.C) { u, err := user.New("username", map[string]string{}) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) url := fmt.Sprintf("/user/%s", u.Name) request, err := http.NewRequest("DELETE", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, 200) + c.Assert(recorder.Code, check.Equals, 200) b, err := ioutil.ReadAll(recorder.Body) - c.Assert(err, gocheck.IsNil) - c.Assert(string(b), gocheck.Equals, "User \"username\" successfully removed\n") + c.Assert(err, check.IsNil) + c.Assert(string(b), check.Equals, "User \"username\" successfully removed\n") } -func (s *S) TestRemoveUserShouldRemoveFromDB(c *gocheck.C) { +func (s *S) TestRemoveUserShouldRemoveFromDB(c *check.C) { u, err := user.New("anuser", map[string]string{}) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) url := fmt.Sprintf("/user/%s", u.Name) request, err := http.NewRequest("DELETE", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() collection := conn.User() lenght, err := collection.Find(bson.M{"_id": u.Name}).Count() - c.Assert(err, gocheck.IsNil) - c.Assert(lenght, gocheck.Equals, 0) + c.Assert(err, check.IsNil) + c.Assert(lenght, check.Equals, 0) } -func (s *S) TestRemoveRepository(c *gocheck.C) { +func (s *S) TestRemoveRepository(c *check.C) { r, err := repository.New("myRepo", []string{"pippin"}, []string{""}, true) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) url := fmt.Sprintf("/repository/%s", r.Name) request, err := http.NewRequest("DELETE", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, 200) + c.Assert(recorder.Code, check.Equals, 200) b, err := ioutil.ReadAll(recorder.Body) - c.Assert(err, gocheck.IsNil) - c.Assert(string(b), gocheck.Equals, "Repository \"myRepo\" successfully removed\n") + c.Assert(err, check.IsNil) + c.Assert(string(b), check.Equals, "Repository \"myRepo\" successfully removed\n") } -func (s *S) TestRemoveRepositoryShouldRemoveFromDB(c *gocheck.C) { +func (s *S) TestRemoveRepositoryShouldRemoveFromDB(c *check.C) { r, err := repository.New("myRepo", []string{"pippin"}, []string{""}, true) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) url := fmt.Sprintf("/repository/%s", r.Name) request, err := http.NewRequest("DELETE", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() err = conn.Repository().Find(bson.M{"_id": r.Name}).One(&r) - c.Assert(err, gocheck.ErrorMatches, "^not found$") + c.Assert(err, check.ErrorMatches, "^not found$") } -func (s *S) TestRemoveRepositoryShouldReturn400OnFailure(c *gocheck.C) { +func (s *S) TestRemoveRepositoryShouldReturn400OnFailure(c *check.C) { url := "/repository/foo" request, err := http.NewRequest("DELETE", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, 400) + c.Assert(recorder.Code, check.Equals, 400) } -func (s *S) TestRemoveRepositoryShouldReturnErrorMsgWhenRepoDoesNotExist(c *gocheck.C) { +func (s *S) TestRemoveRepositoryShouldReturnErrorMsgWhenRepoDoesNotExist(c *check.C) { url := "/repository/foo" request, err := http.NewRequest("DELETE", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) b, err := ioutil.ReadAll(recorder.Body) - c.Assert(err, gocheck.IsNil) - c.Assert(string(b), gocheck.Equals, "Could not remove repository: not found\n") + c.Assert(err, check.IsNil) + c.Assert(string(b), check.Equals, "Could not remove repository: not found\n") } -func (s *S) TestUpdateRespositoryShouldReturnErrorWhenBodyIsEmpty(c *gocheck.C) { +func (s *S) TestUpdateRespositoryShouldReturnErrorWhenBodyIsEmpty(c *check.C) { r, err := repository.New("something", []string{"guardian@what.com"}, []string{""}, true) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.Repository().RemoveId(r.Name) b := strings.NewReader("") recorder, request := put("/repository/something", b, c) s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, 400) + c.Assert(recorder.Code, check.Equals, 400) } -func (s *S) TestUpdateRepositoryData(c *gocheck.C) { +func (s *S) TestUpdateRepositoryData(c *check.C) { r, err := repository.New("something", []string{"guardian@what.com"}, []string{""}, true) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.Repository().RemoveId(r.Name) url := fmt.Sprintf("/repository/%s", r.Name) body := strings.NewReader(`{"users": ["b"], "readonlyusers": ["a"], "ispublic": false}`) request, err := http.NewRequest("PUT", url, body) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusOK) + c.Assert(recorder.Code, check.Equals, http.StatusOK) r.Users = []string{"b"} r.ReadOnlyUsers = []string{"a"} r.IsPublic = false repo, err := repository.Get("something") - c.Assert(err, gocheck.IsNil) - c.Assert(repo, gocheck.DeepEquals, *r) + c.Assert(err, check.IsNil) + c.Assert(repo, check.DeepEquals, *r) } -func (s *S) TestUpdateRepositoryDataPartial(c *gocheck.C) { +func (s *S) TestUpdateRepositoryDataPartial(c *check.C) { r, err := repository.New("something", []string{"pippin"}, []string{"merry"}, true) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.Repository().RemoveId(r.Name) url := fmt.Sprintf("/repository/%s", r.Name) body := strings.NewReader(`{"readonlyusers": ["a", "b"]}`) request, err := http.NewRequest("PUT", url, body) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusOK) + c.Assert(recorder.Code, check.Equals, http.StatusOK) r.Users = []string{"pippin"} r.ReadOnlyUsers = []string{"a", "b"} r.IsPublic = true repo, err := repository.Get("something") - c.Assert(err, gocheck.IsNil) - c.Assert(repo, gocheck.DeepEquals, *r) + c.Assert(err, check.IsNil) + c.Assert(repo, check.DeepEquals, *r) } -func (s *S) TestUpdateRepositoryNotFound(c *gocheck.C) { +func (s *S) TestUpdateRepositoryNotFound(c *check.C) { url := "/repository/foo" body := strings.NewReader(`{"ispublic":true}`) request, err := http.NewRequest("PUT", url, body) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusNotFound) + c.Assert(recorder.Code, check.Equals, http.StatusNotFound) } -func (s *S) TestUpdateRepositoryInvalidJSON(c *gocheck.C) { +func (s *S) TestUpdateRepositoryInvalidJSON(c *check.C) { r, err := repository.New("bar", []string{"guardian@what.com"}, []string{""}, true) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.Repository().RemoveId(r.Name) url := "/repository/bar" body := strings.NewReader(`{"name""`) request, err := http.NewRequest("PUT", url, body) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusBadRequest) + c.Assert(recorder.Code, check.Equals, http.StatusBadRequest) } -func (s *S) TestRenameRepositoryWithNamespace(c *gocheck.C) { +func (s *S) TestRenameRepositoryWithNamespace(c *check.C) { r, err := repository.New("lift/raising", []string{"guardian@what.com"}, []string{}, true) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.Repository().RemoveId(r.Name) url := fmt.Sprintf("/repository/%s/", r.Name) body := strings.NewReader(`{"name":"norestraint/freedom"}`) request, err := http.NewRequest("PUT", url, body) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusOK) + c.Assert(recorder.Code, check.Equals, http.StatusOK) _, err = repository.Get("raising") - c.Assert(err, gocheck.NotNil) + c.Assert(err, check.NotNil) r.Name = "norestraint/freedom" repo, err := repository.Get("norestraint/freedom") - c.Assert(err, gocheck.IsNil) - c.Assert(repo, gocheck.DeepEquals, *r) + c.Assert(err, check.IsNil) + c.Assert(repo, check.DeepEquals, *r) } -func (s *S) TestRenameRepositoryInvalidJSON(c *gocheck.C) { +func (s *S) TestRenameRepositoryInvalidJSON(c *check.C) { r, err := repository.New("foo", []string{"guardian@what.com"}, []string{}, true) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.Repository().RemoveId(r.Name) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) url := "/repository/foo" body := strings.NewReader(`{"name""`) request, err := http.NewRequest("PUT", url, body) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusBadRequest) + c.Assert(recorder.Code, check.Equals, http.StatusBadRequest) } -func (s *S) TestRenameRepositoryNotfound(c *gocheck.C) { +func (s *S) TestRenameRepositoryNotfound(c *check.C) { url := "/repository/foo" body := strings.NewReader(`{"name":"freedom"}`) request, err := http.NewRequest("PUT", url, body) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusNotFound) + c.Assert(recorder.Code, check.Equals, http.StatusNotFound) } -func (s *S) TestHealthcheck(c *gocheck.C) { +func (s *S) TestHealthcheck(c *check.C) { url := "/healthcheck" request, err := http.NewRequest("GET", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusOK) - c.Assert(recorder.Body.String(), gocheck.Equals, "WORKING") + c.Assert(recorder.Code, check.Equals, http.StatusOK) + c.Assert(recorder.Body.String(), check.Equals, "WORKING") } -func (s *S) TestGetFileContents(c *gocheck.C) { +func (s *S) TestGetFileContents(c *check.C) { url := "/repository/repo/contents?path=README.txt" expected := "result" repository.Retriever = &repository.MockContentRetriever{ @@ -1070,16 +1070,16 @@ func (s *S) TestGetFileContents(c *gocheck.C) { repository.Retriever = nil }() request, err := http.NewRequest("GET", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusOK) - c.Assert(recorder.Body.String(), gocheck.Equals, expected) - c.Assert(recorder.Header()["Content-Type"][0], gocheck.Equals, "text/plain; charset=utf-8") - c.Assert(recorder.Header()["Content-Length"][0], gocheck.Equals, "6") + c.Assert(recorder.Code, check.Equals, http.StatusOK) + c.Assert(recorder.Body.String(), check.Equals, expected) + c.Assert(recorder.Header()["Content-Type"][0], check.Equals, "text/plain; charset=utf-8") + c.Assert(recorder.Header()["Content-Length"][0], check.Equals, "6") } -func (s *S) TestGetFileContentsWithoutExtension(c *gocheck.C) { +func (s *S) TestGetFileContentsWithoutExtension(c *check.C) { url := "/repository/repo/contents?path=README" expected := "result" repository.Retriever = &repository.MockContentRetriever{ @@ -1089,16 +1089,16 @@ func (s *S) TestGetFileContentsWithoutExtension(c *gocheck.C) { repository.Retriever = nil }() request, err := http.NewRequest("GET", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusOK) - c.Assert(recorder.Body.String(), gocheck.Equals, expected) - c.Assert(recorder.Header()["Content-Type"][0], gocheck.Equals, "text/plain; charset=utf-8") - c.Assert(recorder.Header()["Content-Length"][0], gocheck.Equals, "6") + c.Assert(recorder.Code, check.Equals, http.StatusOK) + c.Assert(recorder.Body.String(), check.Equals, expected) + c.Assert(recorder.Header()["Content-Type"][0], check.Equals, "text/plain; charset=utf-8") + c.Assert(recorder.Header()["Content-Length"][0], check.Equals, "6") } -func (s *S) TestGetBinaryFileContentsWithoutExtension(c *gocheck.C) { +func (s *S) TestGetBinaryFileContentsWithoutExtension(c *check.C) { url := "/repository/repo/contents?path=my-binary-file" expected := new(bytes.Buffer) expected.Write([]byte{10, 20, 30, 0, 9, 200}) @@ -1109,16 +1109,16 @@ func (s *S) TestGetBinaryFileContentsWithoutExtension(c *gocheck.C) { repository.Retriever = nil }() request, err := http.NewRequest("GET", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusOK) - c.Assert(recorder.Body, gocheck.DeepEquals, expected) - c.Assert(recorder.Header()["Content-Type"][0], gocheck.Equals, "application/octet-stream") - c.Assert(recorder.Header()["Content-Length"][0], gocheck.Equals, "6") + c.Assert(recorder.Code, check.Equals, http.StatusOK) + c.Assert(recorder.Body, check.DeepEquals, expected) + c.Assert(recorder.Header()["Content-Type"][0], check.Equals, "application/octet-stream") + c.Assert(recorder.Header()["Content-Length"][0], check.Equals, "6") } -func (s *S) TestGetFileContentsWithRef(c *gocheck.C) { +func (s *S) TestGetFileContentsWithRef(c *check.C) { url := "/repository/repo/contents?path=README.txt&ref=other" expected := "result" mockRetriever := repository.MockContentRetriever{ @@ -1129,17 +1129,17 @@ func (s *S) TestGetFileContentsWithRef(c *gocheck.C) { repository.Retriever = nil }() request, err := http.NewRequest("GET", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusOK) - c.Assert(recorder.Body.String(), gocheck.Equals, expected) - c.Assert(recorder.Header()["Content-Type"][0], gocheck.Equals, "text/plain; charset=utf-8") - c.Assert(recorder.Header()["Content-Length"][0], gocheck.Equals, "6") - c.Assert(mockRetriever.LastRef, gocheck.Equals, "other") + c.Assert(recorder.Code, check.Equals, http.StatusOK) + c.Assert(recorder.Body.String(), check.Equals, expected) + c.Assert(recorder.Header()["Content-Type"][0], check.Equals, "text/plain; charset=utf-8") + c.Assert(recorder.Header()["Content-Length"][0], check.Equals, "6") + c.Assert(mockRetriever.LastRef, check.Equals, "other") } -func (s *S) TestGetFileContentsWhenCommandFails(c *gocheck.C) { +func (s *S) TestGetFileContentsWhenCommandFails(c *check.C) { url := "/repository/repo/contents?path=README.txt&ref=other" outputError := fmt.Errorf("command error") repository.Retriever = &repository.MockContentRetriever{ @@ -1149,47 +1149,47 @@ func (s *S) TestGetFileContentsWhenCommandFails(c *gocheck.C) { repository.Retriever = nil }() request, err := http.NewRequest("GET", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusNotFound) - c.Assert(recorder.Body.String(), gocheck.Equals, "command error\n") + c.Assert(recorder.Code, check.Equals, http.StatusNotFound) + c.Assert(recorder.Body.String(), check.Equals, "command error\n") } -func (s *S) TestGetFileContentsWhenNoPath(c *gocheck.C) { +func (s *S) TestGetFileContentsWhenNoPath(c *check.C) { url := "/repository/repo/contents?&ref=other" request, err := http.NewRequest("GET", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusBadRequest) + c.Assert(recorder.Code, check.Equals, http.StatusBadRequest) expected := "Error when trying to obtain an uknown file on ref other of repository repo (path is required).\n" - c.Assert(recorder.Body.String(), gocheck.Equals, expected) + c.Assert(recorder.Body.String(), check.Equals, expected) } -func (s *S) TestGetArchiveWhenNoRef(c *gocheck.C) { +func (s *S) TestGetArchiveWhenNoRef(c *check.C) { url := "/repository/repo/archive?ref=&format=zip" request, err := http.NewRequest("GET", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusBadRequest) + c.Assert(recorder.Code, check.Equals, http.StatusBadRequest) expected := "Error when trying to obtain archive for ref '' (format: zip) of repository 'repo' (ref and format are required).\n" - c.Assert(recorder.Body.String(), gocheck.Equals, expected) + c.Assert(recorder.Body.String(), check.Equals, expected) } -func (s *S) TestGetArchiveWhenNoFormat(c *gocheck.C) { +func (s *S) TestGetArchiveWhenNoFormat(c *check.C) { url := "/repository/repo/archive?ref=master&format=" request, err := http.NewRequest("GET", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusBadRequest) + c.Assert(recorder.Code, check.Equals, http.StatusBadRequest) expected := "Error when trying to obtain archive for ref 'master' (format: ) of repository 'repo' (ref and format are required).\n" - c.Assert(recorder.Body.String(), gocheck.Equals, expected) + c.Assert(recorder.Body.String(), check.Equals, expected) } -func (s *S) TestGetArchiveWhenCommandFails(c *gocheck.C) { +func (s *S) TestGetArchiveWhenCommandFails(c *check.C) { url := "/repository/repo/archive?ref=master&format=zip" expected := fmt.Errorf("output error") mockRetriever := repository.MockContentRetriever{ @@ -1200,14 +1200,14 @@ func (s *S) TestGetArchiveWhenCommandFails(c *gocheck.C) { repository.Retriever = nil }() request, err := http.NewRequest("GET", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusNotFound) - c.Assert(recorder.Body.String(), gocheck.Equals, "output error\n") + c.Assert(recorder.Code, check.Equals, http.StatusNotFound) + c.Assert(recorder.Body.String(), check.Equals, "output error\n") } -func (s *S) TestGetArchive(c *gocheck.C) { +func (s *S) TestGetArchive(c *check.C) { url := "/repository/repo/archive?ref=master&format=zip" expected := "result123" mockRetriever := repository.MockContentRetriever{ @@ -1218,23 +1218,23 @@ func (s *S) TestGetArchive(c *gocheck.C) { repository.Retriever = nil }() request, err := http.NewRequest("GET", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusOK) - c.Assert(recorder.Body.String(), gocheck.Equals, expected) - c.Assert(mockRetriever.LastFormat, gocheck.Equals, repository.Zip) - c.Assert(recorder.Header()["Content-Type"][0], gocheck.Equals, "application/octet-stream") - c.Assert(recorder.Header()["Content-Disposition"][0], gocheck.Equals, "attachment; filename=\"repo_master.zip\"") - c.Assert(recorder.Header()["Content-Transfer-Encoding"][0], gocheck.Equals, "binary") - c.Assert(recorder.Header()["Accept-Ranges"][0], gocheck.Equals, "bytes") - c.Assert(recorder.Header()["Content-Length"][0], gocheck.Equals, "9") - c.Assert(recorder.Header()["Cache-Control"][0], gocheck.Equals, "private") - c.Assert(recorder.Header()["Pragma"][0], gocheck.Equals, "private") - c.Assert(recorder.Header()["Expires"][0], gocheck.Equals, "Mon, 26 Jul 1997 05:00:00 GMT") + c.Assert(recorder.Code, check.Equals, http.StatusOK) + c.Assert(recorder.Body.String(), check.Equals, expected) + c.Assert(mockRetriever.LastFormat, check.Equals, repository.Zip) + c.Assert(recorder.Header()["Content-Type"][0], check.Equals, "application/octet-stream") + c.Assert(recorder.Header()["Content-Disposition"][0], check.Equals, "attachment; filename=\"repo_master.zip\"") + c.Assert(recorder.Header()["Content-Transfer-Encoding"][0], check.Equals, "binary") + c.Assert(recorder.Header()["Accept-Ranges"][0], check.Equals, "bytes") + c.Assert(recorder.Header()["Content-Length"][0], check.Equals, "9") + c.Assert(recorder.Header()["Cache-Control"][0], check.Equals, "private") + c.Assert(recorder.Header()["Pragma"][0], check.Equals, "private") + c.Assert(recorder.Header()["Expires"][0], check.Equals, "Mon, 26 Jul 1997 05:00:00 GMT") } -func (s *S) TestGetTreeWithDefaultValues(c *gocheck.C) { +func (s *S) TestGetTreeWithDefaultValues(c *check.C) { url := "/repository/repo/tree" tree := make([]map[string]string, 1) tree[0] = make(map[string]string) @@ -1251,23 +1251,23 @@ func (s *S) TestGetTreeWithDefaultValues(c *gocheck.C) { repository.Retriever = nil }() request, err := http.NewRequest("GET", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusOK) + c.Assert(recorder.Code, check.Equals, http.StatusOK) var obj []map[string]string json.Unmarshal(recorder.Body.Bytes(), &obj) - c.Assert(len(obj), gocheck.Equals, 1) - c.Assert(obj[0]["permission"], gocheck.Equals, tree[0]["permission"]) - c.Assert(obj[0]["filetype"], gocheck.Equals, tree[0]["filetype"]) - c.Assert(obj[0]["hash"], gocheck.Equals, tree[0]["hash"]) - c.Assert(obj[0]["path"], gocheck.Equals, tree[0]["path"]) - c.Assert(obj[0]["rawPath"], gocheck.Equals, tree[0]["rawPath"]) - c.Assert(mockRetriever.LastRef, gocheck.Equals, "master") - c.Assert(mockRetriever.LastPath, gocheck.Equals, ".") + c.Assert(len(obj), check.Equals, 1) + c.Assert(obj[0]["permission"], check.Equals, tree[0]["permission"]) + c.Assert(obj[0]["filetype"], check.Equals, tree[0]["filetype"]) + c.Assert(obj[0]["hash"], check.Equals, tree[0]["hash"]) + c.Assert(obj[0]["path"], check.Equals, tree[0]["path"]) + c.Assert(obj[0]["rawPath"], check.Equals, tree[0]["rawPath"]) + c.Assert(mockRetriever.LastRef, check.Equals, "master") + c.Assert(mockRetriever.LastPath, check.Equals, ".") } -func (s *S) TestGetTreeWithSpecificPath(c *gocheck.C) { +func (s *S) TestGetTreeWithSpecificPath(c *check.C) { url := "/repository/repo/tree?path=/test" tree := make([]map[string]string, 1) tree[0] = make(map[string]string) @@ -1284,23 +1284,23 @@ func (s *S) TestGetTreeWithSpecificPath(c *gocheck.C) { repository.Retriever = nil }() request, err := http.NewRequest("GET", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusOK) + c.Assert(recorder.Code, check.Equals, http.StatusOK) var obj []map[string]string json.Unmarshal(recorder.Body.Bytes(), &obj) - c.Assert(len(obj), gocheck.Equals, 1) - c.Assert(obj[0]["permission"], gocheck.Equals, tree[0]["permission"]) - c.Assert(obj[0]["filetype"], gocheck.Equals, tree[0]["filetype"]) - c.Assert(obj[0]["hash"], gocheck.Equals, tree[0]["hash"]) - c.Assert(obj[0]["path"], gocheck.Equals, tree[0]["path"]) - c.Assert(obj[0]["rawPath"], gocheck.Equals, tree[0]["rawPath"]) - c.Assert(mockRetriever.LastRef, gocheck.Equals, "master") - c.Assert(mockRetriever.LastPath, gocheck.Equals, "/test") + c.Assert(len(obj), check.Equals, 1) + c.Assert(obj[0]["permission"], check.Equals, tree[0]["permission"]) + c.Assert(obj[0]["filetype"], check.Equals, tree[0]["filetype"]) + c.Assert(obj[0]["hash"], check.Equals, tree[0]["hash"]) + c.Assert(obj[0]["path"], check.Equals, tree[0]["path"]) + c.Assert(obj[0]["rawPath"], check.Equals, tree[0]["rawPath"]) + c.Assert(mockRetriever.LastRef, check.Equals, "master") + c.Assert(mockRetriever.LastPath, check.Equals, "/test") } -func (s *S) TestGetTreeWithSpecificRef(c *gocheck.C) { +func (s *S) TestGetTreeWithSpecificRef(c *check.C) { url := "/repository/repo/tree?path=/test&ref=1.1.1" tree := make([]map[string]string, 1) tree[0] = make(map[string]string) @@ -1317,23 +1317,23 @@ func (s *S) TestGetTreeWithSpecificRef(c *gocheck.C) { repository.Retriever = nil }() request, err := http.NewRequest("GET", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusOK) + c.Assert(recorder.Code, check.Equals, http.StatusOK) var obj []map[string]string json.Unmarshal(recorder.Body.Bytes(), &obj) - c.Assert(len(obj), gocheck.Equals, 1) - c.Assert(obj[0]["permission"], gocheck.Equals, tree[0]["permission"]) - c.Assert(obj[0]["filetype"], gocheck.Equals, tree[0]["filetype"]) - c.Assert(obj[0]["hash"], gocheck.Equals, tree[0]["hash"]) - c.Assert(obj[0]["path"], gocheck.Equals, tree[0]["path"]) - c.Assert(obj[0]["rawPath"], gocheck.Equals, tree[0]["rawPath"]) - c.Assert(mockRetriever.LastRef, gocheck.Equals, "1.1.1") - c.Assert(mockRetriever.LastPath, gocheck.Equals, "/test") + c.Assert(len(obj), check.Equals, 1) + c.Assert(obj[0]["permission"], check.Equals, tree[0]["permission"]) + c.Assert(obj[0]["filetype"], check.Equals, tree[0]["filetype"]) + c.Assert(obj[0]["hash"], check.Equals, tree[0]["hash"]) + c.Assert(obj[0]["path"], check.Equals, tree[0]["path"]) + c.Assert(obj[0]["rawPath"], check.Equals, tree[0]["rawPath"]) + c.Assert(mockRetriever.LastRef, check.Equals, "1.1.1") + c.Assert(mockRetriever.LastPath, check.Equals, "/test") } -func (s *S) TestGetTreeWhenCommandFails(c *gocheck.C) { +func (s *S) TestGetTreeWhenCommandFails(c *check.C) { url := "/repository/repo/tree/?ref=master&path=/test" expected := fmt.Errorf("output error") mockRetriever := repository.MockContentRetriever{ @@ -1344,14 +1344,14 @@ func (s *S) TestGetTreeWhenCommandFails(c *gocheck.C) { repository.Retriever = nil }() request, err := http.NewRequest("GET", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusBadRequest) - c.Assert(recorder.Body.String(), gocheck.Equals, "Error when trying to obtain tree for path /test on ref master of repository repo (output error).\n") + c.Assert(recorder.Code, check.Equals, http.StatusBadRequest) + c.Assert(recorder.Body.String(), check.Equals, "Error when trying to obtain tree for path /test on ref master of repository repo (output error).\n") } -func (s *S) TestGetBranches(c *gocheck.C) { +func (s *S) TestGetBranches(c *check.C) { url := "/repository/repo/branches" refs := make([]repository.Ref, 1) refs[0] = repository.Ref{ @@ -1380,28 +1380,28 @@ func (s *S) TestGetBranches(c *gocheck.C) { repository.Retriever = nil }() request, err := http.NewRequest("GET", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusOK) + c.Assert(recorder.Code, check.Equals, http.StatusOK) var obj []repository.Ref json.Unmarshal(recorder.Body.Bytes(), &obj) - c.Assert(obj, gocheck.HasLen, 1) - c.Assert(obj[0], gocheck.DeepEquals, refs[0]) + c.Assert(obj, check.HasLen, 1) + c.Assert(obj[0], check.DeepEquals, refs[0]) } -func (s *S) TestGetBranchesWhenRepoNonExistent(c *gocheck.C) { +func (s *S) TestGetBranchesWhenRepoNonExistent(c *check.C) { url := "/repository/repo/branches" request, err := http.NewRequest("GET", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusBadRequest) + c.Assert(recorder.Code, check.Equals, http.StatusBadRequest) expected := "Error when trying to obtain the branches of repository repo (Error when trying to obtain the refs of repository repo (Repository does not exist).).\n" - c.Assert(recorder.Body.String(), gocheck.Equals, expected) + c.Assert(recorder.Body.String(), check.Equals, expected) } -func (s *S) TestGetBranchesWhenCommandFails(c *gocheck.C) { +func (s *S) TestGetBranchesWhenCommandFails(c *check.C) { url := "/repository/repo/branches" expected := fmt.Errorf("output error") mockRetriever := repository.MockContentRetriever{ @@ -1412,14 +1412,14 @@ func (s *S) TestGetBranchesWhenCommandFails(c *gocheck.C) { repository.Retriever = nil }() request, err := http.NewRequest("GET", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusBadRequest) - c.Assert(recorder.Body.String(), gocheck.Equals, "Error when trying to obtain the branches of repository repo (output error).\n") + c.Assert(recorder.Code, check.Equals, http.StatusBadRequest) + c.Assert(recorder.Body.String(), check.Equals, "Error when trying to obtain the branches of repository repo (output error).\n") } -func (s *S) TestGetTags(c *gocheck.C) { +func (s *S) TestGetTags(c *check.C) { url := "/repository/repo/tags" refs := make([]repository.Ref, 1) refs[0] = repository.Ref{ @@ -1448,17 +1448,17 @@ func (s *S) TestGetTags(c *gocheck.C) { repository.Retriever = nil }() request, err := http.NewRequest("GET", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusOK) + c.Assert(recorder.Code, check.Equals, http.StatusOK) var obj []repository.Ref json.Unmarshal(recorder.Body.Bytes(), &obj) - c.Assert(obj, gocheck.HasLen, 1) - c.Assert(obj[0], gocheck.DeepEquals, refs[0]) + c.Assert(obj, check.HasLen, 1) + c.Assert(obj[0], check.DeepEquals, refs[0]) } -func (s *S) TestGetDiff(c *gocheck.C) { +func (s *S) TestGetDiff(c *check.C) { url := "/repository/repo/diff/commits?previous_commit=1b970b076bbb30d708e262b402d4e31910e1dc10&last_commit=545b1904af34458704e2aa06ff1aaffad5289f8f" expected := "test_diff" repository.Retriever = &repository.MockContentRetriever{ @@ -1468,14 +1468,14 @@ func (s *S) TestGetDiff(c *gocheck.C) { repository.Retriever = nil }() request, err := http.NewRequest("GET", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusOK) - c.Assert(recorder.Body.String(), gocheck.Equals, expected) + c.Assert(recorder.Code, check.Equals, http.StatusOK) + c.Assert(recorder.Body.String(), check.Equals, expected) } -func (s *S) TestGetDiffWhenCommandFails(c *gocheck.C) { +func (s *S) TestGetDiffWhenCommandFails(c *check.C) { url := "/repository/repo/diff/commits?previous_commit=1b970b076bbb30d708e262b402d4e31910e1dc10&last_commit=545b1904af34458704e2aa06ff1aaffad5289f8f" outputError := fmt.Errorf("command error") repository.Retriever = &repository.MockContentRetriever{ @@ -1485,25 +1485,25 @@ func (s *S) TestGetDiffWhenCommandFails(c *gocheck.C) { repository.Retriever = nil }() request, err := http.NewRequest("GET", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusNotFound) - c.Assert(recorder.Body.String(), gocheck.Equals, "command error\n") + c.Assert(recorder.Code, check.Equals, http.StatusNotFound) + c.Assert(recorder.Body.String(), check.Equals, "command error\n") } -func (s *S) TestGetDiffWhenNoCommits(c *gocheck.C) { +func (s *S) TestGetDiffWhenNoCommits(c *check.C) { url := "/repository/repo/diff/commits?previous_commit=&last_commit=" request, err := http.NewRequest("GET", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) expected := "Error when trying to obtain diff between hash commits of repository repo (Hash Commit(s) are required).\n" - c.Assert(recorder.Code, gocheck.Equals, http.StatusBadRequest) - c.Assert(recorder.Body.String(), gocheck.Equals, expected) + c.Assert(recorder.Code, check.Equals, http.StatusBadRequest) + c.Assert(recorder.Body.String(), check.Equals, expected) } -func (s *S) TestPostNewCommit(c *gocheck.C) { +func (s *S) TestPostNewCommit(c *check.C) { url := "/repository/repo/commit" params := map[string]string{ "message": "Repository scaffold", @@ -1519,7 +1519,7 @@ func (s *S) TestPostNewCommit(c *gocheck.C) { {"WOW/WOW.WOW", "WOW\nWOW"}, } buf, err := multipartzip.CreateZipBuffer(files) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) reader, writer := io.Pipe() go multipartzip.StreamWriteMultipartForm(params, "zipfile", "scaffold.zip", "muchBOUNDARY", writer, buf) mockRetriever := repository.MockContentRetriever{ @@ -1548,14 +1548,14 @@ func (s *S) TestPostNewCommit(c *gocheck.C) { }() request, err := http.NewRequest("POST", url, reader) request.Header.Set("Content-Type", "multipart/form-data;boundary=muchBOUNDARY") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusOK) + c.Assert(recorder.Code, check.Equals, http.StatusOK) var data map[string]interface{} body, err := ioutil.ReadAll(recorder.Body) err = json.Unmarshal(body, &data) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) expected := map[string]interface{}{ "ref": "some-random-ref", "name": "master", @@ -1576,10 +1576,10 @@ func (s *S) TestPostNewCommit(c *gocheck.C) { "subject": "Repository scaffold", "createdAt": "Mon Jul 28 10:13:27 2014 -0300", } - c.Assert(data, gocheck.DeepEquals, expected) + c.Assert(data, check.DeepEquals, expected) } -func (s *S) TestPostNewCommitWithoutBranch(c *gocheck.C) { +func (s *S) TestPostNewCommitWithoutBranch(c *check.C) { url := "/repository/repo/commit" params := map[string]string{ "message": "Repository scaffold", @@ -1594,7 +1594,7 @@ func (s *S) TestPostNewCommitWithoutBranch(c *gocheck.C) { {"WOW/WOW.WOW", "WOW\nWOW"}, } buf, err := multipartzip.CreateZipBuffer(files) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) reader, writer := io.Pipe() go multipartzip.StreamWriteMultipartForm(params, "zipfile", "scaffold.zip", "muchBOUNDARY", writer, buf) repository.Retriever = &repository.MockContentRetriever{} @@ -1603,13 +1603,13 @@ func (s *S) TestPostNewCommitWithoutBranch(c *gocheck.C) { }() request, err := http.NewRequest("POST", url, reader) request.Header.Set("Content-Type", "multipart/form-data;boundary=muchBOUNDARY") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusBadRequest) + c.Assert(recorder.Code, check.Equals, http.StatusBadRequest) } -func (s *S) TestPostNewCommitWithEmptyBranch(c *gocheck.C) { +func (s *S) TestPostNewCommitWithEmptyBranch(c *check.C) { url := "/repository/repo/commit" params := map[string]string{ "message": "Repository scaffold", @@ -1625,7 +1625,7 @@ func (s *S) TestPostNewCommitWithEmptyBranch(c *gocheck.C) { {"WOW/WOW.WOW", "WOW\nWOW"}, } buf, err := multipartzip.CreateZipBuffer(files) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) reader, writer := io.Pipe() go multipartzip.StreamWriteMultipartForm(params, "zipfile", "scaffold.zip", "muchBOUNDARY", writer, buf) repository.Retriever = &repository.MockContentRetriever{} @@ -1634,13 +1634,13 @@ func (s *S) TestPostNewCommitWithEmptyBranch(c *gocheck.C) { }() request, err := http.NewRequest("POST", url, reader) request.Header.Set("Content-Type", "multipart/form-data;boundary=muchBOUNDARY") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusBadRequest) + c.Assert(recorder.Code, check.Equals, http.StatusBadRequest) } -func (s *S) TestLogs(c *gocheck.C) { +func (s *S) TestLogs(c *check.C) { url := "/repository/repo/logs?ref=HEAD&total=1" objects := repository.GitHistory{} parent := make([]string, 2) @@ -1671,18 +1671,18 @@ func (s *S) TestLogs(c *gocheck.C) { repository.Retriever = nil }() request, err := http.NewRequest("GET", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusOK) + c.Assert(recorder.Code, check.Equals, http.StatusOK) var obj repository.GitHistory json.Unmarshal(recorder.Body.Bytes(), &obj) - c.Assert(obj.Next, gocheck.Equals, "b231c2d3e4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b9") - c.Assert(obj.Commits, gocheck.HasLen, 1) - c.Assert(obj.Commits[0], gocheck.DeepEquals, commits[0]) + c.Assert(obj.Next, check.Equals, "b231c2d3e4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b9") + c.Assert(obj.Commits, check.HasLen, 1) + c.Assert(obj.Commits[0], check.DeepEquals, commits[0]) } -func (s *S) TestLogsWithPath(c *gocheck.C) { +func (s *S) TestLogsWithPath(c *check.C) { url := "/repository/repo/logs?ref=HEAD&total=1&path=README.txt" objects := repository.GitHistory{} parent := make([]string, 2) @@ -1713,36 +1713,36 @@ func (s *S) TestLogsWithPath(c *gocheck.C) { repository.Retriever = nil }() request, err := http.NewRequest("GET", url, nil) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) recorder := httptest.NewRecorder() s.router.ServeHTTP(recorder, request) - c.Assert(recorder.Code, gocheck.Equals, http.StatusOK) + c.Assert(recorder.Code, check.Equals, http.StatusOK) var obj repository.GitHistory json.Unmarshal(recorder.Body.Bytes(), &obj) - c.Assert(obj.Next, gocheck.Equals, "b231c2d3e4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b9") - c.Assert(obj.Commits, gocheck.HasLen, 1) - c.Assert(obj.Commits[0], gocheck.DeepEquals, commits[0]) + c.Assert(obj.Next, check.Equals, "b231c2d3e4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b9") + c.Assert(obj.Commits, check.HasLen, 1) + c.Assert(obj.Commits[0], check.DeepEquals, commits[0]) } -func (s *S) TestGetMimeTypeFromExtension(c *gocheck.C) { +func (s *S) TestGetMimeTypeFromExtension(c *check.C) { path := "my-text-file.txt" content := new(bytes.Buffer) content.WriteString("") - c.Assert(getMimeType(path, content.Bytes()), gocheck.Equals, "text/plain; charset=utf-8") + c.Assert(getMimeType(path, content.Bytes()), check.Equals, "text/plain; charset=utf-8") path = "my-text-file.sh" content = new(bytes.Buffer) content.WriteString("") expected := mime.TypeByExtension(".sh") - c.Assert(getMimeType(path, content.Bytes()), gocheck.Equals, expected) + c.Assert(getMimeType(path, content.Bytes()), check.Equals, expected) } -func (s *S) TestGetMimeTypeFromContent(c *gocheck.C) { +func (s *S) TestGetMimeTypeFromContent(c *check.C) { path := "README" content := new(bytes.Buffer) content.WriteString("thou shalt not pass") - c.Assert(getMimeType(path, content.Bytes()), gocheck.Equals, "text/plain; charset=utf-8") + c.Assert(getMimeType(path, content.Bytes()), check.Equals, "text/plain; charset=utf-8") path = "my-binary-file" content = new(bytes.Buffer) content.Write([]byte{10, 20, 30, 0, 9, 200}) - c.Assert(getMimeType(path, content.Bytes()), gocheck.Equals, "application/octet-stream") + c.Assert(getMimeType(path, content.Bytes()), check.Equals, "application/octet-stream") } diff --git a/api/utils_test.go b/api/utils_test.go index df04e64..b5e7ab9 100644 --- a/api/utils_test.go +++ b/api/utils_test.go @@ -14,11 +14,11 @@ import ( "github.com/tsuru/gandalf/fs" "github.com/tsuru/gandalf/user" "github.com/tsuru/tsuru/fs/fstest" + "gopkg.in/check.v1" "gopkg.in/mgo.v2/bson" - "launchpad.net/gocheck" ) -func Test(t *testing.T) { gocheck.TestingT(t) } +func Test(t *testing.T) { check.TestingT(t) } type S struct { tmpdir string @@ -26,53 +26,53 @@ type S struct { router *pat.Router } -var _ = gocheck.Suite(&S{}) +var _ = check.Suite(&S{}) -func (s *S) SetUpSuite(c *gocheck.C) { +func (s *S) SetUpSuite(c *check.C) { err := config.ReadConfigFile("../etc/gandalf.conf") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) config.Set("database:url", "127.0.0.1:27017") config.Set("database:name", "gandalf_api_tests") s.tmpdir, err = commandmocker.Add("git", "") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) s.router = SetupRouter() } -func (s *S) SetUpTest(c *gocheck.C) { +func (s *S) SetUpTest(c *check.C) { s.rfs = &fstest.RecordingFs{} fs.Fsystem = s.rfs bareTemplate, _ := config.GetString("git:bare:template") fs.Fsystem.MkdirAll(bareTemplate+"/hooks", 0755) } -func (s *S) TearDownTest(c *gocheck.C) { +func (s *S) TearDownTest(c *check.C) { fs.Fsystem = nil } -func (s *S) TearDownSuite(c *gocheck.C) { +func (s *S) TearDownSuite(c *check.C) { commandmocker.Remove(s.tmpdir) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() conn.User().Database.DropDatabase() } -func (s *S) TestGetUserOr404(c *gocheck.C) { +func (s *S) TestGetUserOr404(c *check.C) { u := user.User{Name: "umi"} conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() err = conn.User().Insert(&u) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.User().Remove(bson.M{"_id": u.Name}) rUser, err := getUserOr404("umi") - c.Assert(err, gocheck.IsNil) - c.Assert(rUser.Name, gocheck.Equals, "umi") + c.Assert(err, check.IsNil) + c.Assert(rUser.Name, check.Equals, "umi") } -func (s *S) TestGetUserOr404ShouldReturn404WhenUserDoesntExist(c *gocheck.C) { +func (s *S) TestGetUserOr404ShouldReturn404WhenUserDoesntExist(c *check.C) { _, e := getUserOr404("umi") expected := "User umi not found" got := e.Error() - c.Assert(got, gocheck.Equals, expected) + c.Assert(got, check.Equals, expected) } diff --git a/bin/gandalf_test.go b/bin/gandalf_test.go index 322ae8c..a40b27b 100644 --- a/bin/gandalf_test.go +++ b/bin/gandalf_test.go @@ -1,4 +1,4 @@ -// Copyright 2014 gandalf authors. All rights reserved. +// Copyright 2015 gandalf authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -16,222 +16,222 @@ import ( "github.com/tsuru/gandalf/db" "github.com/tsuru/gandalf/repository" "github.com/tsuru/gandalf/user" + "gopkg.in/check.v1" "gopkg.in/mgo.v2/bson" - "launchpad.net/gocheck" ) -func Test(t *testing.T) { gocheck.TestingT(t) } +func Test(t *testing.T) { check.TestingT(t) } type S struct { user *user.User repo *repository.Repository } -var _ = gocheck.Suite(&S{}) +var _ = check.Suite(&S{}) -func (s *S) SetUpSuite(c *gocheck.C) { +func (s *S) SetUpSuite(c *check.C) { var err error log, err = syslog.New(syslog.LOG_INFO, "gandalf-listener") - c.Check(err, gocheck.IsNil) + c.Check(err, check.IsNil) err = config.ReadConfigFile("../etc/gandalf.conf") - c.Check(err, gocheck.IsNil) + c.Check(err, check.IsNil) config.Set("database:name", "gandalf_bin_tests") s.user, err = user.New("testuser", map[string]string{}) - c.Check(err, gocheck.IsNil) + c.Check(err, check.IsNil) // does not uses repository.New to avoid creation of bare git repo s.repo = &repository.Repository{Name: "myapp", Users: []string{s.user.Name}} conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() err = conn.Repository().Insert(s.repo) - c.Check(err, gocheck.IsNil) + c.Check(err, check.IsNil) } -func (s *S) TearDownSuite(c *gocheck.C) { +func (s *S) TearDownSuite(c *check.C) { conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() conn.User().Database.DropDatabase() } -func (s *S) TestHasWritePermissionSholdReturnTrueWhenUserCanWriteInRepo(c *gocheck.C) { +func (s *S) TestHasWritePermissionSholdReturnTrueWhenUserCanWriteInRepo(c *check.C) { allowed := hasWritePermission(s.user, s.repo) - c.Assert(allowed, gocheck.Equals, true) + c.Assert(allowed, check.Equals, true) } -func (s *S) TestHasWritePermissionShouldReturnFalseWhenUserCannotWriteinRepo(c *gocheck.C) { +func (s *S) TestHasWritePermissionShouldReturnFalseWhenUserCannotWriteinRepo(c *check.C) { r := &repository.Repository{Name: "myotherapp"} conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() conn.Repository().Insert(&r) defer conn.Repository().Remove(bson.M{"_id": r.Name}) allowed := hasWritePermission(s.user, r) - c.Assert(allowed, gocheck.Equals, false) + c.Assert(allowed, check.Equals, false) } -func (s *S) TestHasReadPermissionShouldReturnTrueWhenRepositoryIsPublic(c *gocheck.C) { +func (s *S) TestHasReadPermissionShouldReturnTrueWhenRepositoryIsPublic(c *check.C) { r := &repository.Repository{Name: "myotherapp", IsPublic: true} conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() conn.Repository().Insert(&r) defer conn.Repository().Remove(bson.M{"_id": r.Name}) allowed := hasReadPermission(s.user, r) - c.Assert(allowed, gocheck.Equals, true) + c.Assert(allowed, check.Equals, true) } -func (s *S) TestHasReadPermissionShouldReturnTrueWhenRepositoryIsNotPublicAndUserHasPermissionToRead(c *gocheck.C) { +func (s *S) TestHasReadPermissionShouldReturnTrueWhenRepositoryIsNotPublicAndUserHasPermissionToRead(c *check.C) { user, err := user.New("readonlyuser", map[string]string{}) - c.Check(err, gocheck.IsNil) + c.Check(err, check.IsNil) repo := &repository.Repository{ Name: "otherapp", Users: []string{s.user.Name}, ReadOnlyUsers: []string{user.Name}, } allowed := hasReadPermission(user, repo) - c.Assert(allowed, gocheck.Equals, true) + c.Assert(allowed, check.Equals, true) } -func (s *S) TestHasReadPermissionShouldReturnTrueWhenRepositoryIsNotPublicAndUserHasPermissionToReadAndWrite(c *gocheck.C) { +func (s *S) TestHasReadPermissionShouldReturnTrueWhenRepositoryIsNotPublicAndUserHasPermissionToReadAndWrite(c *check.C) { allowed := hasReadPermission(s.user, s.repo) - c.Assert(allowed, gocheck.Equals, true) + c.Assert(allowed, check.Equals, true) } -func (s *S) TestHasReadPermissionShouldReturnFalseWhenUserDoesNotHavePermissionToReadWriteAndRepoIsNotPublic(c *gocheck.C) { +func (s *S) TestHasReadPermissionShouldReturnFalseWhenUserDoesNotHavePermissionToReadWriteAndRepoIsNotPublic(c *check.C) { r := &repository.Repository{Name: "myotherapp", IsPublic: false} conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() conn.Repository().Insert(&r) defer conn.Repository().Remove(bson.M{"_id": r.Name}) allowed := hasReadPermission(s.user, r) - c.Assert(allowed, gocheck.Equals, false) + c.Assert(allowed, check.Equals, false) } -func (s *S) TestActionShouldReturnTheCommandBeingExecutedBySSH_ORIGINAL_COMMANDEnvVar(c *gocheck.C) { +func (s *S) TestActionShouldReturnTheCommandBeingExecutedBySSH_ORIGINAL_COMMANDEnvVar(c *check.C) { os.Setenv("SSH_ORIGINAL_COMMAND", "test-cmd") defer os.Setenv("SSH_ORIGINAL_COMMAND", "") cmd := action() - c.Assert(cmd, gocheck.Equals, "test-cmd") + c.Assert(cmd, check.Equals, "test-cmd") } -func (s *S) TestActionShouldReturnEmptyWhenEnvVarIsNotSet(c *gocheck.C) { +func (s *S) TestActionShouldReturnEmptyWhenEnvVarIsNotSet(c *check.C) { cmd := action() - c.Assert(cmd, gocheck.Equals, "") + c.Assert(cmd, check.Equals, "") } -func (s *S) TestRequestedRepositoryShouldGetArgumentInSSH_ORIGINAL_COMMANDAndRetrieveTheEquivalentDatabaseRepository(c *gocheck.C) { +func (s *S) TestRequestedRepositoryShouldGetArgumentInSSH_ORIGINAL_COMMANDAndRetrieveTheEquivalentDatabaseRepository(c *check.C) { r := repository.Repository{Name: "foo"} conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() err = conn.Repository().Insert(&r) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Repository().Remove(bson.M{"_id": r.Name}) os.Setenv("SSH_ORIGINAL_COMMAND", "git-receive-pack 'foo.git'") defer os.Setenv("SSH_ORIGINAL_COMMAND", "") repo, err := requestedRepository() - c.Assert(err, gocheck.IsNil) - c.Assert(repo.Name, gocheck.Equals, r.Name) + c.Assert(err, check.IsNil) + c.Assert(repo.Name, check.Equals, r.Name) } -func (s *S) TestRequestedRepositoryShouldDeduceCorrectlyRepositoryNameWithDash(c *gocheck.C) { +func (s *S) TestRequestedRepositoryShouldDeduceCorrectlyRepositoryNameWithDash(c *check.C) { r := repository.Repository{Name: "foo-bar"} conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() err = conn.Repository().Insert(&r) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Repository().Remove(bson.M{"_id": r.Name}) os.Setenv("SSH_ORIGINAL_COMMAND", "git-receive-pack 'foo-bar.git'") defer os.Setenv("SSH_ORIGINAL_COMMAND", "") repo, err := requestedRepository() - c.Assert(err, gocheck.IsNil) - c.Assert(repo.Name, gocheck.Equals, r.Name) + c.Assert(err, check.IsNil) + c.Assert(repo.Name, check.Equals, r.Name) } -func (s *S) TestRequestedRepositoryShouldReturnErrorWhenCommandDoesNotPassesWhatIsExpected(c *gocheck.C) { +func (s *S) TestRequestedRepositoryShouldReturnErrorWhenCommandDoesNotPassesWhatIsExpected(c *check.C) { os.Setenv("SSH_ORIGINAL_COMMAND", "rm -rf /") defer os.Setenv("SSH_ORIGINAL_COMMAND", "") _, err := requestedRepository() - c.Assert(err, gocheck.ErrorMatches, "^You've tried to execute some weird command, I'm deliberately denying you to do that, get over it.$") + c.Assert(err, check.ErrorMatches, "^You've tried to execute some weird command, I'm deliberately denying you to do that, get over it.$") } -func (s *S) TestRequestedRepositoryShouldReturnErrorWhenThereIsNoCommandPassedToSSH_ORIGINAL_COMMAND(c *gocheck.C) { +func (s *S) TestRequestedRepositoryShouldReturnErrorWhenThereIsNoCommandPassedToSSH_ORIGINAL_COMMAND(c *check.C) { _, err := requestedRepository() - c.Assert(err, gocheck.ErrorMatches, "^You've tried to execute some weird command, I'm deliberately denying you to do that, get over it.$") + c.Assert(err, check.ErrorMatches, "^You've tried to execute some weird command, I'm deliberately denying you to do that, get over it.$") } -func (s *S) TestRequestedRepositoryShouldReturnFormatedErrorWhenRepositoryDoesNotExist(c *gocheck.C) { +func (s *S) TestRequestedRepositoryShouldReturnFormatedErrorWhenRepositoryDoesNotExist(c *check.C) { os.Setenv("SSH_ORIGINAL_COMMAND", "git-receive-pack 'inexistent-repo.git'") defer os.Setenv("SSH_ORIGINAL_COMMAND", "") _, err := requestedRepository() - c.Assert(err, gocheck.ErrorMatches, "^Repository not found$") + c.Assert(err, check.ErrorMatches, "^Repository not found$") } -func (s *S) TestRequestedRepositoryShouldReturnEmptyRepositoryStructOnError(c *gocheck.C) { +func (s *S) TestRequestedRepositoryShouldReturnEmptyRepositoryStructOnError(c *check.C) { repo, err := requestedRepository() - c.Assert(err, gocheck.NotNil) - c.Assert(repo.Name, gocheck.Equals, "") + c.Assert(err, check.NotNil) + c.Assert(repo.Name, check.Equals, "") } -func (s *S) TestParseGitCommand(c *gocheck.C) { +func (s *S) TestParseGitCommand(c *check.C) { os.Setenv("SSH_ORIGINAL_COMMAND", "git-receive-pack 'foobar.git'") defer os.Setenv("SSH_ORIGINAL_COMMAND", "") _, name, err := parseGitCommand() - c.Assert(err, gocheck.IsNil) - c.Assert(name, gocheck.Equals, "foobar") + c.Assert(err, check.IsNil) + c.Assert(name, check.Equals, "foobar") } -func (s *S) TestParseGitCommandWithSlash(c *gocheck.C) { +func (s *S) TestParseGitCommandWithSlash(c *check.C) { os.Setenv("SSH_ORIGINAL_COMMAND", "git-receive-pack '/foobar.git'") defer os.Setenv("SSH_ORIGINAL_COMMAND", "") _, name, err := parseGitCommand() - c.Assert(err, gocheck.IsNil) - c.Assert(name, gocheck.Equals, "foobar") + c.Assert(err, check.IsNil) + c.Assert(name, check.Equals, "foobar") } -func (s *S) TestParseGitCommandShouldReturnErrorWhenTheresNoMatch(c *gocheck.C) { +func (s *S) TestParseGitCommandShouldReturnErrorWhenTheresNoMatch(c *check.C) { defer os.Setenv("SSH_ORIGINAL_COMMAND", "") os.Setenv("SSH_ORIGINAL_COMMAND", "git-receive-pack foobar") _, name, err := parseGitCommand() - c.Assert(err, gocheck.ErrorMatches, "You've tried to execute some weird command, I'm deliberately denying you to do that, get over it.") - c.Assert(name, gocheck.Equals, "") + c.Assert(err, check.ErrorMatches, "You've tried to execute some weird command, I'm deliberately denying you to do that, get over it.") + c.Assert(name, check.Equals, "") os.Setenv("SSH_ORIGINAL_COMMAND", "git-receive-pack ../foobar") _, name, err = parseGitCommand() - c.Assert(err, gocheck.ErrorMatches, "You've tried to execute some weird command, I'm deliberately denying you to do that, get over it.") - c.Assert(name, gocheck.Equals, "") + c.Assert(err, check.ErrorMatches, "You've tried to execute some weird command, I'm deliberately denying you to do that, get over it.") + c.Assert(name, check.Equals, "") os.Setenv("SSH_ORIGINAL_COMMAND", "git-receive-pack /etc") _, name, err = parseGitCommand() - c.Assert(err, gocheck.ErrorMatches, "You've tried to execute some weird command, I'm deliberately denying you to do that, get over it.") - c.Assert(name, gocheck.Equals, "") + c.Assert(err, check.ErrorMatches, "You've tried to execute some weird command, I'm deliberately denying you to do that, get over it.") + c.Assert(name, check.Equals, "") } -func (s *S) TestParseGitCommandReturnsErrorWhenSSH_ORIGINAL_COMMANDIsNotAGitCommand(c *gocheck.C) { +func (s *S) TestParseGitCommandReturnsErrorWhenSSH_ORIGINAL_COMMANDIsNotAGitCommand(c *check.C) { os.Setenv("SSH_ORIGINAL_COMMAND", "rm -rf /") defer os.Setenv("SSH_ORIGINAL_COMMAND", "") _, _, err := parseGitCommand() - c.Assert(err, gocheck.ErrorMatches, "^You've tried to execute some weird command, I'm deliberately denying you to do that, get over it.$") + c.Assert(err, check.ErrorMatches, "^You've tried to execute some weird command, I'm deliberately denying you to do that, get over it.$") } -func (s *S) TestParseGitCommandDoNotReturnsErrorWhenSSH_ORIGINAL_COMMANDIsAValidGitCommand(c *gocheck.C) { +func (s *S) TestParseGitCommandDoNotReturnsErrorWhenSSH_ORIGINAL_COMMANDIsAValidGitCommand(c *check.C) { os.Setenv("SSH_ORIGINAL_COMMAND", "git-receive-pack 'my-repo.git'") defer os.Setenv("SSH_ORIGINAL_COMMAND", "") _, _, err := parseGitCommand() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) } -func (s *S) TestParseGitCommandDoNotReturnsErrorWhenSSH_ORIGINAL_COMMANDIsAValidGitCommandWithDashInName(c *gocheck.C) { +func (s *S) TestParseGitCommandDoNotReturnsErrorWhenSSH_ORIGINAL_COMMANDIsAValidGitCommandWithDashInName(c *check.C) { os.Setenv("SSH_ORIGINAL_COMMAND", "git-receive-pack '/my-repo.git'") defer os.Setenv("SSH_ORIGINAL_COMMAND", "") _, _, err := parseGitCommand() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) } -func (s *S) TestExecuteActionShouldExecuteGitReceivePackWhenUserHasWritePermission(c *gocheck.C) { +func (s *S) TestExecuteActionShouldExecuteGitReceivePackWhenUserHasWritePermission(c *check.C) { dir, err := commandmocker.Add("git-receive-pack", "$*") - c.Check(err, gocheck.IsNil) + c.Check(err, check.IsNil) defer commandmocker.Remove(dir) os.Args = []string{"gandalf", s.user.Name} os.Setenv("SSH_ORIGINAL_COMMAND", "git-receive-pack 'myapp.git'") @@ -241,16 +241,16 @@ func (s *S) TestExecuteActionShouldExecuteGitReceivePackWhenUserHasWritePermissi }() stdout := &bytes.Buffer{} executeAction(hasWritePermission, "You don't have access to write in this repository.", stdout) - c.Assert(commandmocker.Ran(dir), gocheck.Equals, true) + c.Assert(commandmocker.Ran(dir), check.Equals, true) p, err := config.GetString("git:bare:location") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) expected := path.Join(p, "myapp.git") - c.Assert(stdout.String(), gocheck.Equals, expected) + c.Assert(stdout.String(), check.Equals, expected) } -func (s *S) TestExecuteActionShouldNotCallSSH_ORIGINAL_COMMANDWhenUserDoesNotExist(c *gocheck.C) { +func (s *S) TestExecuteActionShouldNotCallSSH_ORIGINAL_COMMANDWhenUserDoesNotExist(c *check.C) { dir, err := commandmocker.Add("git-receive-pack", "$*") - c.Check(err, gocheck.IsNil) + c.Check(err, check.IsNil) defer commandmocker.Remove(dir) os.Args = []string{"gandalf", "god"} os.Setenv("SSH_ORIGINAL_COMMAND", "git-receive-pack 'myapp.git'") @@ -261,12 +261,12 @@ func (s *S) TestExecuteActionShouldNotCallSSH_ORIGINAL_COMMANDWhenUserDoesNotExi stdout := new(bytes.Buffer) errorMsg := "You don't have access to write in this repository." executeAction(hasWritePermission, errorMsg, stdout) - c.Assert(commandmocker.Ran(dir), gocheck.Equals, false) + c.Assert(commandmocker.Ran(dir), check.Equals, false) } -func (s *S) TestExecuteActionShouldNotCallSSH_ORIGINAL_COMMANDWhenRepositoryDoesNotExist(c *gocheck.C) { +func (s *S) TestExecuteActionShouldNotCallSSH_ORIGINAL_COMMANDWhenRepositoryDoesNotExist(c *check.C) { dir, err := commandmocker.Add("git-receive-pack", "$*") - c.Check(err, gocheck.IsNil) + c.Check(err, check.IsNil) defer commandmocker.Remove(dir) os.Args = []string{"gandalf", s.user.Name} os.Setenv("SSH_ORIGINAL_COMMAND", "git-receive-pack 'ghostapp.git'") @@ -277,38 +277,38 @@ func (s *S) TestExecuteActionShouldNotCallSSH_ORIGINAL_COMMANDWhenRepositoryDoes stdout := &bytes.Buffer{} errorMsg := "You don't have access to write in this repository." executeAction(hasWritePermission, errorMsg, stdout) - c.Assert(commandmocker.Ran(dir), gocheck.Equals, false) + c.Assert(commandmocker.Ran(dir), check.Equals, false) } -func (s *S) TestFormatCommandShouldReceiveAGitCommandAndCanonizalizeTheRepositoryPath(c *gocheck.C) { +func (s *S) TestFormatCommandShouldReceiveAGitCommandAndCanonizalizeTheRepositoryPath(c *check.C) { os.Setenv("SSH_ORIGINAL_COMMAND", "git-receive-pack 'myproject.git'") defer os.Setenv("SSH_ORIGINAL_COMMAND", "") cmd, err := formatCommand() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) p, err := config.GetString("git:bare:location") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) expected := path.Join(p, "myproject.git") - c.Assert(cmd, gocheck.DeepEquals, []string{"git-receive-pack", expected}) + c.Assert(cmd, check.DeepEquals, []string{"git-receive-pack", expected}) } -func (s *S) TestFormatCommandShouldReceiveAGitCommandAndCanonizalizeTheRepositoryPathWithNamespace(c *gocheck.C) { +func (s *S) TestFormatCommandShouldReceiveAGitCommandAndCanonizalizeTheRepositoryPathWithNamespace(c *check.C) { os.Setenv("SSH_ORIGINAL_COMMAND", "git-receive-pack 'me/myproject.git'") defer os.Setenv("SSH_ORIGINAL_COMMAND", "") cmd, err := formatCommand() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) p, err := config.GetString("git:bare:location") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) expected := path.Join(p, "me/myproject.git") - c.Assert(cmd, gocheck.DeepEquals, []string{"git-receive-pack", expected}) + c.Assert(cmd, check.DeepEquals, []string{"git-receive-pack", expected}) } -func (s *S) TestFormatCommandShouldReceiveAGitCommandProjectWithDash(c *gocheck.C) { +func (s *S) TestFormatCommandShouldReceiveAGitCommandProjectWithDash(c *check.C) { os.Setenv("SSH_ORIGINAL_COMMAND", "git-receive-pack '/myproject.git'") defer os.Setenv("SSH_ORIGINAL_COMMAND", "") cmd, err := formatCommand() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) p, err := config.GetString("git:bare:location") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) expected := path.Join(p, "myproject.git") - c.Assert(cmd, gocheck.DeepEquals, []string{"git-receive-pack", expected}) + c.Assert(cmd, check.DeepEquals, []string{"git-receive-pack", expected}) } diff --git a/db/conn_test.go b/db/conn_test.go index 08ca7f4..dd62f63 100644 --- a/db/conn_test.go +++ b/db/conn_test.go @@ -1,4 +1,4 @@ -// Copyright 2014 gandalf authors. All rights reserved. +// Copyright 2015 gandalf authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -8,76 +8,76 @@ import ( "testing" "github.com/tsuru/config" - "launchpad.net/gocheck" + "gopkg.in/check.v1" ) -func Test(t *testing.T) { gocheck.TestingT(t) } +func Test(t *testing.T) { check.TestingT(t) } type S struct{} -var _ = gocheck.Suite(&S{}) +var _ = check.Suite(&S{}) -func (s *S) SetUpSuite(c *gocheck.C) { +func (s *S) SetUpSuite(c *check.C) { config.Set("database:url", "127.0.0.1:27017") config.Set("database:name", "gandalf_tests") } -func (s *S) TearDownSuite(c *gocheck.C) { +func (s *S) TearDownSuite(c *check.C) { conn, err := Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() conn.User().Database.DropDatabase() } -func (s *S) TestSessionRepositoryShouldReturnAMongoCollection(c *gocheck.C) { +func (s *S) TestSessionRepositoryShouldReturnAMongoCollection(c *check.C) { conn, err := Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() rep := conn.Repository() cRep := conn.Collection("repository") - c.Assert(rep, gocheck.DeepEquals, cRep) + c.Assert(rep, check.DeepEquals, cRep) } -func (s *S) TestSessionUserShouldReturnAMongoCollection(c *gocheck.C) { +func (s *S) TestSessionUserShouldReturnAMongoCollection(c *check.C) { conn, err := Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() usr := conn.User() cUsr := conn.Collection("user") - c.Assert(usr, gocheck.DeepEquals, cUsr) + c.Assert(usr, check.DeepEquals, cUsr) } -func (s *S) TestSessionKeyShouldReturnKeyCollection(c *gocheck.C) { +func (s *S) TestSessionKeyShouldReturnKeyCollection(c *check.C) { conn, err := Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() key := conn.Key() cKey := conn.Collection("key") - c.Assert(key, gocheck.DeepEquals, cKey) + c.Assert(key, check.DeepEquals, cKey) } -func (s *S) TestSessionKeyBodyIsUnique(c *gocheck.C) { +func (s *S) TestSessionKeyBodyIsUnique(c *check.C) { conn, err := Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() key := conn.Key() indexes, err := key.Indexes() - c.Assert(err, gocheck.IsNil) - c.Assert(indexes, gocheck.HasLen, 2) - c.Assert(indexes[1].Key, gocheck.DeepEquals, []string{"body"}) - c.Assert(indexes[1].Unique, gocheck.DeepEquals, true) + c.Assert(err, check.IsNil) + c.Assert(indexes, check.HasLen, 2) + c.Assert(indexes[1].Key, check.DeepEquals, []string{"body"}) + c.Assert(indexes[1].Unique, check.DeepEquals, true) } -func (s *S) TestConnect(c *gocheck.C) { +func (s *S) TestConnect(c *check.C) { conn, err := Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() - c.Assert(conn.User().Database.Name, gocheck.Equals, "gandalf_tests") + c.Assert(conn.User().Database.Name, check.Equals, "gandalf_tests") err = conn.User().Database.Session.Ping() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) } -func (s *S) TestConnectDefaultSettings(c *gocheck.C) { +func (s *S) TestConnectDefaultSettings(c *check.C) { oldURL, _ := config.Get("database:url") defer config.Set("database:url", oldURL) oldName, _ := config.Get("database:name") @@ -85,8 +85,8 @@ func (s *S) TestConnectDefaultSettings(c *gocheck.C) { config.Unset("database:url") config.Unset("database:name") conn, err := Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() - c.Assert(conn.User().Database.Name, gocheck.Equals, "gandalf") - c.Assert(conn.User().Database.Session.LiveServers(), gocheck.DeepEquals, []string{"127.0.0.1:27017"}) + c.Assert(conn.User().Database.Name, check.Equals, "gandalf") + c.Assert(conn.User().Database.Session.LiveServers(), check.DeepEquals, []string{"127.0.0.1:27017"}) } diff --git a/fs/filesystem_test.go b/fs/filesystem_test.go index 04e3e59..97b0744 100644 --- a/fs/filesystem_test.go +++ b/fs/filesystem_test.go @@ -1,4 +1,4 @@ -// Copyright 2014 gandalf authors. All rights reserved. +// Copyright 2015 gandalf authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -8,18 +8,18 @@ import ( "testing" tsurufs "github.com/tsuru/tsuru/fs" - "launchpad.net/gocheck" + "gopkg.in/check.v1" ) -func Test(t *testing.T) { gocheck.TestingT(t) } +func Test(t *testing.T) { check.TestingT(t) } type S struct{} -var _ = gocheck.Suite(&S{}) +var _ = check.Suite(&S{}) -func (s *S) TestFsystemShouldSetGlobalFsystemWhenItsNil(c *gocheck.C) { +func (s *S) TestFsystemShouldSetGlobalFsystemWhenItsNil(c *check.C) { Fsystem = nil fsys := Filesystem() _, ok := fsys.(tsurufs.Fs) - c.Assert(ok, gocheck.Equals, true) + c.Assert(ok, check.Equals, true) } diff --git a/gandalftest/server_test.go b/gandalftest/server_test.go index ea2136c..b663bcb 100644 --- a/gandalftest/server_test.go +++ b/gandalftest/server_test.go @@ -8,55 +8,55 @@ import ( "net" "testing" - "launchpad.net/gocheck" + "gopkg.in/check.v1" ) -func Test(t *testing.T) { gocheck.TestingT(t) } +func Test(t *testing.T) { check.TestingT(t) } type S struct{} -var _ = gocheck.Suite(&S{}) +var _ = check.Suite(&S{}) -func (s *S) TestNewServerFreePort(c *gocheck.C) { +func (s *S) TestNewServerFreePort(c *check.C) { server, err := NewServer("127.0.0.1:0") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer server.Stop() conn, err := net.Dial("tcp", server.listener.Addr().String()) - c.Assert(err, gocheck.IsNil) - c.Assert(conn.Close(), gocheck.IsNil) + c.Assert(err, check.IsNil) + c.Assert(conn.Close(), check.IsNil) } -func (s *S) TestNewServerSpecificPort(c *gocheck.C) { +func (s *S) TestNewServerSpecificPort(c *check.C) { server, err := NewServer("127.0.0.1:8599") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer server.Stop() conn, err := net.Dial("tcp", server.listener.Addr().String()) - c.Assert(err, gocheck.IsNil) - c.Assert(conn.Close(), gocheck.IsNil) + c.Assert(err, check.IsNil) + c.Assert(conn.Close(), check.IsNil) } -func (s *S) TestNewServerListenError(c *gocheck.C) { +func (s *S) TestNewServerListenError(c *check.C) { listen, err := net.Listen("tcp", "127.0.0.1:0") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer listen.Close() server, err := NewServer(listen.Addr().String()) - c.Assert(err, gocheck.ErrorMatches, `^.*bind: address already in use$`) - c.Assert(server, gocheck.IsNil) + c.Assert(err, check.ErrorMatches, `^.*bind: address already in use$`) + c.Assert(server, check.IsNil) } -func (s *S) TestServerStop(c *gocheck.C) { +func (s *S) TestServerStop(c *check.C) { server, err := NewServer("127.0.0.1:0") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = server.Stop() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) _, err = net.Dial("tcp", server.listener.Addr().String()) - c.Assert(err, gocheck.ErrorMatches, `^.*connection refused$`) + c.Assert(err, check.ErrorMatches, `^.*connection refused$`) } -func (s *S) TestURL(c *gocheck.C) { +func (s *S) TestURL(c *check.C) { server, err := NewServer("127.0.0.1:0") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer server.Stop() expected := "http://" + server.listener.Addr().String() + "/" - c.Assert(server.URL(), gocheck.Equals, expected) + c.Assert(server.URL(), check.Equals, expected) } diff --git a/hook/hook_test.go b/hook/hook_test.go index 852f2e9..3c21deb 100644 --- a/hook/hook_test.go +++ b/hook/hook_test.go @@ -14,91 +14,91 @@ import ( "github.com/tsuru/gandalf/db" "github.com/tsuru/gandalf/fs" "github.com/tsuru/tsuru/fs/fstest" - "launchpad.net/gocheck" + "gopkg.in/check.v1" ) -func Test(t *testing.T) { gocheck.TestingT(t) } +func Test(t *testing.T) { check.TestingT(t) } type S struct { tmpdir string rfs *fstest.RecordingFs } -var _ = gocheck.Suite(&S{}) +var _ = check.Suite(&S{}) -func (s *S) SetUpSuite(c *gocheck.C) { +func (s *S) SetUpSuite(c *check.C) { err := config.ReadConfigFile("../etc/gandalf.conf") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) config.Set("database:url", "127.0.0.1:27017") config.Set("database:name", "gandalf_api_tests") s.tmpdir, err = commandmocker.Add("git", "") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) } -func (s *S) SetUpTest(c *gocheck.C) { +func (s *S) SetUpTest(c *check.C) { s.rfs = &fstest.RecordingFs{} fs.Fsystem = s.rfs bareTemplate, _ := config.GetString("git:bare:template") fs.Fsystem.MkdirAll(bareTemplate+"/hooks", 0755) } -func (s *S) TearDownTest(c *gocheck.C) { +func (s *S) TearDownTest(c *check.C) { fs.Fsystem = nil } -func (s *S) TearDownSuite(c *gocheck.C) { +func (s *S) TearDownSuite(c *check.C) { commandmocker.Remove(s.tmpdir) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() conn.User().Database.DropDatabase() } -func (s *S) TestCanCreateHookFile(c *gocheck.C) { +func (s *S) TestCanCreateHookFile(c *check.C) { hookContent := []byte("some content") err := createHookFile("/tmp/repositories/some-repo.git/hooks/test-can-create-hook-file", hookContent) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) file, err := fs.Filesystem().OpenFile("/tmp/repositories/some-repo.git/hooks/test-can-create-hook-file", os.O_RDONLY, 0755) defer file.Close() content, err := ioutil.ReadAll(file) - c.Assert(err, gocheck.IsNil) - c.Assert(string(content), gocheck.Equals, "some content") + c.Assert(err, check.IsNil) + c.Assert(string(content), check.Equals, "some content") } -func (s *S) TestCanAddNewHook(c *gocheck.C) { +func (s *S) TestCanAddNewHook(c *check.C) { hookContent := []byte("some content") err := Add("test-can-add-new-hook", []string{}, hookContent) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) file, err := fs.Filesystem().OpenFile("/home/git/bare-template/hooks/test-can-add-new-hook", os.O_RDONLY, 0755) defer file.Close() content, err := ioutil.ReadAll(file) - c.Assert(err, gocheck.IsNil) - c.Assert(string(content), gocheck.Equals, "some content") + c.Assert(err, check.IsNil) + c.Assert(string(content), check.Equals, "some content") } -func (s *S) TestCanAddNewHookInOldRepository(c *gocheck.C) { +func (s *S) TestCanAddNewHookInOldRepository(c *check.C) { s.rfs = &fstest.RecordingFs{} fs.Fsystem = s.rfs bareTemplate, _ := config.GetString("git:bare:template") err := fs.Fsystem.RemoveAll(bareTemplate + "/hooks") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) hookContent := []byte("some content") err = Add("test-can-add-new-hook", []string{}, hookContent) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) file, err := fs.Filesystem().OpenFile("/home/git/bare-template/hooks/test-can-add-new-hook", os.O_RDONLY, 0755) defer file.Close() content, err := ioutil.ReadAll(file) - c.Assert(err, gocheck.IsNil) - c.Assert(string(content), gocheck.Equals, "some content") + c.Assert(err, check.IsNil) + c.Assert(string(content), check.Equals, "some content") } -func (s *S) TestCanAddNewRepository(c *gocheck.C) { +func (s *S) TestCanAddNewRepository(c *check.C) { hookContent := []byte("some content") err := Add("test-can-add-new-repository-hook", []string{"some-repo"}, hookContent) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) file, err := fs.Filesystem().OpenFile("/tmp/repositories/some-repo.git/hooks/test-can-add-new-repository-hook", os.O_RDONLY, 0755) defer file.Close() content, err := ioutil.ReadAll(file) - c.Assert(err, gocheck.IsNil) - c.Assert(string(content), gocheck.Equals, "some content") + c.Assert(err, check.IsNil) + c.Assert(string(content), check.Equals, "some content") } diff --git a/multipartzip/multipartzip_test.go b/multipartzip/multipartzip_test.go index a417471..d142a8a 100644 --- a/multipartzip/multipartzip_test.go +++ b/multipartzip/multipartzip_test.go @@ -1,4 +1,4 @@ -// Copyright 2014 gandalf authors. All rights reserved. +// Copyright 2015 gandalf authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -14,23 +14,23 @@ import ( "path" "testing" - "launchpad.net/gocheck" + "gopkg.in/check.v1" ) -func Test(t *testing.T) { gocheck.TestingT(t) } +func Test(t *testing.T) { check.TestingT(t) } type S struct { tmpdir string } -var _ = gocheck.Suite(&S{}) +var _ = check.Suite(&S{}) -func (s *S) TestCopyZipFile(c *gocheck.C) { +func (s *S) TestCopyZipFile(c *check.C) { tempDir, err := ioutil.TempDir("", "TestCopyZipFileDir") defer func() { os.RemoveAll(tempDir) }() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) var files = []File{ {"doge.txt", "Much doge"}, {"much.txt", "Much mucho"}, @@ -40,19 +40,19 @@ func (s *S) TestCopyZipFile(c *gocheck.C) { {"/usr/WOW/WOW.WOW4", "WOW\nWOW"}, } buf, err := CreateZipBuffer(files) - c.Assert(err, gocheck.IsNil) - c.Assert(buf, gocheck.NotNil) + c.Assert(err, check.IsNil) + c.Assert(buf, check.NotNil) r, err := zip.NewReader(bytes.NewReader(buf.Bytes()), int64(buf.Len())) for _, f := range r.File { err = CopyZipFile(f, tempDir, f.Name) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) fstat, errStat := os.Stat(path.Join(tempDir, f.Name)) - c.Assert(errStat, gocheck.IsNil) - c.Assert(fstat.IsDir(), gocheck.Equals, false) + c.Assert(errStat, check.IsNil) + c.Assert(fstat.IsDir(), check.Equals, false) } } -func (s *S) TestExtractZip(c *gocheck.C) { +func (s *S) TestExtractZip(c *check.C) { boundary := "muchBOUNDARY" params := map[string]string{} var files = []File{ @@ -64,27 +64,27 @@ func (s *S) TestExtractZip(c *gocheck.C) { {"/usr/WOW/WOW.WOW4", "WOW\nWOW"}, } buf, err := CreateZipBuffer(files) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) reader, writer := io.Pipe() go StreamWriteMultipartForm(params, "zipfile", "scaffold.zip", boundary, writer, buf) mpr := multipart.NewReader(reader, boundary) form, err := mpr.ReadForm(0) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) formfile := form.File["zipfile"][0] tempDir, err := ioutil.TempDir("", "TestCopyZipFileDir") defer func() { os.RemoveAll(tempDir) }() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) ExtractZip(formfile, tempDir) for _, file := range files { body, err := ioutil.ReadFile(path.Join(tempDir, file.Name)) - c.Assert(err, gocheck.IsNil) - c.Assert(string(body), gocheck.Equals, file.Body) + c.Assert(err, check.IsNil) + c.Assert(string(body), check.Equals, file.Body) } } -func (s *S) TestValueField(c *gocheck.C) { +func (s *S) TestValueField(c *check.C) { boundary := "muchBOUNDARY" params := map[string]string{ "committername": "Barking Doge", @@ -98,26 +98,26 @@ func (s *S) TestValueField(c *gocheck.C) { go StreamWriteMultipartForm(params, "", "", boundary, writer, nil) mpr := multipart.NewReader(reader, boundary) form, err := mpr.ReadForm(0) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) value, err := ValueField(form, "branch") - c.Assert(err, gocheck.IsNil) - c.Assert(value, gocheck.Equals, "master") + c.Assert(err, check.IsNil) + c.Assert(value, check.Equals, "master") } -func (s *S) TestValueFieldWhenFieldInvalid(c *gocheck.C) { +func (s *S) TestValueFieldWhenFieldInvalid(c *check.C) { boundary := "muchBOUNDARY" params := map[string]string{} reader, writer := io.Pipe() go StreamWriteMultipartForm(params, "", "", boundary, writer, nil) mpr := multipart.NewReader(reader, boundary) form, err := mpr.ReadForm(0) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) _, err = ValueField(form, "dleif_dilavni") - c.Assert(err, gocheck.NotNil) - c.Assert(err.Error(), gocheck.Equals, "Invalid value field \"dleif_dilavni\"") + c.Assert(err, check.NotNil) + c.Assert(err.Error(), check.Equals, "Invalid value field \"dleif_dilavni\"") } -func (s *S) TestValueFieldWhenFieldEmpty(c *gocheck.C) { +func (s *S) TestValueFieldWhenFieldEmpty(c *check.C) { boundary := "muchBOUNDARY" params := map[string]string{ "branch": "", @@ -126,13 +126,13 @@ func (s *S) TestValueFieldWhenFieldEmpty(c *gocheck.C) { go StreamWriteMultipartForm(params, "", "", boundary, writer, nil) mpr := multipart.NewReader(reader, boundary) form, err := mpr.ReadForm(0) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) _, err = ValueField(form, "branch") - c.Assert(err, gocheck.NotNil) - c.Assert(err.Error(), gocheck.Equals, "Empty value \"branch\"") + c.Assert(err, check.NotNil) + c.Assert(err.Error(), check.Equals, "Empty value \"branch\"") } -func (s *S) TestFileField(c *gocheck.C) { +func (s *S) TestFileField(c *check.C) { boundary := "muchBOUNDARY" params := map[string]string{} var files = []File{ @@ -144,18 +144,18 @@ func (s *S) TestFileField(c *gocheck.C) { {"/usr/WOW/WOW.WOW4", "WOW\nWOW"}, } buf, err := CreateZipBuffer(files) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) reader, writer := io.Pipe() go StreamWriteMultipartForm(params, "muchfile", "muchfile.zip", boundary, writer, buf) mpr := multipart.NewReader(reader, boundary) form, err := mpr.ReadForm(0) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) file, err := FileField(form, "muchfile") - c.Assert(err, gocheck.IsNil) - c.Assert(file.Filename, gocheck.Equals, "muchfile.zip") + c.Assert(err, check.IsNil) + c.Assert(file.Filename, check.Equals, "muchfile.zip") } -func (s *S) TestFileFieldWhenFieldInvalid(c *gocheck.C) { +func (s *S) TestFileFieldWhenFieldInvalid(c *check.C) { boundary := "muchBOUNDARY" params := map[string]string{ "dleif_dilavni": "dleif_dilavni", @@ -164,26 +164,26 @@ func (s *S) TestFileFieldWhenFieldInvalid(c *gocheck.C) { go StreamWriteMultipartForm(params, "", "", boundary, writer, nil) mpr := multipart.NewReader(reader, boundary) form, err := mpr.ReadForm(0) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) _, err = FileField(form, "dleif_dilavni") - c.Assert(err, gocheck.NotNil) - c.Assert(err.Error(), gocheck.Equals, "Invalid file field \"dleif_dilavni\"") + c.Assert(err, check.NotNil) + c.Assert(err.Error(), check.Equals, "Invalid file field \"dleif_dilavni\"") } -func (s *S) TestFileFieldWhenFieldEmpty(c *gocheck.C) { +func (s *S) TestFileFieldWhenFieldEmpty(c *check.C) { boundary := "muchBOUNDARY" params := map[string]string{} reader, writer := io.Pipe() go StreamWriteMultipartForm(params, "muchfile", "muchfile.zip", boundary, writer, nil) mpr := multipart.NewReader(reader, boundary) form, err := mpr.ReadForm(0) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) file, err := FileField(form, "muchfile") - c.Assert(err, gocheck.IsNil) - c.Assert(file.Filename, gocheck.Equals, "muchfile.zip") + c.Assert(err, check.IsNil) + c.Assert(file.Filename, check.Equals, "muchfile.zip") fp, err := file.Open() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) fs, err := fp.Seek(0, 2) - c.Assert(err, gocheck.IsNil) - c.Assert(fs, gocheck.Equals, int64(0)) + c.Assert(err, check.IsNil) + c.Assert(fs, check.Equals, int64(0)) } diff --git a/repository/git_test.go b/repository/git_test.go index 56e380c..94ba331 100644 --- a/repository/git_test.go +++ b/repository/git_test.go @@ -12,87 +12,87 @@ import ( "github.com/tsuru/config" "github.com/tsuru/gandalf/fs" "github.com/tsuru/tsuru/fs/fstest" - "launchpad.net/gocheck" + "gopkg.in/check.v1" ) -func (s *S) TestBareLocationValuShouldComeFromGandalfConf(c *gocheck.C) { +func (s *S) TestBareLocationValuShouldComeFromGandalfConf(c *check.C) { bare = "" config.Set("git:bare:location", "/home/gandalf") l := bareLocation() - c.Assert(l, gocheck.Equals, "/home/gandalf") + c.Assert(l, check.Equals, "/home/gandalf") } -func (s *S) TestBareLocationShouldResetBareValue(c *gocheck.C) { +func (s *S) TestBareLocationShouldResetBareValue(c *check.C) { l := bareLocation() config.Set("git:bare:location", "fooo/baaar") - c.Assert(bareLocation(), gocheck.Equals, l) + c.Assert(bareLocation(), check.Equals, l) } -func (s *S) TestNewBareShouldCreateADir(c *gocheck.C) { +func (s *S) TestNewBareShouldCreateADir(c *check.C) { dir, err := commandmocker.Add("git", "$*") - c.Check(err, gocheck.IsNil) + c.Check(err, check.IsNil) defer commandmocker.Remove(dir) err = newBare("myBare") - c.Assert(err, gocheck.IsNil) - c.Assert(commandmocker.Ran(dir), gocheck.Equals, true) + c.Assert(err, check.IsNil) + c.Assert(commandmocker.Ran(dir), check.Equals, true) } -func (s *S) TestNewBareShouldReturnMeaningfullErrorWhenBareCreationFails(c *gocheck.C) { +func (s *S) TestNewBareShouldReturnMeaningfullErrorWhenBareCreationFails(c *check.C) { dir, err := commandmocker.Error("git", "cmd output", 1) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(dir) err = newBare("foo") - c.Check(err, gocheck.NotNil) + c.Check(err, check.NotNil) got := err.Error() expected := "Could not create git bare repository: exit status 1. cmd output" - c.Assert(got, gocheck.Equals, expected) + c.Assert(got, check.Equals, expected) } -func (s *S) TestNewBareShouldPassTemplateOptionWhenItExistsOnConfig(c *gocheck.C) { +func (s *S) TestNewBareShouldPassTemplateOptionWhenItExistsOnConfig(c *check.C) { bareTemplate := "/var/templates" bareLocation, err := config.GetString("git:bare:location") config.Set("git:bare:template", bareTemplate) defer config.Unset("git:bare:template") barePath := path.Join(bareLocation, "foo.git") dir, err := commandmocker.Add("git", "$*") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(dir) err = newBare("foo") - c.Assert(err, gocheck.IsNil) - c.Assert(commandmocker.Ran(dir), gocheck.Equals, true) + c.Assert(err, check.IsNil) + c.Assert(commandmocker.Ran(dir), check.Equals, true) expected := fmt.Sprintf("init %s --bare --template=%s", barePath, bareTemplate) - c.Assert(commandmocker.Output(dir), gocheck.Equals, expected) + c.Assert(commandmocker.Output(dir), check.Equals, expected) } -func (s *S) TestNewBareShouldNotPassTemplateOptionWhenItsNotSetInConfig(c *gocheck.C) { +func (s *S) TestNewBareShouldNotPassTemplateOptionWhenItsNotSetInConfig(c *check.C) { config.Unset("git:bare:template") bareLocation, err := config.GetString("git:bare:location") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) barePath := path.Join(bareLocation, "foo.git") dir, err := commandmocker.Add("git", "$*") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(dir) err = newBare("foo") - c.Assert(err, gocheck.IsNil) - c.Assert(commandmocker.Ran(dir), gocheck.Equals, true) + c.Assert(err, check.IsNil) + c.Assert(commandmocker.Ran(dir), check.Equals, true) expected := fmt.Sprintf("init %s --bare", barePath) - c.Assert(commandmocker.Output(dir), gocheck.Equals, expected) + c.Assert(commandmocker.Output(dir), check.Equals, expected) } -func (s *S) TestRemoveBareShouldRemoveBareDirFromFileSystem(c *gocheck.C) { +func (s *S) TestRemoveBareShouldRemoveBareDirFromFileSystem(c *check.C) { rfs := &fstest.RecordingFs{FileContent: "foo"} fs.Fsystem = rfs defer func() { fs.Fsystem = nil }() err := removeBare("myBare") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) action := "removeall " + path.Join(bareLocation(), "myBare.git") - c.Assert(rfs.HasAction(action), gocheck.Equals, true) + c.Assert(rfs.HasAction(action), check.Equals, true) } -func (s *S) TestRemoveBareShouldReturnDescriptiveErrorWhenRemovalFails(c *gocheck.C) { +func (s *S) TestRemoveBareShouldReturnDescriptiveErrorWhenRemovalFails(c *check.C) { rfs := &fstest.RecordingFs{FileContent: "foo"} fs.Fsystem = &fstest.FileNotFoundFs{RecordingFs: *rfs} defer func() { fs.Fsystem = nil }() err := removeBare("fooo") - c.Assert(err, gocheck.ErrorMatches, "^Could not remove git bare repository: .*") + c.Assert(err, check.ErrorMatches, "^Could not remove git bare repository: .*") } diff --git a/repository/repository_test.go b/repository/repository_test.go index d2521a0..3f7b956 100644 --- a/repository/repository_test.go +++ b/repository/repository_test.go @@ -1,4 +1,4 @@ -// Copyright 2014 gandalf authors. All rights reserved. +// Copyright 2015 gandalf authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -25,378 +25,378 @@ import ( "github.com/tsuru/gandalf/fs" "github.com/tsuru/gandalf/multipartzip" "github.com/tsuru/tsuru/fs/fstest" + "gopkg.in/check.v1" "gopkg.in/mgo.v2" "gopkg.in/mgo.v2/bson" - "launchpad.net/gocheck" ) -func Test(t *testing.T) { gocheck.TestingT(t) } +func Test(t *testing.T) { check.TestingT(t) } type S struct { tmpdir string } -var _ = gocheck.Suite(&S{}) +var _ = check.Suite(&S{}) -func (s *S) SetUpSuite(c *gocheck.C) { +func (s *S) SetUpSuite(c *check.C) { err := config.ReadConfigFile("../etc/gandalf.conf") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) config.Set("database:url", "127.0.0.1:27017") config.Set("database:name", "gandalf_repository_tests") } -func (s *S) TearDownSuite(c *gocheck.C) { +func (s *S) TearDownSuite(c *check.C) { conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() conn.User().Database.DropDatabase() } -func (s *S) TestTempDirLocationShouldComeFromGandalfConf(c *gocheck.C) { +func (s *S) TestTempDirLocationShouldComeFromGandalfConf(c *check.C) { config.Set("repository:tempDir", "/home/gandalf/temp") oldTempDir := tempDir tempDir = "" defer func() { tempDir = oldTempDir }() - c.Assert(tempDirLocation(), gocheck.Equals, "/home/gandalf/temp") + c.Assert(tempDirLocation(), check.Equals, "/home/gandalf/temp") } -func (s *S) TestTempDirLocationDontResetTempDir(c *gocheck.C) { +func (s *S) TestTempDirLocationDontResetTempDir(c *check.C) { config.Set("repository:tempDir", "/home/gandalf/temp") oldTempDir := tempDir tempDir = "/var/folders" defer func() { tempDir = oldTempDir }() - c.Assert(tempDirLocation(), gocheck.Equals, "/var/folders") + c.Assert(tempDirLocation(), check.Equals, "/var/folders") } -func (s *S) TestTempDirLocationWhenNotInGandalfConf(c *gocheck.C) { +func (s *S) TestTempDirLocationWhenNotInGandalfConf(c *check.C) { config.Unset("repository:tempDir") oldTempDir := tempDir tempDir = "" defer func() { tempDir = oldTempDir }() - c.Assert(tempDirLocation(), gocheck.Equals, "") + c.Assert(tempDirLocation(), check.Equals, "") } -func (s *S) TestNewShouldCreateANewRepository(c *gocheck.C) { +func (s *S) TestNewShouldCreateANewRepository(c *check.C) { tmpdir, err := commandmocker.Add("git", "$*") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(tmpdir) users := []string{"smeagol", "saruman"} readOnlyUsers := []string{"gollum", "curumo"} r, err := New("myRepo", users, readOnlyUsers, false) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.Repository().Remove(bson.M{"_id": "myRepo"}) - c.Assert(r.Name, gocheck.Equals, "myRepo") - c.Assert(r.Users, gocheck.DeepEquals, users) - c.Assert(r.ReadOnlyUsers, gocheck.DeepEquals, readOnlyUsers) - c.Assert(r.IsPublic, gocheck.Equals, false) + c.Assert(r.Name, check.Equals, "myRepo") + c.Assert(r.Users, check.DeepEquals, users) + c.Assert(r.ReadOnlyUsers, check.DeepEquals, readOnlyUsers) + c.Assert(r.IsPublic, check.Equals, false) } -func (s *S) TestNewIntegration(c *gocheck.C) { +func (s *S) TestNewIntegration(c *check.C) { configBare, err := config.GetString("git:bare:location") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) odlBare := bare bare, err = ioutil.TempDir("", "gandalf_repository_test") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) config.Set("git:bare:location", bare) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer func() { os.RemoveAll(bare) config.Set("git:bare:location", configBare) checkBare, err := config.GetString("git:bare:location") - c.Assert(err, gocheck.IsNil) - c.Assert(checkBare, gocheck.Equals, configBare) + c.Assert(err, check.IsNil) + c.Assert(checkBare, check.Equals, configBare) bare = odlBare }() r, err := New("the-shire", []string{"bilbo"}, []string{""}, false) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.Repository().Remove(bson.M{"_id": "the-shire"}) barePath := barePath(r.Name) - c.Assert(barePath, gocheck.Equals, path.Join(bare, "the-shire.git")) + c.Assert(barePath, check.Equals, path.Join(bare, "the-shire.git")) fstat, errStat := os.Stat(path.Join(barePath, "HEAD")) - c.Assert(errStat, gocheck.IsNil) - c.Assert(fstat.IsDir(), gocheck.Equals, false) + c.Assert(errStat, check.IsNil) + c.Assert(fstat.IsDir(), check.Equals, false) fstat, errStat = os.Stat(path.Join(barePath, "config")) - c.Assert(errStat, gocheck.IsNil) - c.Assert(fstat.IsDir(), gocheck.Equals, false) + c.Assert(errStat, check.IsNil) + c.Assert(fstat.IsDir(), check.Equals, false) fstat, errStat = os.Stat(path.Join(barePath, "objects")) - c.Assert(errStat, gocheck.IsNil) - c.Assert(fstat.IsDir(), gocheck.Equals, true) + c.Assert(errStat, check.IsNil) + c.Assert(fstat.IsDir(), check.Equals, true) fstat, errStat = os.Stat(path.Join(barePath, "refs")) - c.Assert(errStat, gocheck.IsNil) - c.Assert(fstat.IsDir(), gocheck.Equals, true) + c.Assert(errStat, check.IsNil) + c.Assert(fstat.IsDir(), check.Equals, true) } -func (s *S) TestNewIntegrationWithNamespace(c *gocheck.C) { +func (s *S) TestNewIntegrationWithNamespace(c *check.C) { configBare, err := config.GetString("git:bare:location") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) odlBare := bare bare, err = ioutil.TempDir("", "gandalf_repository_test") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) config.Set("git:bare:location", bare) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer func() { os.RemoveAll(bare) config.Set("git:bare:location", configBare) checkBare, err := config.GetString("git:bare:location") - c.Assert(err, gocheck.IsNil) - c.Assert(checkBare, gocheck.Equals, configBare) + c.Assert(err, check.IsNil) + c.Assert(checkBare, check.Equals, configBare) bare = odlBare }() r, err := New("saruman/two-towers", []string{"frodo"}, []string{""}, false) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.Repository().Remove(bson.M{"_id": "saruman/two-towers"}) barePath := barePath(r.Name) - c.Assert(barePath, gocheck.Equals, path.Join(bare, "saruman/two-towers.git")) + c.Assert(barePath, check.Equals, path.Join(bare, "saruman/two-towers.git")) fstat, errStat := os.Stat(path.Join(barePath, "HEAD")) - c.Assert(errStat, gocheck.IsNil) - c.Assert(fstat.IsDir(), gocheck.Equals, false) + c.Assert(errStat, check.IsNil) + c.Assert(fstat.IsDir(), check.Equals, false) fstat, errStat = os.Stat(path.Join(barePath, "config")) - c.Assert(errStat, gocheck.IsNil) - c.Assert(fstat.IsDir(), gocheck.Equals, false) + c.Assert(errStat, check.IsNil) + c.Assert(fstat.IsDir(), check.Equals, false) fstat, errStat = os.Stat(path.Join(barePath, "objects")) - c.Assert(errStat, gocheck.IsNil) - c.Assert(fstat.IsDir(), gocheck.Equals, true) + c.Assert(errStat, check.IsNil) + c.Assert(fstat.IsDir(), check.Equals, true) fstat, errStat = os.Stat(path.Join(barePath, "refs")) - c.Assert(errStat, gocheck.IsNil) - c.Assert(fstat.IsDir(), gocheck.Equals, true) + c.Assert(errStat, check.IsNil) + c.Assert(fstat.IsDir(), check.Equals, true) } -func (s *S) TestNewShouldRecordItOnDatabase(c *gocheck.C) { +func (s *S) TestNewShouldRecordItOnDatabase(c *check.C) { tmpdir, err := commandmocker.Add("git", "$*") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(tmpdir) r, err := New("someRepo", []string{"smeagol"}, []string{"gollum"}, false) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.Repository().Remove(bson.M{"_id": "someRepo"}) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = conn.Repository().Find(bson.M{"_id": "someRepo"}).One(&r) - c.Assert(err, gocheck.IsNil) - c.Assert(r.Name, gocheck.Equals, "someRepo") - c.Assert(r.Users, gocheck.DeepEquals, []string{"smeagol"}) - c.Assert(r.ReadOnlyUsers, gocheck.DeepEquals, []string{"gollum"}) - c.Assert(r.IsPublic, gocheck.Equals, false) + c.Assert(err, check.IsNil) + c.Assert(r.Name, check.Equals, "someRepo") + c.Assert(r.Users, check.DeepEquals, []string{"smeagol"}) + c.Assert(r.ReadOnlyUsers, check.DeepEquals, []string{"gollum"}) + c.Assert(r.IsPublic, check.Equals, false) } -func (s *S) TestNewShouldCreateNamesakeRepositories(c *gocheck.C) { +func (s *S) TestNewShouldCreateNamesakeRepositories(c *check.C) { tmpdir, err := commandmocker.Add("git", "$*") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(tmpdir) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() u1 := struct { Name string `bson:"_id"` }{Name: "melkor"} err = conn.User().Insert(&u1) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.User().RemoveId(u1.Name) u2 := struct { Name string `bson:"_id"` }{Name: "morgoth"} err = conn.User().Insert(&u2) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.User().RemoveId(u2.Name) r1, err := New("melkor/angband", []string{"nazgul"}, []string{""}, false) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Repository().Remove(bson.M{"_id": "melkor/angband"}) - c.Assert(r1.Name, gocheck.Equals, "melkor/angband") - c.Assert(r1.IsPublic, gocheck.Equals, false) + c.Assert(r1.Name, check.Equals, "melkor/angband") + c.Assert(r1.IsPublic, check.Equals, false) r2, err := New("morgoth/angband", []string{"nazgul"}, []string{""}, false) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Repository().Remove(bson.M{"_id": "morgoth/angband"}) - c.Assert(r2.Name, gocheck.Equals, "morgoth/angband") - c.Assert(r2.IsPublic, gocheck.Equals, false) + c.Assert(r2.Name, check.Equals, "morgoth/angband") + c.Assert(r2.IsPublic, check.Equals, false) } -func (s *S) TestNewPublicRepository(c *gocheck.C) { +func (s *S) TestNewPublicRepository(c *check.C) { rfs := &fstest.RecordingFs{FileContent: "foo"} fs.Fsystem = rfs defer func() { fs.Fsystem = nil }() tmpdir, err := commandmocker.Add("git", "$*") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(tmpdir) r, err := New("someRepo", []string{"smeagol"}, []string{"gollum"}, true) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.Repository().Remove(bson.M{"_id": "someRepo"}) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = conn.Repository().Find(bson.M{"_id": "someRepo"}).One(&r) - c.Assert(err, gocheck.IsNil) - c.Assert(r.Name, gocheck.Equals, "someRepo") - c.Assert(r.Users, gocheck.DeepEquals, []string{"smeagol"}) - c.Assert(r.ReadOnlyUsers, gocheck.DeepEquals, []string{"gollum"}) - c.Assert(r.IsPublic, gocheck.Equals, true) + c.Assert(err, check.IsNil) + c.Assert(r.Name, check.Equals, "someRepo") + c.Assert(r.Users, check.DeepEquals, []string{"smeagol"}) + c.Assert(r.ReadOnlyUsers, check.DeepEquals, []string{"gollum"}) + c.Assert(r.IsPublic, check.Equals, true) path := barePath("someRepo") + "/git-daemon-export-ok" - c.Assert(rfs.HasAction("create "+path), gocheck.Equals, true) + c.Assert(rfs.HasAction("create "+path), check.Equals, true) } -func (s *S) TestNewBreaksOnValidationError(c *gocheck.C) { +func (s *S) TestNewBreaksOnValidationError(c *check.C) { _, err := New("", []string{"smeagol"}, []string{""}, false) - c.Check(err, gocheck.NotNil) + c.Check(err, check.NotNil) expected := "Validation Error: repository name is not valid" got := err.Error() - c.Assert(got, gocheck.Equals, expected) + c.Assert(got, check.Equals, expected) } -func (s *S) TestRepositoryIsNotValidWithoutAName(c *gocheck.C) { +func (s *S) TestRepositoryIsNotValidWithoutAName(c *check.C) { r := Repository{Users: []string{"gollum"}, IsPublic: true} v, err := r.isValid() - c.Assert(v, gocheck.Equals, false) - c.Check(err, gocheck.NotNil) + c.Assert(v, check.Equals, false) + c.Check(err, check.NotNil) got := err.Error() expected := "Validation Error: repository name is not valid" - c.Assert(got, gocheck.Equals, expected) + c.Assert(got, check.Equals, expected) } -func (s *S) TestRepositoryIsNotValidWithInvalidName(c *gocheck.C) { +func (s *S) TestRepositoryIsNotValidWithInvalidName(c *check.C) { r := Repository{Name: "foo bar", Users: []string{"gollum"}, IsPublic: true} v, err := r.isValid() - c.Assert(v, gocheck.Equals, false) - c.Check(err, gocheck.NotNil) + c.Assert(v, check.Equals, false) + c.Check(err, check.NotNil) got := err.Error() expected := "Validation Error: repository name is not valid" - c.Assert(got, gocheck.Equals, expected) + c.Assert(got, check.Equals, expected) } -func (s *S) TestRepositoryShoudBeInvalidWIthoutAnyUsers(c *gocheck.C) { +func (s *S) TestRepositoryShoudBeInvalidWIthoutAnyUsers(c *check.C) { r := Repository{Name: "foo_bar", Users: []string{}, IsPublic: true} v, err := r.isValid() - c.Assert(v, gocheck.Equals, false) - c.Assert(err, gocheck.NotNil) + c.Assert(v, check.Equals, false) + c.Assert(err, check.NotNil) got := err.Error() expected := "Validation Error: repository should have at least one user" - c.Assert(got, gocheck.Equals, expected) + c.Assert(got, check.Equals, expected) } -func (s *S) TestRepositoryShoudBeInvalidWIthInvalidNamespace(c *gocheck.C) { +func (s *S) TestRepositoryShoudBeInvalidWIthInvalidNamespace(c *check.C) { r := Repository{Name: "../repositories", Users: []string{}} v, err := r.isValid() - c.Assert(v, gocheck.Equals, false) - c.Assert(err, gocheck.NotNil) + c.Assert(v, check.Equals, false) + c.Assert(err, check.NotNil) expected := "^Validation Error: repository name is not valid$" - c.Assert(err, gocheck.ErrorMatches, expected) + c.Assert(err, check.ErrorMatches, expected) r = Repository{Name: "../../repositories", Users: []string{}} v, err = r.isValid() - c.Assert(v, gocheck.Equals, false) - c.Assert(err, gocheck.NotNil) + c.Assert(v, check.Equals, false) + c.Assert(err, check.NotNil) expected = "^Validation Error: repository name is not valid$" - c.Assert(err, gocheck.ErrorMatches, expected) + c.Assert(err, check.ErrorMatches, expected) } -func (s *S) TestRepositoryAcceptsValidNamespaces(c *gocheck.C) { +func (s *S) TestRepositoryAcceptsValidNamespaces(c *check.C) { r := Repository{Name: "_.mallory/foo_bar", Users: []string{"alice", "bob"}} v, err := r.isValid() - c.Assert(v, gocheck.Equals, true) - c.Assert(err, gocheck.IsNil) + c.Assert(v, check.Equals, true) + c.Assert(err, check.IsNil) r = Repository{Name: "_git/foo_bar", Users: []string{"alice", "bob"}} v, err = r.isValid() - c.Assert(v, gocheck.Equals, true) - c.Assert(err, gocheck.IsNil) + c.Assert(v, check.Equals, true) + c.Assert(err, check.IsNil) r = Repository{Name: "time-home_rc2+beta@globoi.com/foo_bar", Users: []string{"you", "me"}} v, err = r.isValid() - c.Assert(v, gocheck.Equals, true) - c.Assert(err, gocheck.IsNil) + c.Assert(v, check.Equals, true) + c.Assert(err, check.IsNil) } -func (s *S) TestRepositoryShouldBeValidWithoutIsPublic(c *gocheck.C) { +func (s *S) TestRepositoryShouldBeValidWithoutIsPublic(c *check.C) { r := Repository{Name: "someName", Users: []string{"smeagol"}} v, _ := r.isValid() - c.Assert(v, gocheck.Equals, true) + c.Assert(v, check.Equals, true) } -func (s *S) TestNewShouldCreateNewGitBareRepository(c *gocheck.C) { +func (s *S) TestNewShouldCreateNewGitBareRepository(c *check.C) { tmpdir, err := commandmocker.Add("git", "$*") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(tmpdir) _, err = New("myRepo", []string{"pumpkin"}, []string{""}, true) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.Repository().Remove(bson.M{"_id": "myRepo"}) - c.Assert(commandmocker.Ran(tmpdir), gocheck.Equals, true) + c.Assert(commandmocker.Ran(tmpdir), check.Equals, true) } -func (s *S) TestNewShouldNotStoreRepoInDbWhenBareCreationFails(c *gocheck.C) { +func (s *S) TestNewShouldNotStoreRepoInDbWhenBareCreationFails(c *check.C) { dir, err := commandmocker.Error("git", "", 1) - c.Check(err, gocheck.IsNil) + c.Check(err, check.IsNil) defer commandmocker.Remove(dir) r, err := New("myRepo", []string{"pumpkin"}, []string{""}, true) - c.Check(err, gocheck.NotNil) + c.Check(err, check.NotNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() err = conn.Repository().Find(bson.M{"_id": r.Name}).One(&r) - c.Assert(err, gocheck.ErrorMatches, "^not found$") + c.Assert(err, check.ErrorMatches, "^not found$") } -func (s *S) TestRemoveShouldRemoveBareRepositoryFromFileSystem(c *gocheck.C) { +func (s *S) TestRemoveShouldRemoveBareRepositoryFromFileSystem(c *check.C) { tmpdir, err := commandmocker.Add("git", "$*") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(tmpdir) rfs := &fstest.RecordingFs{FileContent: "foo"} fs.Fsystem = rfs defer func() { fs.Fsystem = nil }() r, err := New("myRepo", []string{"pumpkin"}, []string{""}, false) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = Remove(r.Name) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) action := "removeall " + path.Join(bareLocation(), "myRepo.git") - c.Assert(rfs.HasAction(action), gocheck.Equals, true) + c.Assert(rfs.HasAction(action), check.Equals, true) } -func (s *S) TestRemoveShouldRemoveRepositoryFromDatabase(c *gocheck.C) { +func (s *S) TestRemoveShouldRemoveRepositoryFromDatabase(c *check.C) { tmpdir, err := commandmocker.Add("git", "$*") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(tmpdir) rfs := &fstest.RecordingFs{FileContent: "foo"} fs.Fsystem = rfs defer func() { fs.Fsystem = nil }() r, err := New("myRepo", []string{"pumpkin"}, []string{""}, false) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = Remove(r.Name) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() err = conn.Repository().Find(bson.M{"_id": r.Name}).One(&r) - c.Assert(err, gocheck.ErrorMatches, "^not found$") + c.Assert(err, check.ErrorMatches, "^not found$") } -func (s *S) TestRemoveShouldReturnMeaningfulErrorWhenRepositoryDoesNotExistInDatabase(c *gocheck.C) { +func (s *S) TestRemoveShouldReturnMeaningfulErrorWhenRepositoryDoesNotExistInDatabase(c *check.C) { rfs := &fstest.RecordingFs{FileContent: "foo"} fs.Fsystem = rfs defer func() { fs.Fsystem = nil }() r := &Repository{Name: "fooBar"} err := Remove(r.Name) - c.Assert(err, gocheck.ErrorMatches, "^Could not remove repository: not found$") + c.Assert(err, check.ErrorMatches, "^Could not remove repository: not found$") } -func (s *S) TestUpdate(c *gocheck.C) { +func (s *S) TestUpdate(c *check.C) { tmpdir, err := commandmocker.Add("git", "$*") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(tmpdir) r, err := New("freedom", []string{"c"}, []string{"d"}, false) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.Repository().RemoveId(r.Name) expected := Repository{ @@ -406,19 +406,19 @@ func (s *S) TestUpdate(c *gocheck.C) { IsPublic: true, } err = Update(r.Name, expected) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) repo, err := Get("freedom") - c.Assert(err, gocheck.IsNil) - c.Assert(repo, gocheck.DeepEquals, expected) + c.Assert(err, check.IsNil) + c.Assert(repo, check.DeepEquals, expected) } -func (s *S) TestUpdateWithRenaming(c *gocheck.C) { +func (s *S) TestUpdateWithRenaming(c *check.C) { tmpdir, err := commandmocker.Add("git", "$*") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(tmpdir) r, err := New("freedom", []string{"c"}, []string{"d"}, false) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.Repository().RemoveId(r.Name) rfs := &fstest.RecordingFs{} @@ -431,27 +431,27 @@ func (s *S) TestUpdateWithRenaming(c *gocheck.C) { IsPublic: true, } err = Update(r.Name, expected) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) repo, err := Get("freedom") - c.Assert(err, gocheck.NotNil) + c.Assert(err, check.NotNil) repo, err = Get("freedom2") - c.Assert(err, gocheck.IsNil) - c.Assert(repo, gocheck.DeepEquals, expected) + c.Assert(err, check.IsNil) + c.Assert(repo, check.DeepEquals, expected) oldPath := path.Join(bareLocation(), "freedom.git") newPath := path.Join(bareLocation(), "freedom2.git") action := fmt.Sprintf("rename %s %s", oldPath, newPath) - c.Assert(rfs.HasAction(action), gocheck.Equals, true) + c.Assert(rfs.HasAction(action), check.Equals, true) } -func (s *S) TestUpdateErrsWithAlreadyExists(c *gocheck.C) { +func (s *S) TestUpdateErrsWithAlreadyExists(c *check.C) { tmpdir, err := commandmocker.Add("git", "$*") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(tmpdir) r1, err := New("freedom", []string{"free"}, []string{}, false) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) r2, err := New("subjection", []string{"subdued"}, []string{}, false) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.Repository().RemoveId(r1.Name) defer conn.Repository().RemoveId(r2.Name) @@ -459,289 +459,289 @@ func (s *S) TestUpdateErrsWithAlreadyExists(c *gocheck.C) { Name: "subjection", } err = Update(r1.Name, update) - c.Assert(mgo.IsDup(err), gocheck.Equals, true) + c.Assert(mgo.IsDup(err), check.Equals, true) } -func (s *S) TestUpdateErrsWhenNotFound(c *gocheck.C) { +func (s *S) TestUpdateErrsWhenNotFound(c *check.C) { update := Repository{} err := Update("nonexistent", update) - c.Assert(err, gocheck.ErrorMatches, "not found") + c.Assert(err, check.ErrorMatches, "not found") } -func (s *S) TestReadOnlyURL(c *gocheck.C) { +func (s *S) TestReadOnlyURL(c *check.C) { host, err := config.GetString("host") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) remote := (&Repository{Name: "lol"}).ReadOnlyURL() - c.Assert(remote, gocheck.Equals, fmt.Sprintf("git://%s/lol.git", host)) + c.Assert(remote, check.Equals, fmt.Sprintf("git://%s/lol.git", host)) } -func (s *S) TestReadOnlyURLWithNamespace(c *gocheck.C) { +func (s *S) TestReadOnlyURLWithNamespace(c *check.C) { host, err := config.GetString("host") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) remote := (&Repository{Name: "olo/lol"}).ReadOnlyURL() - c.Assert(remote, gocheck.Equals, fmt.Sprintf("git://%s/olo/lol.git", host)) + c.Assert(remote, check.Equals, fmt.Sprintf("git://%s/olo/lol.git", host)) } -func (s *S) TestReadOnlyURLWithSSH(c *gocheck.C) { +func (s *S) TestReadOnlyURLWithSSH(c *check.C) { config.Set("git:ssh:use", true) defer config.Unset("git:ssh:use") host, err := config.GetString("host") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) remote := (&Repository{Name: "lol"}).ReadOnlyURL() - c.Assert(remote, gocheck.Equals, fmt.Sprintf("ssh://git@%s/lol.git", host)) + c.Assert(remote, check.Equals, fmt.Sprintf("ssh://git@%s/lol.git", host)) } -func (s *S) TestReadOnlyURLWithSSHAndPort(c *gocheck.C) { +func (s *S) TestReadOnlyURLWithSSHAndPort(c *check.C) { config.Set("git:ssh:use", true) defer config.Unset("git:ssh:use") config.Set("git:ssh:port", "49022") defer config.Unset("git:ssh:port") host, err := config.GetString("host") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) remote := (&Repository{Name: "lol"}).ReadOnlyURL() - c.Assert(remote, gocheck.Equals, fmt.Sprintf("ssh://git@%s:49022/lol.git", host)) + c.Assert(remote, check.Equals, fmt.Sprintf("ssh://git@%s:49022/lol.git", host)) } -func (s *S) TestReadOnlyURLWithReadOnlyHost(c *gocheck.C) { +func (s *S) TestReadOnlyURLWithReadOnlyHost(c *check.C) { config.Set("readonly-host", "something-private") defer config.Unset("readonly-host") remote := (&Repository{Name: "lol"}).ReadOnlyURL() - c.Assert(remote, gocheck.Equals, "git://something-private/lol.git") + c.Assert(remote, check.Equals, "git://something-private/lol.git") } -func (s *S) TestReadWriteURLWithSSH(c *gocheck.C) { +func (s *S) TestReadWriteURLWithSSH(c *check.C) { config.Set("git:ssh:use", true) defer config.Unset("git:ssh:use") uid, err := config.GetString("uid") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) host, err := config.GetString("host") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) remote := (&Repository{Name: "lol"}).ReadWriteURL() expected := fmt.Sprintf("ssh://%s@%s/lol.git", uid, host) - c.Assert(remote, gocheck.Equals, expected) + c.Assert(remote, check.Equals, expected) } -func (s *S) TestReadWriteURLWithNamespaceAndSSH(c *gocheck.C) { +func (s *S) TestReadWriteURLWithNamespaceAndSSH(c *check.C) { config.Set("git:ssh:use", true) defer config.Unset("git:ssh:use") uid, err := config.GetString("uid") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) host, err := config.GetString("host") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) remote := (&Repository{Name: "olo/lol"}).ReadWriteURL() expected := fmt.Sprintf("ssh://%s@%s/olo/lol.git", uid, host) - c.Assert(remote, gocheck.Equals, expected) + c.Assert(remote, check.Equals, expected) } -func (s *S) TestReadWriteURLWithSSHAndPort(c *gocheck.C) { +func (s *S) TestReadWriteURLWithSSHAndPort(c *check.C) { config.Set("git:ssh:use", true) defer config.Unset("git:ssh:use") config.Set("git:ssh:port", "49022") defer config.Unset("git:ssh:port") uid, err := config.GetString("uid") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) host, err := config.GetString("host") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) remote := (&Repository{Name: "lol"}).ReadWriteURL() expected := fmt.Sprintf("ssh://%s@%s:49022/lol.git", uid, host) - c.Assert(remote, gocheck.Equals, expected) + c.Assert(remote, check.Equals, expected) } -func (s *S) TestReadWriteURL(c *gocheck.C) { +func (s *S) TestReadWriteURL(c *check.C) { host, err := config.GetString("host") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) remote := (&Repository{Name: "lol"}).ReadWriteURL() - c.Assert(remote, gocheck.Equals, fmt.Sprintf("git@%s:lol.git", host)) + c.Assert(remote, check.Equals, fmt.Sprintf("git@%s:lol.git", host)) } -func (s *S) TestReadWriteURLUseUidFromConfigFile(c *gocheck.C) { +func (s *S) TestReadWriteURLUseUidFromConfigFile(c *check.C) { uid, err := config.GetString("uid") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) host, err := config.GetString("host") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) config.Set("uid", "test") defer config.Set("uid", uid) remote := (&Repository{Name: "f#"}).ReadWriteURL() - c.Assert(remote, gocheck.Equals, fmt.Sprintf("test@%s:f#.git", host)) + c.Assert(remote, check.Equals, fmt.Sprintf("test@%s:f#.git", host)) } -func (s *S) TestGrantAccessShouldAddUserToListOfRepositories(c *gocheck.C) { +func (s *S) TestGrantAccessShouldAddUserToListOfRepositories(c *check.C) { tmpdir, err := commandmocker.Add("git", "$*") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(tmpdir) r, err := New("proj1", []string{"someuser"}, []string{"otheruser"}, true) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.Repository().RemoveId(r.Name) r2, err := New("proj2", []string{"otheruser"}, []string{"someuser"}, true) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Repository().RemoveId(r2.Name) u := struct { Name string `bson:"_id"` }{Name: "lolcat"} err = conn.User().Insert(&u) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.User().RemoveId(u.Name) err = GrantAccess([]string{r.Name, r2.Name}, []string{u.Name}, false) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = conn.Repository().FindId(r.Name).One(&r) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = conn.Repository().FindId(r2.Name).One(&r2) - c.Assert(err, gocheck.IsNil) - c.Assert(r.Users, gocheck.DeepEquals, []string{"someuser", u.Name}) - c.Assert(r2.Users, gocheck.DeepEquals, []string{"otheruser", u.Name}) - c.Assert(r.ReadOnlyUsers, gocheck.DeepEquals, []string{"otheruser"}) - c.Assert(r2.ReadOnlyUsers, gocheck.DeepEquals, []string{"someuser"}) + c.Assert(err, check.IsNil) + c.Assert(r.Users, check.DeepEquals, []string{"someuser", u.Name}) + c.Assert(r2.Users, check.DeepEquals, []string{"otheruser", u.Name}) + c.Assert(r.ReadOnlyUsers, check.DeepEquals, []string{"otheruser"}) + c.Assert(r2.ReadOnlyUsers, check.DeepEquals, []string{"someuser"}) } -func (s *S) TestGrantReadOnlyAccessShouldAddUserToListOfRepositories(c *gocheck.C) { +func (s *S) TestGrantReadOnlyAccessShouldAddUserToListOfRepositories(c *check.C) { tmpdir, err := commandmocker.Add("git", "$*") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(tmpdir) r, err := New("proj1", []string{"someuser"}, []string{"otheruser"}, true) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.Repository().RemoveId(r.Name) r2, err := New("proj2", []string{"otheruser"}, []string{"someuser"}, true) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Repository().RemoveId(r2.Name) u := struct { Name string `bson:"_id"` }{Name: "lolcat"} err = conn.User().Insert(&u) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.User().RemoveId(u.Name) err = GrantAccess([]string{r.Name, r2.Name}, []string{u.Name}, true) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = conn.Repository().FindId(r.Name).One(&r) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = conn.Repository().FindId(r2.Name).One(&r2) - c.Assert(err, gocheck.IsNil) - c.Assert(r.Users, gocheck.DeepEquals, []string{"someuser"}) - c.Assert(r2.Users, gocheck.DeepEquals, []string{"otheruser"}) - c.Assert(r.ReadOnlyUsers, gocheck.DeepEquals, []string{"otheruser", u.Name}) - c.Assert(r2.ReadOnlyUsers, gocheck.DeepEquals, []string{"someuser", u.Name}) + c.Assert(err, check.IsNil) + c.Assert(r.Users, check.DeepEquals, []string{"someuser"}) + c.Assert(r2.Users, check.DeepEquals, []string{"otheruser"}) + c.Assert(r.ReadOnlyUsers, check.DeepEquals, []string{"otheruser", u.Name}) + c.Assert(r2.ReadOnlyUsers, check.DeepEquals, []string{"someuser", u.Name}) } -func (s *S) TestGrantAccessShouldAddFirstUserIntoRepositoryDocument(c *gocheck.C) { +func (s *S) TestGrantAccessShouldAddFirstUserIntoRepositoryDocument(c *check.C) { r := Repository{Name: "proj1"} conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() err = conn.Repository().Insert(&r) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Repository().RemoveId(r.Name) r2 := Repository{Name: "proj2"} err = conn.Repository().Insert(&r2) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Repository().RemoveId(r2.Name) err = GrantAccess([]string{r.Name, r2.Name}, []string{"Umi"}, false) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = conn.Repository().FindId(r.Name).One(&r) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = conn.Repository().FindId(r.Name).One(&r2) - c.Assert(err, gocheck.IsNil) - c.Assert(r.Users, gocheck.DeepEquals, []string{"Umi"}) - c.Assert(r2.Users, gocheck.DeepEquals, []string{"Umi"}) + c.Assert(err, check.IsNil) + c.Assert(r.Users, check.DeepEquals, []string{"Umi"}) + c.Assert(r2.Users, check.DeepEquals, []string{"Umi"}) } -func (s *S) TestGrantAccessShouldSkipDuplicatedUsers(c *gocheck.C) { +func (s *S) TestGrantAccessShouldSkipDuplicatedUsers(c *check.C) { r := Repository{Name: "proj1", Users: []string{"umi", "luke", "pade"}} conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() err = conn.Repository().Insert(&r) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Repository().RemoveId(r.Name) err = GrantAccess([]string{r.Name}, []string{"pade"}, false) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = conn.Repository().FindId(r.Name).One(&r) - c.Assert(err, gocheck.IsNil) - c.Assert(r.Users, gocheck.DeepEquals, []string{"umi", "luke", "pade"}) + c.Assert(err, check.IsNil) + c.Assert(r.Users, check.DeepEquals, []string{"umi", "luke", "pade"}) } -func (s *S) TestRevokeAccessShouldRemoveUserFromAllRepositories(c *gocheck.C) { +func (s *S) TestRevokeAccessShouldRemoveUserFromAllRepositories(c *check.C) { tmpdir, err := commandmocker.Add("git", "$*") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(tmpdir) r, err := New("proj1", []string{"someuser", "umi"}, []string{"otheruser"}, true) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.Repository().RemoveId(r.Name) r2, err := New("proj2", []string{"otheruser", "umi"}, []string{"someuser"}, true) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Repository().RemoveId(r2.Name) err = RevokeAccess([]string{r.Name, r2.Name}, []string{"umi"}, false) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = conn.Repository().FindId(r.Name).One(&r) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = conn.Repository().FindId(r2.Name).One(&r2) - c.Assert(err, gocheck.IsNil) - c.Assert(r.Users, gocheck.DeepEquals, []string{"someuser"}) - c.Assert(r2.Users, gocheck.DeepEquals, []string{"otheruser"}) - c.Assert(r.ReadOnlyUsers, gocheck.DeepEquals, []string{"otheruser"}) - c.Assert(r2.ReadOnlyUsers, gocheck.DeepEquals, []string{"someuser"}) + c.Assert(err, check.IsNil) + c.Assert(r.Users, check.DeepEquals, []string{"someuser"}) + c.Assert(r2.Users, check.DeepEquals, []string{"otheruser"}) + c.Assert(r.ReadOnlyUsers, check.DeepEquals, []string{"otheruser"}) + c.Assert(r2.ReadOnlyUsers, check.DeepEquals, []string{"someuser"}) } -func (s *S) TestRevokeReadOnlyAccessShouldRemoveUserFromAllRepositories(c *gocheck.C) { +func (s *S) TestRevokeReadOnlyAccessShouldRemoveUserFromAllRepositories(c *check.C) { tmpdir, err := commandmocker.Add("git", "$*") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(tmpdir) r, err := New("proj1", []string{"someuser"}, []string{"otheruser", "umi"}, true) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.Repository().RemoveId(r.Name) r2, err := New("proj2", []string{"otheruser"}, []string{"someuser", "umi"}, true) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Repository().RemoveId(r2.Name) err = RevokeAccess([]string{r.Name, r2.Name}, []string{"umi"}, true) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = conn.Repository().FindId(r.Name).One(&r) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = conn.Repository().FindId(r2.Name).One(&r2) - c.Assert(err, gocheck.IsNil) - c.Assert(r.Users, gocheck.DeepEquals, []string{"someuser"}) - c.Assert(r2.Users, gocheck.DeepEquals, []string{"otheruser"}) - c.Assert(r.ReadOnlyUsers, gocheck.DeepEquals, []string{"otheruser"}) - c.Assert(r2.ReadOnlyUsers, gocheck.DeepEquals, []string{"someuser"}) + c.Assert(err, check.IsNil) + c.Assert(r.Users, check.DeepEquals, []string{"someuser"}) + c.Assert(r2.Users, check.DeepEquals, []string{"otheruser"}) + c.Assert(r.ReadOnlyUsers, check.DeepEquals, []string{"otheruser"}) + c.Assert(r2.ReadOnlyUsers, check.DeepEquals, []string{"someuser"}) } -func (s *S) TestConflictingRepositoryNameShouldReturnExplicitError(c *gocheck.C) { +func (s *S) TestConflictingRepositoryNameShouldReturnExplicitError(c *check.C) { tmpdir, err := commandmocker.Add("git", "$*") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(tmpdir) _, err = New("someRepo", []string{"gollum"}, []string{""}, true) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.Repository().Remove(bson.M{"_id": "someRepo"}) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) _, err = New("someRepo", []string{"gollum"}, []string{""}, true) - c.Assert(err, gocheck.ErrorMatches, "A repository with this name already exists.") + c.Assert(err, check.ErrorMatches, "A repository with this name already exists.") } -func (s *S) TestGet(c *gocheck.C) { +func (s *S) TestGet(c *check.C) { repo := Repository{Name: "somerepo", Users: []string{}, ReadOnlyUsers: []string{}} conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() err = conn.Repository().Insert(repo) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) r, err := Get("somerepo") - c.Assert(err, gocheck.IsNil) - c.Assert(r, gocheck.DeepEquals, repo) + c.Assert(err, check.IsNil) + c.Assert(r, check.DeepEquals, repo) } -func (s *S) TestMarshalJSON(c *gocheck.C) { +func (s *S) TestMarshalJSON(c *check.C) { repo := Repository{Name: "somerepo", Users: []string{}} expected := map[string]interface{}{ "name": repo.Name, @@ -750,14 +750,14 @@ func (s *S) TestMarshalJSON(c *gocheck.C) { "git_url": repo.ReadOnlyURL(), } data, err := json.Marshal(&repo) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) var result map[string]interface{} err = json.Unmarshal(data, &result) - c.Assert(err, gocheck.IsNil) - c.Assert(result, gocheck.DeepEquals, expected) + c.Assert(err, check.IsNil) + c.Assert(result, check.DeepEquals, expected) } -func (s *S) TestGetFileContentsWhenContentsAvailable(c *gocheck.C) { +func (s *S) TestGetFileContentsWhenContentsAvailable(c *check.C) { expected := []byte("something") Retriever = &MockContentRetriever{ ResultContents: expected, @@ -766,11 +766,11 @@ func (s *S) TestGetFileContentsWhenContentsAvailable(c *gocheck.C) { Retriever = nil }() contents, err := GetFileContents("repo", "ref", "path") - c.Assert(err, gocheck.IsNil) - c.Assert(string(contents), gocheck.Equals, string(expected)) + c.Assert(err, check.IsNil) + c.Assert(string(contents), check.Equals, string(expected)) } -func (s *S) TestGetFileContentsWhenGitNotFound(c *gocheck.C) { +func (s *S) TestGetFileContentsWhenGitNotFound(c *check.C) { lookpathError := fmt.Errorf("mock lookpath error") Retriever = &MockContentRetriever{ LookPathError: lookpathError, @@ -779,10 +779,10 @@ func (s *S) TestGetFileContentsWhenGitNotFound(c *gocheck.C) { Retriever = nil }() _, err := GetFileContents("repo", "ref", "path") - c.Assert(err.Error(), gocheck.Equals, "mock lookpath error") + c.Assert(err.Error(), check.Equals, "mock lookpath error") } -func (s *S) TestGetFileContentsWhenCommandFails(c *gocheck.C) { +func (s *S) TestGetFileContentsWhenCommandFails(c *check.C) { outputError := fmt.Errorf("mock output error") Retriever = &MockContentRetriever{ OutputError: outputError, @@ -791,10 +791,10 @@ func (s *S) TestGetFileContentsWhenCommandFails(c *gocheck.C) { Retriever = nil }() _, err := GetFileContents("repo", "ref", "path") - c.Assert(err.Error(), gocheck.Equals, "mock output error") + c.Assert(err.Error(), check.Equals, "mock output error") } -func (s *S) TestGetArchive(c *gocheck.C) { +func (s *S) TestGetArchive(c *check.C) { expected := []byte("something") Retriever = &MockContentRetriever{ ResultContents: expected, @@ -803,11 +803,11 @@ func (s *S) TestGetArchive(c *gocheck.C) { Retriever = nil }() contents, err := GetArchive("repo", "ref", Zip) - c.Assert(err, gocheck.IsNil) - c.Assert(string(contents), gocheck.Equals, string(expected)) + c.Assert(err, check.IsNil) + c.Assert(string(contents), check.Equals, string(expected)) } -func (s *S) TestGetArchiveWhenGitNotFound(c *gocheck.C) { +func (s *S) TestGetArchiveWhenGitNotFound(c *check.C) { lookpathError := fmt.Errorf("mock lookpath error") Retriever = &MockContentRetriever{ LookPathError: lookpathError, @@ -816,10 +816,10 @@ func (s *S) TestGetArchiveWhenGitNotFound(c *gocheck.C) { Retriever = nil }() _, err := GetArchive("repo", "ref", Zip) - c.Assert(err.Error(), gocheck.Equals, "mock lookpath error") + c.Assert(err.Error(), check.Equals, "mock lookpath error") } -func (s *S) TestGetArchiveWhenCommandFails(c *gocheck.C) { +func (s *S) TestGetArchiveWhenCommandFails(c *check.C) { outputError := fmt.Errorf("mock output error") Retriever = &MockContentRetriever{ OutputError: outputError, @@ -828,10 +828,10 @@ func (s *S) TestGetArchiveWhenCommandFails(c *gocheck.C) { Retriever = nil }() _, err := GetArchive("repo", "ref", Zip) - c.Assert(err.Error(), gocheck.Equals, "mock output error") + c.Assert(err.Error(), check.Equals, "mock output error") } -func (s *S) TestGetFileContentIntegration(c *gocheck.C) { +func (s *S) TestGetFileContentIntegration(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -842,13 +842,13 @@ func (s *S) TestGetFileContentIntegration(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) contents, err := GetFileContents(repo, "master", file) - c.Assert(err, gocheck.IsNil) - c.Assert(string(contents), gocheck.Equals, content) + c.Assert(err, check.IsNil) + c.Assert(string(contents), check.Equals, content) } -func (s *S) TestGetFileContentIntegrationEmptyContent(c *gocheck.C) { +func (s *S) TestGetFileContentIntegrationEmptyContent(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -859,18 +859,18 @@ func (s *S) TestGetFileContentIntegrationEmptyContent(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) err := CreateEmptyFile(bare, repo, file) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) testPath := path.Join(bare, repo+".git") err = MakeCommit(testPath, "empty file content") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) contents, err := GetFileContents(repo, "master", file) - c.Assert(err, gocheck.IsNil) - c.Assert(string(contents), gocheck.Equals, content) + c.Assert(err, check.IsNil) + c.Assert(string(contents), check.Equals, content) } -func (s *S) TestGetFileContentWhenRefIsInvalid(c *gocheck.C) { +func (s *S) TestGetFileContentWhenRefIsInvalid(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -881,12 +881,12 @@ func (s *S) TestGetFileContentWhenRefIsInvalid(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) _, err := GetFileContents(repo, "MuchMissing", file) - c.Assert(err, gocheck.ErrorMatches, "^Error when trying to obtain file README on ref MuchMissing of repository gandalf-test-repo \\(exit status 128\\)\\.$") + c.Assert(err, check.ErrorMatches, "^Error when trying to obtain file README on ref MuchMissing of repository gandalf-test-repo \\(exit status 128\\)\\.$") } -func (s *S) TestGetFileContentWhenFileIsInvalid(c *gocheck.C) { +func (s *S) TestGetFileContentWhenFileIsInvalid(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -897,12 +897,12 @@ func (s *S) TestGetFileContentWhenFileIsInvalid(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) _, err := GetFileContents(repo, "master", "Such file") - c.Assert(err, gocheck.ErrorMatches, "^Error when trying to obtain file Such file on ref master of repository gandalf-test-repo \\(exit status 128\\)\\.$") + c.Assert(err, check.ErrorMatches, "^Error when trying to obtain file Such file on ref master of repository gandalf-test-repo \\(exit status 128\\)\\.$") } -func (s *S) TestGetTreeIntegration(c *gocheck.C) { +func (s *S) TestGetTreeIntegration(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -913,14 +913,14 @@ func (s *S) TestGetTreeIntegration(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) tree, err := GetTree(repo, "master", "much/README") - c.Assert(err, gocheck.IsNil) - c.Assert(tree[0]["path"], gocheck.Equals, "much/README") - c.Assert(tree[0]["rawPath"], gocheck.Equals, "much/README") + c.Assert(err, check.IsNil) + c.Assert(tree[0]["path"], check.Equals, "much/README") + c.Assert(tree[0]["rawPath"], check.Equals, "much/README") } -func (s *S) TestGetTreeIntegrationEmptyContent(c *gocheck.C) { +func (s *S) TestGetTreeIntegrationEmptyContent(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -931,14 +931,14 @@ func (s *S) TestGetTreeIntegrationEmptyContent(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) tree, err := GetTree(repo, "master", "much/README") - c.Assert(err, gocheck.IsNil) - c.Assert(tree[0]["path"], gocheck.Equals, "much/README") - c.Assert(tree[0]["rawPath"], gocheck.Equals, "much/README") + c.Assert(err, check.IsNil) + c.Assert(tree[0]["path"], check.Equals, "much/README") + c.Assert(tree[0]["rawPath"], check.Equals, "much/README") } -func (s *S) TestGetTreeIntegrationWithEscapedFileName(c *gocheck.C) { +func (s *S) TestGetTreeIntegrationWithEscapedFileName(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -949,14 +949,14 @@ func (s *S) TestGetTreeIntegrationWithEscapedFileName(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) tree, err := GetTree(repo, "master", "much/such\tREADME") - c.Assert(err, gocheck.IsNil) - c.Assert(tree[0]["path"], gocheck.Equals, "much/such\\tREADME") - c.Assert(tree[0]["rawPath"], gocheck.Equals, "\"much/such\\tREADME\"") + c.Assert(err, check.IsNil) + c.Assert(tree[0]["path"], check.Equals, "much/such\\tREADME") + c.Assert(tree[0]["rawPath"], check.Equals, "\"much/such\\tREADME\"") } -func (s *S) TestGetTreeIntegrationWithFileNameWithSpace(c *gocheck.C) { +func (s *S) TestGetTreeIntegrationWithFileNameWithSpace(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -967,14 +967,14 @@ func (s *S) TestGetTreeIntegrationWithFileNameWithSpace(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) tree, err := GetTree(repo, "master", "much/much README") - c.Assert(err, gocheck.IsNil) - c.Assert(tree[0]["path"], gocheck.Equals, "much/much README") - c.Assert(tree[0]["rawPath"], gocheck.Equals, "much/much README") + c.Assert(err, check.IsNil) + c.Assert(tree[0]["path"], check.Equals, "much/much README") + c.Assert(tree[0]["rawPath"], check.Equals, "much/much README") } -func (s *S) TestGetArchiveIntegrationWhenZip(c *gocheck.C) { +func (s *S) TestGetArchiveIntegrationWhenZip(c *check.C) { expected := make(map[string]string) expected["gandalf-test-repo-master/README"] = "much WOW" oldBare := bare @@ -987,22 +987,22 @@ func (s *S) TestGetArchiveIntegrationWhenZip(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) zipContents, err := GetArchive(repo, "master", Zip) reader := bytes.NewReader(zipContents) zipReader, err := zip.NewReader(reader, int64(len(zipContents))) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) for _, f := range zipReader.File { rc, err := f.Open() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer rc.Close() contents, err := ioutil.ReadAll(rc) - c.Assert(err, gocheck.IsNil) - c.Assert(string(contents), gocheck.Equals, expected[f.Name]) + c.Assert(err, check.IsNil) + c.Assert(string(contents), check.Equals, expected[f.Name]) } } -func (s *S) TestGetArchiveIntegrationWhenTar(c *gocheck.C) { +func (s *S) TestGetArchiveIntegrationWhenTar(c *check.C) { expected := make(map[string]string) expected["gandalf-test-repo-master/README"] = "much WOW" oldBare := bare @@ -1015,19 +1015,19 @@ func (s *S) TestGetArchiveIntegrationWhenTar(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) tarContents, err := GetArchive(repo, "master", Tar) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) reader := bytes.NewReader(tarContents) tarReader := tar.NewReader(reader) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) for { hdr, err := tarReader.Next() if err == io.EOF { // end of tar archive break } - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) path := hdr.Name _, ok := expected[path] if !ok { @@ -1035,12 +1035,12 @@ func (s *S) TestGetArchiveIntegrationWhenTar(c *gocheck.C) { } buffer := new(bytes.Buffer) _, err = io.Copy(buffer, tarReader) - c.Assert(err, gocheck.IsNil) - c.Assert(buffer.String(), gocheck.Equals, expected[path]) + c.Assert(err, check.IsNil) + c.Assert(buffer.String(), check.Equals, expected[path]) } } -func (s *S) TestGetArchiveIntegrationWhenInvalidFormat(c *gocheck.C) { +func (s *S) TestGetArchiveIntegrationWhenInvalidFormat(c *check.C) { expected := make(map[string]string) expected["gandalf-test-repo-master/README"] = "much WOW" oldBare := bare @@ -1053,23 +1053,23 @@ func (s *S) TestGetArchiveIntegrationWhenInvalidFormat(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) zipContents, err := GetArchive(repo, "master", 99) reader := bytes.NewReader(zipContents) zipReader, err := zip.NewReader(reader, int64(len(zipContents))) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) for _, f := range zipReader.File { //fmt.Printf("Contents of %s:\n", f.Name) rc, err := f.Open() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer rc.Close() contents, err := ioutil.ReadAll(rc) - c.Assert(err, gocheck.IsNil) - c.Assert(string(contents), gocheck.Equals, expected[f.Name]) + c.Assert(err, check.IsNil) + c.Assert(string(contents), check.Equals, expected[f.Name]) } } -func (s *S) TestGetArchiveIntegrationWhenInvalidRepo(c *gocheck.C) { +func (s *S) TestGetArchiveIntegrationWhenInvalidRepo(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -1080,12 +1080,12 @@ func (s *S) TestGetArchiveIntegrationWhenInvalidRepo(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) _, err := GetArchive("invalid-repo", "master", Zip) - c.Assert(err.Error(), gocheck.Equals, "Error when trying to obtain archive for ref master of repository invalid-repo (Repository does not exist).") + c.Assert(err.Error(), check.Equals, "Error when trying to obtain archive for ref master of repository invalid-repo (Repository does not exist).") } -func (s *S) TestGetTreeIntegrationWithMissingFile(c *gocheck.C) { +func (s *S) TestGetTreeIntegrationWithMissingFile(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -1096,13 +1096,13 @@ func (s *S) TestGetTreeIntegrationWithMissingFile(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) tree, err := GetTree(repo, "master", "very missing") - c.Assert(err, gocheck.IsNil) - c.Assert(tree, gocheck.HasLen, 0) + c.Assert(err, check.IsNil) + c.Assert(tree, check.HasLen, 0) } -func (s *S) TestGetTreeIntegrationWithInvalidRef(c *gocheck.C) { +func (s *S) TestGetTreeIntegrationWithInvalidRef(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -1113,12 +1113,12 @@ func (s *S) TestGetTreeIntegrationWithInvalidRef(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) _, err := GetTree(repo, "VeryInvalid", "very missing") - c.Assert(err, gocheck.ErrorMatches, "^Error when trying to obtain tree very missing on ref VeryInvalid of repository gandalf-test-repo \\(exit status 128\\)\\.$") + c.Assert(err, check.ErrorMatches, "^Error when trying to obtain tree very missing on ref VeryInvalid of repository gandalf-test-repo \\(exit status 128\\)\\.$") } -func (s *S) TestGetBranchesIntegration(c *gocheck.C) { +func (s *S) TestGetBranchesIntegration(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -1129,45 +1129,45 @@ func (s *S) TestGetBranchesIntegration(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) errCreateBranches := CreateBranchesOnTestRepository(bare, repo, "doge_bites", "doge_barks") - c.Assert(errCreateBranches, gocheck.IsNil) + c.Assert(errCreateBranches, check.IsNil) branches, err := GetBranches(repo) - c.Assert(err, gocheck.IsNil) - c.Assert(branches, gocheck.HasLen, 3) - c.Assert(branches[0].Ref, gocheck.Matches, "[a-f0-9]{40}") - c.Assert(branches[0].Name, gocheck.Equals, "doge_barks") - c.Assert(branches[0].Committer.Name, gocheck.Equals, "doge") - c.Assert(branches[0].Committer.Email, gocheck.Equals, "") - c.Assert(branches[0].Author.Name, gocheck.Equals, "doge") - c.Assert(branches[0].Author.Email, gocheck.Equals, "") - c.Assert(branches[0].Subject, gocheck.Equals, "will bark") - c.Assert(branches[0].CreatedAt, gocheck.Equals, branches[0].Author.Date) - c.Assert(branches[0].Links.ZipArchive, gocheck.Equals, GetArchiveUrl(repo, "doge_barks", "zip")) - c.Assert(branches[0].Links.TarArchive, gocheck.Equals, GetArchiveUrl(repo, "doge_barks", "tar.gz")) - c.Assert(branches[1].Ref, gocheck.Matches, "[a-f0-9]{40}") - c.Assert(branches[1].Name, gocheck.Equals, "doge_bites") - c.Assert(branches[1].Committer.Name, gocheck.Equals, "doge") - c.Assert(branches[1].Committer.Email, gocheck.Equals, "") - c.Assert(branches[1].Author.Name, gocheck.Equals, "doge") - c.Assert(branches[1].Author.Email, gocheck.Equals, "") - c.Assert(branches[1].Subject, gocheck.Equals, "will bark") - c.Assert(branches[1].CreatedAt, gocheck.Equals, branches[1].Author.Date) - c.Assert(branches[1].Links.ZipArchive, gocheck.Equals, GetArchiveUrl(repo, "doge_bites", "zip")) - c.Assert(branches[1].Links.TarArchive, gocheck.Equals, GetArchiveUrl(repo, "doge_bites", "tar.gz")) - c.Assert(branches[2].Ref, gocheck.Matches, "[a-f0-9]{40}") - c.Assert(branches[2].Name, gocheck.Equals, "master") - c.Assert(branches[2].Committer.Name, gocheck.Equals, "doge") - c.Assert(branches[2].Committer.Email, gocheck.Equals, "") - c.Assert(branches[2].Author.Name, gocheck.Equals, "doge") - c.Assert(branches[2].Author.Email, gocheck.Equals, "") - c.Assert(branches[2].Subject, gocheck.Equals, "will bark") - c.Assert(branches[2].CreatedAt, gocheck.Equals, branches[2].Author.Date) - c.Assert(branches[2].Links.ZipArchive, gocheck.Equals, GetArchiveUrl(repo, "master", "zip")) - c.Assert(branches[2].Links.TarArchive, gocheck.Equals, GetArchiveUrl(repo, "master", "tar.gz")) -} - -func (s *S) TestGetForEachRefIntegrationWithSubjectEmpty(c *gocheck.C) { + c.Assert(err, check.IsNil) + c.Assert(branches, check.HasLen, 3) + c.Assert(branches[0].Ref, check.Matches, "[a-f0-9]{40}") + c.Assert(branches[0].Name, check.Equals, "doge_barks") + c.Assert(branches[0].Committer.Name, check.Equals, "doge") + c.Assert(branches[0].Committer.Email, check.Equals, "") + c.Assert(branches[0].Author.Name, check.Equals, "doge") + c.Assert(branches[0].Author.Email, check.Equals, "") + c.Assert(branches[0].Subject, check.Equals, "will bark") + c.Assert(branches[0].CreatedAt, check.Equals, branches[0].Author.Date) + c.Assert(branches[0].Links.ZipArchive, check.Equals, GetArchiveUrl(repo, "doge_barks", "zip")) + c.Assert(branches[0].Links.TarArchive, check.Equals, GetArchiveUrl(repo, "doge_barks", "tar.gz")) + c.Assert(branches[1].Ref, check.Matches, "[a-f0-9]{40}") + c.Assert(branches[1].Name, check.Equals, "doge_bites") + c.Assert(branches[1].Committer.Name, check.Equals, "doge") + c.Assert(branches[1].Committer.Email, check.Equals, "") + c.Assert(branches[1].Author.Name, check.Equals, "doge") + c.Assert(branches[1].Author.Email, check.Equals, "") + c.Assert(branches[1].Subject, check.Equals, "will bark") + c.Assert(branches[1].CreatedAt, check.Equals, branches[1].Author.Date) + c.Assert(branches[1].Links.ZipArchive, check.Equals, GetArchiveUrl(repo, "doge_bites", "zip")) + c.Assert(branches[1].Links.TarArchive, check.Equals, GetArchiveUrl(repo, "doge_bites", "tar.gz")) + c.Assert(branches[2].Ref, check.Matches, "[a-f0-9]{40}") + c.Assert(branches[2].Name, check.Equals, "master") + c.Assert(branches[2].Committer.Name, check.Equals, "doge") + c.Assert(branches[2].Committer.Email, check.Equals, "") + c.Assert(branches[2].Author.Name, check.Equals, "doge") + c.Assert(branches[2].Author.Email, check.Equals, "") + c.Assert(branches[2].Subject, check.Equals, "will bark") + c.Assert(branches[2].CreatedAt, check.Equals, branches[2].Author.Date) + c.Assert(branches[2].Links.ZipArchive, check.Equals, GetArchiveUrl(repo, "master", "zip")) + c.Assert(branches[2].Links.TarArchive, check.Equals, GetArchiveUrl(repo, "master", "tar.gz")) +} + +func (s *S) TestGetForEachRefIntegrationWithSubjectEmpty(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -1178,31 +1178,31 @@ func (s *S) TestGetForEachRefIntegrationWithSubjectEmpty(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) errCreateBranches := CreateBranchesOnTestRepository(bare, repo, "doge_howls") - c.Assert(errCreateBranches, gocheck.IsNil) + c.Assert(errCreateBranches, check.IsNil) refs, err := GetForEachRef(repo, "refs/") - c.Assert(err, gocheck.IsNil) - c.Assert(refs, gocheck.HasLen, 2) - c.Assert(refs[0].Ref, gocheck.Matches, "[a-f0-9]{40}") - c.Assert(refs[0].Name, gocheck.Equals, "doge_howls") - c.Assert(refs[0].Committer.Name, gocheck.Equals, "doge") - c.Assert(refs[0].Committer.Email, gocheck.Equals, "") - c.Assert(refs[0].Author.Name, gocheck.Equals, "doge") - c.Assert(refs[0].Author.Email, gocheck.Equals, "") - c.Assert(refs[0].Subject, gocheck.Equals, "") - c.Assert(refs[0].CreatedAt, gocheck.Equals, refs[0].Author.Date) - c.Assert(refs[1].Ref, gocheck.Matches, "[a-f0-9]{40}") - c.Assert(refs[1].Name, gocheck.Equals, "master") - c.Assert(refs[1].Committer.Name, gocheck.Equals, "doge") - c.Assert(refs[1].Committer.Email, gocheck.Equals, "") - c.Assert(refs[1].Author.Name, gocheck.Equals, "doge") - c.Assert(refs[1].Author.Email, gocheck.Equals, "") - c.Assert(refs[1].Subject, gocheck.Equals, "") - c.Assert(refs[1].CreatedAt, gocheck.Equals, refs[1].Author.Date) -} - -func (s *S) TestGetForEachRefIntegrationWithSubjectTabbed(c *gocheck.C) { + c.Assert(err, check.IsNil) + c.Assert(refs, check.HasLen, 2) + c.Assert(refs[0].Ref, check.Matches, "[a-f0-9]{40}") + c.Assert(refs[0].Name, check.Equals, "doge_howls") + c.Assert(refs[0].Committer.Name, check.Equals, "doge") + c.Assert(refs[0].Committer.Email, check.Equals, "") + c.Assert(refs[0].Author.Name, check.Equals, "doge") + c.Assert(refs[0].Author.Email, check.Equals, "") + c.Assert(refs[0].Subject, check.Equals, "") + c.Assert(refs[0].CreatedAt, check.Equals, refs[0].Author.Date) + c.Assert(refs[1].Ref, check.Matches, "[a-f0-9]{40}") + c.Assert(refs[1].Name, check.Equals, "master") + c.Assert(refs[1].Committer.Name, check.Equals, "doge") + c.Assert(refs[1].Committer.Email, check.Equals, "") + c.Assert(refs[1].Author.Name, check.Equals, "doge") + c.Assert(refs[1].Author.Email, check.Equals, "") + c.Assert(refs[1].Subject, check.Equals, "") + c.Assert(refs[1].CreatedAt, check.Equals, refs[1].Author.Date) +} + +func (s *S) TestGetForEachRefIntegrationWithSubjectTabbed(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -1213,31 +1213,31 @@ func (s *S) TestGetForEachRefIntegrationWithSubjectTabbed(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) errCreateBranches := CreateBranchesOnTestRepository(bare, repo, "doge_howls") - c.Assert(errCreateBranches, gocheck.IsNil) + c.Assert(errCreateBranches, check.IsNil) refs, err := GetForEachRef(repo, "refs/") - c.Assert(err, gocheck.IsNil) - c.Assert(refs, gocheck.HasLen, 2) - c.Assert(refs[0].Ref, gocheck.Matches, "[a-f0-9]{40}") - c.Assert(refs[0].Name, gocheck.Equals, "doge_howls") - c.Assert(refs[0].Committer.Name, gocheck.Equals, "doge") - c.Assert(refs[0].Committer.Email, gocheck.Equals, "") - c.Assert(refs[0].Author.Name, gocheck.Equals, "doge") - c.Assert(refs[0].Author.Email, gocheck.Equals, "") - c.Assert(refs[0].Subject, gocheck.Equals, "will\tbark") - c.Assert(refs[0].CreatedAt, gocheck.Equals, refs[0].Author.Date) - c.Assert(refs[1].Ref, gocheck.Matches, "[a-f0-9]{40}") - c.Assert(refs[1].Name, gocheck.Equals, "master") - c.Assert(refs[1].Committer.Name, gocheck.Equals, "doge") - c.Assert(refs[1].Committer.Email, gocheck.Equals, "") - c.Assert(refs[1].Author.Name, gocheck.Equals, "doge") - c.Assert(refs[1].Author.Email, gocheck.Equals, "") - c.Assert(refs[1].Subject, gocheck.Equals, "will\tbark") - c.Assert(refs[1].CreatedAt, gocheck.Equals, refs[1].Author.Date) -} - -func (s *S) TestGetForEachRefIntegrationWhenPatternEmpty(c *gocheck.C) { + c.Assert(err, check.IsNil) + c.Assert(refs, check.HasLen, 2) + c.Assert(refs[0].Ref, check.Matches, "[a-f0-9]{40}") + c.Assert(refs[0].Name, check.Equals, "doge_howls") + c.Assert(refs[0].Committer.Name, check.Equals, "doge") + c.Assert(refs[0].Committer.Email, check.Equals, "") + c.Assert(refs[0].Author.Name, check.Equals, "doge") + c.Assert(refs[0].Author.Email, check.Equals, "") + c.Assert(refs[0].Subject, check.Equals, "will\tbark") + c.Assert(refs[0].CreatedAt, check.Equals, refs[0].Author.Date) + c.Assert(refs[1].Ref, check.Matches, "[a-f0-9]{40}") + c.Assert(refs[1].Name, check.Equals, "master") + c.Assert(refs[1].Committer.Name, check.Equals, "doge") + c.Assert(refs[1].Committer.Email, check.Equals, "") + c.Assert(refs[1].Author.Name, check.Equals, "doge") + c.Assert(refs[1].Author.Email, check.Equals, "") + c.Assert(refs[1].Subject, check.Equals, "will\tbark") + c.Assert(refs[1].CreatedAt, check.Equals, refs[1].Author.Date) +} + +func (s *S) TestGetForEachRefIntegrationWhenPatternEmpty(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -1248,15 +1248,15 @@ func (s *S) TestGetForEachRefIntegrationWhenPatternEmpty(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) refs, err := GetForEachRef("gandalf-test-repo", "") - c.Assert(err, gocheck.IsNil) - c.Assert(refs, gocheck.HasLen, 1) - c.Assert(refs[0], gocheck.FitsTypeOf, Ref{}) - c.Assert(refs[0].Name, gocheck.Equals, "master") + c.Assert(err, check.IsNil) + c.Assert(refs, check.HasLen, 1) + c.Assert(refs[0], check.FitsTypeOf, Ref{}) + c.Assert(refs[0].Name, check.Equals, "master") } -func (s *S) TestGetForEachRefIntegrationWhenPatternNonExistent(c *gocheck.C) { +func (s *S) TestGetForEachRefIntegrationWhenPatternNonExistent(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -1267,18 +1267,18 @@ func (s *S) TestGetForEachRefIntegrationWhenPatternNonExistent(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) refs, err := GetForEachRef("gandalf-test-repo", "non_existent_pattern") - c.Assert(err, gocheck.IsNil) - c.Assert(refs, gocheck.HasLen, 0) + c.Assert(err, check.IsNil) + c.Assert(refs, check.HasLen, 0) } -func (s *S) TestGetForEachRefIntegrationWhenInvalidRepo(c *gocheck.C) { +func (s *S) TestGetForEachRefIntegrationWhenInvalidRepo(c *check.C) { _, err := GetForEachRef("invalid-repo", "refs/") - c.Assert(err.Error(), gocheck.Equals, "Error when trying to obtain the refs of repository invalid-repo (Repository does not exist).") + c.Assert(err.Error(), check.Equals, "Error when trying to obtain the refs of repository invalid-repo (Repository does not exist).") } -func (s *S) TestGetForEachRefIntegrationWhenPatternSpaced(c *gocheck.C) { +func (s *S) TestGetForEachRefIntegrationWhenPatternSpaced(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -1289,15 +1289,15 @@ func (s *S) TestGetForEachRefIntegrationWhenPatternSpaced(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) errCreateBranches := CreateBranchesOnTestRepository(bare, repo, "doge_howls") - c.Assert(errCreateBranches, gocheck.IsNil) + c.Assert(errCreateBranches, check.IsNil) refs, err := GetForEachRef("gandalf-test-repo", "much bark") - c.Assert(err, gocheck.IsNil) - c.Assert(refs, gocheck.HasLen, 0) + c.Assert(err, check.IsNil) + c.Assert(refs, check.HasLen, 0) } -func (s *S) TestGetForEachRefIntegrationWhenPatternInvalid(c *gocheck.C) { +func (s *S) TestGetForEachRefIntegrationWhenPatternInvalid(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -1308,12 +1308,12 @@ func (s *S) TestGetForEachRefIntegrationWhenPatternInvalid(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) _, err := GetForEachRef("gandalf-test-repo", "--format") - c.Assert(err.Error(), gocheck.Equals, "Error when trying to obtain the refs of repository gandalf-test-repo (exit status 129).") + c.Assert(err.Error(), check.Equals, "Error when trying to obtain the refs of repository gandalf-test-repo (exit status 129).") } -func (s *S) TestGetForEachRefOutputInvalid(c *gocheck.C) { +func (s *S) TestGetForEachRefOutputInvalid(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -1324,15 +1324,15 @@ func (s *S) TestGetForEachRefOutputInvalid(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) tmpdir, err := commandmocker.Add("git", "-") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(tmpdir) _, err = GetForEachRef(repo, "") - c.Assert(err.Error(), gocheck.Equals, "Error when trying to obtain the refs of repository gandalf-test-repo (Invalid git for-each-ref output [-]).") + c.Assert(err.Error(), check.Equals, "Error when trying to obtain the refs of repository gandalf-test-repo (Invalid git for-each-ref output [-]).") } -func (s *S) TestGetForEachRefOutputEmpty(c *gocheck.C) { +func (s *S) TestGetForEachRefOutputEmpty(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -1343,16 +1343,16 @@ func (s *S) TestGetForEachRefOutputEmpty(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) tmpdir, err := commandmocker.Add("git", "\n") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(tmpdir) refs, err := GetForEachRef(repo, "") - c.Assert(err, gocheck.IsNil) - c.Assert(refs, gocheck.HasLen, 0) + c.Assert(err, check.IsNil) + c.Assert(refs, check.HasLen, 0) } -func (s *S) TestGetDiffIntegration(c *gocheck.C) { +func (s *S) TestGetDiffIntegration(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -1365,21 +1365,21 @@ func (s *S) TestGetDiffIntegration(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) errCreateCommit := CreateCommit(bare, repo, file, object1) - c.Assert(errCreateCommit, gocheck.IsNil) + c.Assert(errCreateCommit, check.IsNil) firstHashCommit, err := GetLastHashCommit(bare, repo) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) errCreateCommit = CreateCommit(bare, repo, file, object2) - c.Assert(errCreateCommit, gocheck.IsNil) + c.Assert(errCreateCommit, check.IsNil) secondHashCommit, err := GetLastHashCommit(bare, repo) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) diff, err := GetDiff(repo, string(firstHashCommit), string(secondHashCommit)) - c.Assert(err, gocheck.IsNil) - c.Assert(string(diff), gocheck.Matches, `(?s).*-You should read this README.*\+Seriously, read this file!.*`) + c.Assert(err, check.IsNil) + c.Assert(string(diff), check.Matches, `(?s).*-You should read this README.*\+Seriously, read this file!.*`) } -func (s *S) TestGetDiffIntegrationWhenInvalidRepo(c *gocheck.C) { +func (s *S) TestGetDiffIntegrationWhenInvalidRepo(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -1392,21 +1392,21 @@ func (s *S) TestGetDiffIntegrationWhenInvalidRepo(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) errCreateCommit := CreateCommit(bare, repo, file, object1) - c.Assert(errCreateCommit, gocheck.IsNil) + c.Assert(errCreateCommit, check.IsNil) firstHashCommit, err := GetLastHashCommit(bare, repo) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) errCreateCommit = CreateCommit(bare, repo, file, object2) - c.Assert(errCreateCommit, gocheck.IsNil) + c.Assert(errCreateCommit, check.IsNil) secondHashCommit, err := GetLastHashCommit(bare, repo) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) expectedErr := fmt.Sprintf("Error when trying to obtain diff with commits %s and %s of repository invalid-repo (Repository does not exist).", secondHashCommit, firstHashCommit) _, err = GetDiff("invalid-repo", string(firstHashCommit), string(secondHashCommit)) - c.Assert(err.Error(), gocheck.Equals, expectedErr) + c.Assert(err.Error(), check.Equals, expectedErr) } -func (s *S) TestGetDiffIntegrationWhenInvalidCommit(c *gocheck.C) { +func (s *S) TestGetDiffIntegrationWhenInvalidCommit(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -1418,17 +1418,17 @@ func (s *S) TestGetDiffIntegrationWhenInvalidCommit(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) errCreateCommit := CreateCommit(bare, repo, file, object1) - c.Assert(errCreateCommit, gocheck.IsNil) + c.Assert(errCreateCommit, check.IsNil) firstHashCommit, err := GetLastHashCommit(bare, repo) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) expectedErr := fmt.Sprintf("Error when trying to obtain diff with commits %s and 12beu23eu23923ey32eiyeg2ye of repository %s (exit status 128).", firstHashCommit, repo) _, err = GetDiff(repo, "12beu23eu23923ey32eiyeg2ye", string(firstHashCommit)) - c.Assert(err.Error(), gocheck.Equals, expectedErr) + c.Assert(err.Error(), check.Equals, expectedErr) } -func (s *S) TestGetTagsIntegration(c *gocheck.C) { +func (s *S) TestGetTagsIntegration(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo-tags" @@ -1439,44 +1439,44 @@ func (s *S) TestGetTagsIntegration(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) testPath := path.Join(bare, repo+".git") errCreateTag := CreateTag(testPath, "0.1") - c.Assert(errCreateTag, gocheck.IsNil) + c.Assert(errCreateTag, check.IsNil) errCreateCommit := CreateCommit(bare, repo, "", "") - c.Assert(errCreateCommit, gocheck.IsNil) + c.Assert(errCreateCommit, check.IsNil) errCreateTag = CreateTag(testPath, "0.2") - c.Assert(errCreateTag, gocheck.IsNil) + c.Assert(errCreateTag, check.IsNil) tags, err := GetTags(repo) - c.Assert(err, gocheck.IsNil) - c.Assert(tags[0].Ref, gocheck.Matches, "[a-f0-9]{40}") - c.Assert(tags[0].Name, gocheck.Equals, "0.1") - c.Assert(tags[0].Committer.Name, gocheck.Equals, "doge") - c.Assert(tags[0].Committer.Email, gocheck.Equals, "") - c.Assert(tags[0].Author.Name, gocheck.Equals, "doge") - c.Assert(tags[0].Author.Email, gocheck.Equals, "") - c.Assert(tags[0].Subject, gocheck.Equals, "much WOW") - c.Assert(tags[0].CreatedAt, gocheck.Equals, tags[0].Author.Date) - c.Assert(tags[0].Links.ZipArchive, gocheck.Equals, GetArchiveUrl(repo, "0.1", "zip")) - c.Assert(tags[0].Links.TarArchive, gocheck.Equals, GetArchiveUrl(repo, "0.1", "tar.gz")) - c.Assert(tags[1].Ref, gocheck.Matches, "[a-f0-9]{40}") - c.Assert(tags[1].Name, gocheck.Equals, "0.2") - c.Assert(tags[1].Committer.Name, gocheck.Equals, "doge") - c.Assert(tags[1].Committer.Email, gocheck.Equals, "") - c.Assert(tags[1].Author.Name, gocheck.Equals, "doge") - c.Assert(tags[1].Author.Email, gocheck.Equals, "") - c.Assert(tags[1].Subject, gocheck.Equals, "") - c.Assert(tags[1].Links.ZipArchive, gocheck.Equals, GetArchiveUrl(repo, "0.2", "zip")) - c.Assert(tags[1].Links.TarArchive, gocheck.Equals, GetArchiveUrl(repo, "0.2", "tar.gz")) - c.Assert(tags[1].CreatedAt, gocheck.Equals, tags[1].Author.Date) -} - -func (s *S) TestGetArchiveUrl(c *gocheck.C) { + c.Assert(err, check.IsNil) + c.Assert(tags[0].Ref, check.Matches, "[a-f0-9]{40}") + c.Assert(tags[0].Name, check.Equals, "0.1") + c.Assert(tags[0].Committer.Name, check.Equals, "doge") + c.Assert(tags[0].Committer.Email, check.Equals, "") + c.Assert(tags[0].Author.Name, check.Equals, "doge") + c.Assert(tags[0].Author.Email, check.Equals, "") + c.Assert(tags[0].Subject, check.Equals, "much WOW") + c.Assert(tags[0].CreatedAt, check.Equals, tags[0].Author.Date) + c.Assert(tags[0].Links.ZipArchive, check.Equals, GetArchiveUrl(repo, "0.1", "zip")) + c.Assert(tags[0].Links.TarArchive, check.Equals, GetArchiveUrl(repo, "0.1", "tar.gz")) + c.Assert(tags[1].Ref, check.Matches, "[a-f0-9]{40}") + c.Assert(tags[1].Name, check.Equals, "0.2") + c.Assert(tags[1].Committer.Name, check.Equals, "doge") + c.Assert(tags[1].Committer.Email, check.Equals, "") + c.Assert(tags[1].Author.Name, check.Equals, "doge") + c.Assert(tags[1].Author.Email, check.Equals, "") + c.Assert(tags[1].Subject, check.Equals, "") + c.Assert(tags[1].Links.ZipArchive, check.Equals, GetArchiveUrl(repo, "0.2", "zip")) + c.Assert(tags[1].Links.TarArchive, check.Equals, GetArchiveUrl(repo, "0.2", "tar.gz")) + c.Assert(tags[1].CreatedAt, check.Equals, tags[1].Author.Date) +} + +func (s *S) TestGetArchiveUrl(c *check.C) { url := GetArchiveUrl("repo", "ref", "zip") - c.Assert(url, gocheck.Equals, fmt.Sprintf("/repository/%s/archive?ref=%s&format=%s", "repo", "ref", "zip")) + c.Assert(url, check.Equals, fmt.Sprintf("/repository/%s/archive?ref=%s&format=%s", "repo", "ref", "zip")) } -func (s *S) TestTempCloneIntegration(c *gocheck.C) { +func (s *S) TestTempCloneIntegration(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo-clone" @@ -1487,30 +1487,30 @@ func (s *S) TestTempCloneIntegration(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) clone, cloneCleanUp, errClone := TempClone(repo) if cloneCleanUp != nil { defer cloneCleanUp() } - c.Assert(errClone, gocheck.IsNil) + c.Assert(errClone, check.IsNil) dstat, errStat := os.Stat(clone) - c.Assert(dstat.IsDir(), gocheck.Equals, true) + c.Assert(dstat.IsDir(), check.Equals, true) fstat, errStat := os.Stat(path.Join(clone, file)) - c.Assert(fstat.IsDir(), gocheck.Equals, false) - c.Assert(errStat, gocheck.IsNil) + c.Assert(fstat.IsDir(), check.Equals, false) + c.Assert(errStat, check.IsNil) } -func (s *S) TestTempCloneWhenRepoInvalid(c *gocheck.C) { +func (s *S) TestTempCloneWhenRepoInvalid(c *check.C) { clone, cloneCleanUp, err := TempClone("invalid-repo") if cloneCleanUp != nil { defer cloneCleanUp() } - c.Assert(err.Error(), gocheck.Equals, "Error when trying to clone repository invalid-repo (Repository does not exist).") - c.Assert(cloneCleanUp, gocheck.IsNil) - c.Assert(clone, gocheck.HasLen, 0) + c.Assert(err.Error(), check.Equals, "Error when trying to clone repository invalid-repo (Repository does not exist).") + c.Assert(cloneCleanUp, check.IsNil) + c.Assert(clone, check.HasLen, 0) } -func (s *S) TestTempCloneWhenGitError(c *gocheck.C) { +func (s *S) TestTempCloneWhenGitError(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo-clone" @@ -1520,24 +1520,24 @@ func (s *S) TestTempCloneWhenGitError(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) tmpdir, err := commandmocker.Error("git", "much error", 1) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(tmpdir) clone, cloneCleanUp, errClone := TempClone(repo) if cloneCleanUp != nil { defer cloneCleanUp() } expectedErr := fmt.Sprintf("Error when trying to clone repository %s into %s (exit status 1 [much error]).", repo, clone) - c.Assert(errClone.Error(), gocheck.Equals, expectedErr) + c.Assert(errClone.Error(), check.Equals, expectedErr) dstat, errStat := os.Stat(clone) - c.Assert(dstat.IsDir(), gocheck.Equals, true) + c.Assert(dstat.IsDir(), check.Equals, true) fstat, errStat := os.Stat(path.Join(clone, file)) - c.Assert(fstat, gocheck.IsNil) - c.Assert(errStat, gocheck.NotNil) + c.Assert(fstat, check.IsNil) + c.Assert(errStat, check.NotNil) } -func (s *S) TestSetCommitterIntegration(c *gocheck.C) { +func (s *S) TestSetCommitterIntegration(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo-set-committer" @@ -1546,7 +1546,7 @@ func (s *S) TestSetCommitterIntegration(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) committer := GitUser{ Name: "committer", Email: "committer@globo.com", @@ -1555,30 +1555,30 @@ func (s *S) TestSetCommitterIntegration(c *gocheck.C) { if cloneCleanUp != nil { defer cloneCleanUp() } - c.Assert(errClone, gocheck.IsNil) + c.Assert(errClone, check.IsNil) b, errRead := ioutil.ReadFile(clone + "/.git/config") - c.Assert(errRead, gocheck.IsNil) - c.Assert(strings.Contains(string(b), "[user]"), gocheck.Equals, false) - c.Assert(strings.Contains(string(b), "name = committer"), gocheck.Equals, false) + c.Assert(errRead, check.IsNil) + c.Assert(strings.Contains(string(b), "[user]"), check.Equals, false) + c.Assert(strings.Contains(string(b), "name = committer"), check.Equals, false) errSetC := SetCommitter(clone, committer) - c.Assert(errSetC, gocheck.IsNil) + c.Assert(errSetC, check.IsNil) b, errRead = ioutil.ReadFile(clone + "/.git/config") - c.Assert(errRead, gocheck.IsNil) - c.Assert(strings.Contains(string(b), "[user]"), gocheck.Equals, true) - c.Assert(strings.Contains(string(b), "name = committer"), gocheck.Equals, true) - c.Assert(strings.Contains(string(b), "email = committer@globo.com"), gocheck.Equals, true) + c.Assert(errRead, check.IsNil) + c.Assert(strings.Contains(string(b), "[user]"), check.Equals, true) + c.Assert(strings.Contains(string(b), "name = committer"), check.Equals, true) + c.Assert(strings.Contains(string(b), "email = committer@globo.com"), check.Equals, true) } -func (s *S) TestSetCommitterWhenCloneInvalid(c *gocheck.C) { +func (s *S) TestSetCommitterWhenCloneInvalid(c *check.C) { committer := GitUser{ Name: "committer", Email: "committer@globo.com", } err := SetCommitter("invalid-repo", committer) - c.Assert(err.Error(), gocheck.Equals, "Error when trying to set committer of clone invalid-repo (Clone does not exist).") + c.Assert(err.Error(), check.Equals, "Error when trying to set committer of clone invalid-repo (Clone does not exist).") } -func (s *S) TestSetCommitterWhenGitError(c *gocheck.C) { +func (s *S) TestSetCommitterWhenGitError(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo-set-committer" @@ -1587,14 +1587,14 @@ func (s *S) TestSetCommitterWhenGitError(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) clone, cloneCleanUp, errClone := TempClone(repo) if cloneCleanUp != nil { defer cloneCleanUp() } - c.Assert(errClone, gocheck.IsNil) + c.Assert(errClone, check.IsNil) tmpdir, err := commandmocker.Error("git", "much error", 1) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(tmpdir) committer := GitUser{ Name: "committer", @@ -1602,14 +1602,14 @@ func (s *S) TestSetCommitterWhenGitError(c *gocheck.C) { } errSetC := SetCommitter(clone, committer) expectedErr := fmt.Sprintf("Error when trying to set committer of clone %s (Invalid committer name [much error]).", clone) - c.Assert(errSetC.Error(), gocheck.Equals, expectedErr) + c.Assert(errSetC.Error(), check.Equals, expectedErr) b, errRead := ioutil.ReadFile(clone + "/.git/config") - c.Assert(errRead, gocheck.IsNil) - c.Assert(strings.Contains(string(b), "[user]"), gocheck.Equals, false) - c.Assert(strings.Contains(string(b), "name = "), gocheck.Equals, false) + c.Assert(errRead, check.IsNil) + c.Assert(strings.Contains(string(b), "[user]"), check.Equals, false) + c.Assert(strings.Contains(string(b), "name = "), check.Equals, false) } -func (s *S) TestCheckoutIntegration(c *gocheck.C) { +func (s *S) TestCheckoutIntegration(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo-checkout" @@ -1620,24 +1620,24 @@ func (s *S) TestCheckoutIntegration(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) errCreateBranches := CreateBranchesOnTestRepository(bare, repo, "doge_bites") - c.Assert(errCreateBranches, gocheck.IsNil) + c.Assert(errCreateBranches, check.IsNil) branches, err := GetBranches(repo) - c.Assert(err, gocheck.IsNil) - c.Assert(branches, gocheck.HasLen, 2) + c.Assert(err, check.IsNil) + c.Assert(branches, check.HasLen, 2) clone, cloneCleanUp, errClone := TempClone(repo) if cloneCleanUp != nil { defer cloneCleanUp() } - c.Assert(errClone, gocheck.IsNil) + c.Assert(errClone, check.IsNil) errCheckout := Checkout(clone, "doge_bites", false) - c.Assert(errCheckout, gocheck.IsNil) + c.Assert(errCheckout, check.IsNil) errCheckout = Checkout(clone, "master", false) - c.Assert(errCheckout, gocheck.IsNil) + c.Assert(errCheckout, check.IsNil) } -func (s *S) TestCheckoutBareRepoIntegration(c *gocheck.C) { +func (s *S) TestCheckoutBareRepoIntegration(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo-checkout" @@ -1646,23 +1646,23 @@ func (s *S) TestCheckoutBareRepoIntegration(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) branches, err := GetBranches(repo) - c.Assert(err, gocheck.IsNil) - c.Assert(branches, gocheck.HasLen, 0) + c.Assert(err, check.IsNil) + c.Assert(branches, check.HasLen, 0) clone, cloneCleanUp, errClone := TempClone(repo) if cloneCleanUp != nil { defer cloneCleanUp() } - c.Assert(errClone, gocheck.IsNil) + c.Assert(errClone, check.IsNil) errCheckout := Checkout(clone, "doge_bites", false) expectedErr := fmt.Sprintf("Error when trying to checkout clone %s into branch doge_bites (exit status 1 [error: pathspec 'doge_bites' did not match any file(s) known to git.\n]).", clone) - c.Assert(errCheckout.Error(), gocheck.Equals, expectedErr) + c.Assert(errCheckout.Error(), check.Equals, expectedErr) errCheckout = Checkout(clone, "doge_bites", true) - c.Assert(errCheckout, gocheck.IsNil) + c.Assert(errCheckout, check.IsNil) } -func (s *S) TestCheckoutWhenBranchInvalid(c *gocheck.C) { +func (s *S) TestCheckoutWhenBranchInvalid(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo-checkout" @@ -1673,32 +1673,32 @@ func (s *S) TestCheckoutWhenBranchInvalid(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) errCreateBranches := CreateBranchesOnTestRepository(bare, repo, "doge_bites") - c.Assert(errCreateBranches, gocheck.IsNil) + c.Assert(errCreateBranches, check.IsNil) branches, err := GetBranches(repo) - c.Assert(err, gocheck.IsNil) - c.Assert(branches, gocheck.HasLen, 2) + c.Assert(err, check.IsNil) + c.Assert(branches, check.HasLen, 2) clone, cloneCleanUp, errClone := TempClone(repo) if cloneCleanUp != nil { defer cloneCleanUp() } - c.Assert(errClone, gocheck.IsNil) + c.Assert(errClone, check.IsNil) errCheckout := Checkout(clone, "doge_bites", false) - c.Assert(errCheckout, gocheck.IsNil) + c.Assert(errCheckout, check.IsNil) errCheckout = Checkout(clone, "master", false) - c.Assert(errCheckout, gocheck.IsNil) + c.Assert(errCheckout, check.IsNil) expectedErr := fmt.Sprintf("Error when trying to checkout clone %s into branch invalid_branch (exit status 1 [error: pathspec 'invalid_branch' did not match any file(s) known to git.\n]).", clone) errCheckout = Checkout(clone, "invalid_branch", false) - c.Assert(errCheckout.Error(), gocheck.Equals, expectedErr) + c.Assert(errCheckout.Error(), check.Equals, expectedErr) } -func (s *S) TestCheckoutWhenCloneInvalid(c *gocheck.C) { +func (s *S) TestCheckoutWhenCloneInvalid(c *check.C) { err := Checkout("invalid_clone", "doge_bites", false) - c.Assert(err.Error(), gocheck.Equals, "Error when trying to checkout clone invalid_clone into branch doge_bites (Clone does not exist).") + c.Assert(err.Error(), check.Equals, "Error when trying to checkout clone invalid_clone into branch doge_bites (Clone does not exist).") } -func (s *S) TestCheckoutWhenGitError(c *gocheck.C) { +func (s *S) TestCheckoutWhenGitError(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo-checkout" @@ -1709,23 +1709,23 @@ func (s *S) TestCheckoutWhenGitError(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) clone, cloneCleanUp, errClone := TempClone(repo) if cloneCleanUp != nil { defer cloneCleanUp() } - c.Assert(errClone, gocheck.IsNil) + c.Assert(errClone, check.IsNil) errCheckout := Checkout(clone, "master", false) - c.Assert(errCheckout, gocheck.IsNil) + c.Assert(errCheckout, check.IsNil) tmpdir, err := commandmocker.Error("git", "much error", 1) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(tmpdir) expectedErr := fmt.Sprintf("Error when trying to checkout clone %s into branch master (exit status 1 [much error]).", clone) errCheckout = Checkout(clone, "master", false) - c.Assert(errCheckout.Error(), gocheck.Equals, expectedErr) + c.Assert(errCheckout.Error(), check.Equals, expectedErr) } -func (s *S) TestAddAllIntegration(c *gocheck.C) { +func (s *S) TestAddAllIntegration(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo-add-all" @@ -1736,34 +1736,34 @@ func (s *S) TestAddAllIntegration(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) clone, cloneCleanUp, errClone := TempClone(repo) if cloneCleanUp != nil { defer cloneCleanUp() } - c.Assert(errClone, gocheck.IsNil) + c.Assert(errClone, check.IsNil) errWrite := ioutil.WriteFile(path.Join(clone, file), []byte(content+content), 0644) - c.Assert(errWrite, gocheck.IsNil) + c.Assert(errWrite, check.IsNil) errWrite = ioutil.WriteFile(clone+"/WOWME", []byte(content+content), 0644) - c.Assert(errWrite, gocheck.IsNil) + c.Assert(errWrite, check.IsNil) errAddAll := AddAll(clone) - c.Assert(errAddAll, gocheck.IsNil) + c.Assert(errAddAll, check.IsNil) gitPath, err := exec.LookPath("git") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) cmd := exec.Command(gitPath, "diff", "--staged", "--stat") cmd.Dir = clone out, err := cmd.CombinedOutput() - c.Assert(err, gocheck.IsNil) - c.Assert(strings.Contains(string(out), file), gocheck.Equals, true) - c.Assert(strings.Contains(string(out), "WOWME"), gocheck.Equals, true) + c.Assert(err, check.IsNil) + c.Assert(strings.Contains(string(out), file), check.Equals, true) + c.Assert(strings.Contains(string(out), "WOWME"), check.Equals, true) } -func (s *S) TestAddAllWhenCloneInvalid(c *gocheck.C) { +func (s *S) TestAddAllWhenCloneInvalid(c *check.C) { err := AddAll("invalid_clone") - c.Assert(err.Error(), gocheck.Equals, "Error when trying to add all to clone invalid_clone (Clone does not exist).") + c.Assert(err.Error(), check.Equals, "Error when trying to add all to clone invalid_clone (Clone does not exist).") } -func (s *S) TestAddAllWhenGitError(c *gocheck.C) { +func (s *S) TestAddAllWhenGitError(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo-add-all" @@ -1774,23 +1774,23 @@ func (s *S) TestAddAllWhenGitError(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) clone, cloneCleanUp, errClone := TempClone(repo) if cloneCleanUp != nil { defer cloneCleanUp() } - c.Assert(errClone, gocheck.IsNil) + c.Assert(errClone, check.IsNil) errAddAll := AddAll(clone) - c.Assert(errAddAll, gocheck.IsNil) + c.Assert(errAddAll, check.IsNil) tmpdir, err := commandmocker.Error("git", "much error", 1) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(tmpdir) expectedErr := fmt.Sprintf("Error when trying to add all to clone %s (exit status 1 [much error]).", clone) errAddAll = AddAll(clone) - c.Assert(errAddAll.Error(), gocheck.Equals, expectedErr) + c.Assert(errAddAll.Error(), check.Equals, expectedErr) } -func (s *S) TestCommitIntegration(c *gocheck.C) { +func (s *S) TestCommitIntegration(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo-commit" @@ -1801,23 +1801,23 @@ func (s *S) TestCommitIntegration(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) clone, cloneCleanUp, errClone := TempClone(repo) if cloneCleanUp != nil { defer cloneCleanUp() } - c.Assert(errClone, gocheck.IsNil) + c.Assert(errClone, check.IsNil) errWrite := ioutil.WriteFile(path.Join(clone, file), []byte(content+content), 0644) - c.Assert(errWrite, gocheck.IsNil) + c.Assert(errWrite, check.IsNil) gitPath, err := exec.LookPath("git") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) cmd := exec.Command(gitPath, "diff", "--stat") cmd.Dir = clone out, err := cmd.CombinedOutput() - c.Assert(err, gocheck.IsNil) - c.Assert(len(out) > 0, gocheck.Equals, true) + c.Assert(err, check.IsNil) + c.Assert(len(out) > 0, check.Equals, true) errAddAll := AddAll(clone) - c.Assert(errAddAll, gocheck.IsNil) + c.Assert(errAddAll, check.IsNil) committer := GitUser{ Name: "committer", Email: "committer@globo.com", @@ -1828,27 +1828,27 @@ func (s *S) TestCommitIntegration(c *gocheck.C) { } message := "commit message" errSetC := SetCommitter(clone, committer) - c.Assert(errSetC, gocheck.IsNil) + c.Assert(errSetC, check.IsNil) errCommit := Commit(clone, message, author) - c.Assert(errCommit, gocheck.IsNil) + c.Assert(errCommit, check.IsNil) cmd = exec.Command(gitPath, "diff") cmd.Dir = clone out, err = cmd.CombinedOutput() - c.Assert(err, gocheck.IsNil) - c.Assert(out, gocheck.HasLen, 0) + c.Assert(err, check.IsNil) + c.Assert(out, check.HasLen, 0) } -func (s *S) TestCommitWhenCloneInvalid(c *gocheck.C) { +func (s *S) TestCommitWhenCloneInvalid(c *check.C) { author := GitUser{ Name: "author", Email: "author@globo.com", } message := "commit message" err := Commit("invalid_clone", message, author) - c.Assert(err.Error(), gocheck.Equals, "Error when trying to commit to clone invalid_clone (Clone does not exist).") + c.Assert(err.Error(), check.Equals, "Error when trying to commit to clone invalid_clone (Clone does not exist).") } -func (s *S) TestCommitWhenGitError(c *gocheck.C) { +func (s *S) TestCommitWhenGitError(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo-add-all" @@ -1859,26 +1859,26 @@ func (s *S) TestCommitWhenGitError(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) clone, cloneCleanUp, errClone := TempClone(repo) if cloneCleanUp != nil { defer cloneCleanUp() } - c.Assert(errClone, gocheck.IsNil) + c.Assert(errClone, check.IsNil) author := GitUser{ Name: "author", Email: "author@globo.com", } message := "commit message" tmpdir, err := commandmocker.Error("git", "much error", 1) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(tmpdir) expectedErr := fmt.Sprintf("Error when trying to commit to clone %s (exit status 1 [much error]).", clone) errCommit := Commit(clone, message, author) - c.Assert(errCommit.Error(), gocheck.Equals, expectedErr) + c.Assert(errCommit.Error(), check.Equals, expectedErr) } -func (s *S) TestPushIntegration(c *gocheck.C) { +func (s *S) TestPushIntegration(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo-push" @@ -1889,16 +1889,16 @@ func (s *S) TestPushIntegration(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) clone, cloneCleanUp, errClone := TempClone(repo) if cloneCleanUp != nil { defer cloneCleanUp() } - c.Assert(errClone, gocheck.IsNil) + c.Assert(errClone, check.IsNil) errWrite := ioutil.WriteFile(path.Join(clone, file), []byte(content+content), 0644) - c.Assert(errWrite, gocheck.IsNil) + c.Assert(errWrite, check.IsNil) errAddAll := AddAll(clone) - c.Assert(errAddAll, gocheck.IsNil) + c.Assert(errAddAll, check.IsNil) committer := GitUser{ Name: "committer", Email: "committer@globo.com", @@ -1909,19 +1909,19 @@ func (s *S) TestPushIntegration(c *gocheck.C) { } message := "commit message" errSetC := SetCommitter(clone, committer) - c.Assert(errSetC, gocheck.IsNil) + c.Assert(errSetC, check.IsNil) errCommit := Commit(clone, message, author) - c.Assert(errCommit, gocheck.IsNil) + c.Assert(errCommit, check.IsNil) errPush := Push(clone, "master") - c.Assert(errPush, gocheck.IsNil) + c.Assert(errPush, check.IsNil) } -func (s *S) TestPushWhenCloneInvalid(c *gocheck.C) { +func (s *S) TestPushWhenCloneInvalid(c *check.C) { err := Push("invalid_clone", "master") - c.Assert(err.Error(), gocheck.Equals, "Error when trying to push clone invalid_clone into origin's master branch (Clone does not exist).") + c.Assert(err.Error(), check.Equals, "Error when trying to push clone invalid_clone into origin's master branch (Clone does not exist).") } -func (s *S) TestPushWhenGitError(c *gocheck.C) { +func (s *S) TestPushWhenGitError(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo-add-all" @@ -1932,21 +1932,21 @@ func (s *S) TestPushWhenGitError(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) clone, cloneCleanUp, errClone := TempClone(repo) if cloneCleanUp != nil { defer cloneCleanUp() } - c.Assert(errClone, gocheck.IsNil) + c.Assert(errClone, check.IsNil) tmpdir, err := commandmocker.Error("git", "much error", 1) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(tmpdir) expectedErr := fmt.Sprintf("Error when trying to push clone %s into origin's master branch (exit status 1 [much error]).", clone) errPush := Push(clone, "master") - c.Assert(errPush.Error(), gocheck.Equals, expectedErr) + c.Assert(errPush.Error(), check.Equals, expectedErr) } -func (s *S) TestCommitZipIntegration(c *gocheck.C) { +func (s *S) TestCommitZipIntegration(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo-push" @@ -1955,7 +1955,7 @@ func (s *S) TestCommitZipIntegration(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) boundary := "muchBOUNDARY" params := map[string]string{} var files = []multipartzip.File{ @@ -1964,14 +1964,14 @@ func (s *S) TestCommitZipIntegration(c *gocheck.C) { {"much/WOW.txt", "Much WOW"}, } buf, err := multipartzip.CreateZipBuffer(files) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) reader, writer := io.Pipe() go multipartzip.StreamWriteMultipartForm(params, "muchfile", "muchfile.zip", boundary, writer, buf) mpr := multipart.NewReader(reader, boundary) form, err := mpr.ReadForm(0) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) file, err := multipartzip.FileField(form, "muchfile") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) commit := GitCommit{ Message: "will bark", Author: GitUser{ @@ -1985,26 +1985,26 @@ func (s *S) TestCommitZipIntegration(c *gocheck.C) { Branch: "doge_barks", } ref, err := CommitZip(repo, file, commit) - c.Assert(err, gocheck.IsNil) - c.Assert(ref.Ref, gocheck.Matches, "[a-f0-9]{40}") - c.Assert(ref.Name, gocheck.Equals, "doge_barks") - c.Assert(ref.Committer.Name, gocheck.Equals, "committer") - c.Assert(ref.Committer.Email, gocheck.Equals, "") - c.Assert(ref.Author.Name, gocheck.Equals, "author") - c.Assert(ref.Author.Email, gocheck.Equals, "") - c.Assert(ref.Subject, gocheck.Equals, "will bark") + c.Assert(err, check.IsNil) + c.Assert(ref.Ref, check.Matches, "[a-f0-9]{40}") + c.Assert(ref.Name, check.Equals, "doge_barks") + c.Assert(ref.Committer.Name, check.Equals, "committer") + c.Assert(ref.Committer.Email, check.Equals, "") + c.Assert(ref.Author.Name, check.Equals, "author") + c.Assert(ref.Author.Email, check.Equals, "") + c.Assert(ref.Subject, check.Equals, "will bark") tree, err := GetTree(repo, "doge_barks", "") - c.Assert(err, gocheck.IsNil) - c.Assert(tree, gocheck.HasLen, 3) - c.Assert(tree[0]["path"], gocheck.Equals, "doge.txt") - c.Assert(tree[0]["rawPath"], gocheck.Equals, "doge.txt") - c.Assert(tree[1]["path"], gocheck.Equals, "much.txt") - c.Assert(tree[1]["rawPath"], gocheck.Equals, "much.txt") - c.Assert(tree[2]["path"], gocheck.Equals, "much/WOW.txt") - c.Assert(tree[2]["rawPath"], gocheck.Equals, "much/WOW.txt") + c.Assert(err, check.IsNil) + c.Assert(tree, check.HasLen, 3) + c.Assert(tree[0]["path"], check.Equals, "doge.txt") + c.Assert(tree[0]["rawPath"], check.Equals, "doge.txt") + c.Assert(tree[1]["path"], check.Equals, "much.txt") + c.Assert(tree[1]["rawPath"], check.Equals, "much.txt") + c.Assert(tree[2]["path"], check.Equals, "much/WOW.txt") + c.Assert(tree[2]["rawPath"], check.Equals, "much/WOW.txt") } -func (s *S) TestCommitZipIntegrationWhenFileEmpty(c *gocheck.C) { +func (s *S) TestCommitZipIntegrationWhenFileEmpty(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo-push" @@ -2013,16 +2013,16 @@ func (s *S) TestCommitZipIntegrationWhenFileEmpty(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) boundary := "muchBOUNDARY" params := map[string]string{} reader, writer := io.Pipe() go multipartzip.StreamWriteMultipartForm(params, "muchfile", "muchfile.zip", boundary, writer, nil) mpr := multipart.NewReader(reader, boundary) form, err := mpr.ReadForm(0) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) file, err := multipartzip.FileField(form, "muchfile") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) commit := GitCommit{ Message: "will bark", Author: GitUser{ @@ -2037,10 +2037,10 @@ func (s *S) TestCommitZipIntegrationWhenFileEmpty(c *gocheck.C) { } expectedErr := fmt.Sprintf("Error when trying to commit zip to repository %s, could not extract: zip: not a valid zip file", repo) _, err = CommitZip(repo, file, commit) - c.Assert(err.Error(), gocheck.Equals, expectedErr) + c.Assert(err.Error(), check.Equals, expectedErr) } -func (s *S) TestGetLogs(c *gocheck.C) { +func (s *S) TestGetLogs(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -2053,54 +2053,54 @@ func (s *S) TestGetLogs(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) errCreateCommit := CreateCommit(bare, repo, file, object1) - c.Assert(errCreateCommit, gocheck.IsNil) + c.Assert(errCreateCommit, check.IsNil) errCreateCommit = CreateCommit(bare, repo, file, object2) - c.Assert(errCreateCommit, gocheck.IsNil) + c.Assert(errCreateCommit, check.IsNil) history, err := GetLogs(repo, "HEAD", 1, "") - c.Assert(err, gocheck.IsNil) - c.Assert(history.Commits, gocheck.HasLen, 1) - c.Assert(history.Commits[0].Ref, gocheck.Matches, "[a-f0-9]{40}") - c.Assert(history.Commits[0].Parent, gocheck.HasLen, 1) - c.Assert(history.Commits[0].Parent[0], gocheck.Matches, "[a-f0-9]{40}") - c.Assert(history.Commits[0].Committer.Name, gocheck.Equals, "doge") - c.Assert(history.Commits[0].Committer.Email, gocheck.Equals, "much@email.com") - c.Assert(history.Commits[0].Author.Name, gocheck.Equals, "doge") - c.Assert(history.Commits[0].Author.Email, gocheck.Equals, "much@email.com") - c.Assert(history.Commits[0].Subject, gocheck.Equals, "Seriously, read this file!") - c.Assert(history.Commits[0].CreatedAt, gocheck.Equals, history.Commits[0].Author.Date) - c.Assert(history.Next, gocheck.Matches, "[a-f0-9]{40}") + c.Assert(err, check.IsNil) + c.Assert(history.Commits, check.HasLen, 1) + c.Assert(history.Commits[0].Ref, check.Matches, "[a-f0-9]{40}") + c.Assert(history.Commits[0].Parent, check.HasLen, 1) + c.Assert(history.Commits[0].Parent[0], check.Matches, "[a-f0-9]{40}") + c.Assert(history.Commits[0].Committer.Name, check.Equals, "doge") + c.Assert(history.Commits[0].Committer.Email, check.Equals, "much@email.com") + c.Assert(history.Commits[0].Author.Name, check.Equals, "doge") + c.Assert(history.Commits[0].Author.Email, check.Equals, "much@email.com") + c.Assert(history.Commits[0].Subject, check.Equals, "Seriously, read this file!") + c.Assert(history.Commits[0].CreatedAt, check.Equals, history.Commits[0].Author.Date) + c.Assert(history.Next, check.Matches, "[a-f0-9]{40}") // Next history, err = GetLogs(repo, history.Next, 1, "") - c.Assert(err, gocheck.IsNil) - c.Assert(history.Commits, gocheck.HasLen, 1) - c.Assert(history.Commits[0].Ref, gocheck.Matches, "[a-f0-9]{40}") - c.Assert(history.Commits[0].Parent, gocheck.HasLen, 1) - c.Assert(history.Commits[0].Parent[0], gocheck.Matches, "[a-f0-9]{40}") - c.Assert(history.Commits[0].Committer.Name, gocheck.Equals, "doge") - c.Assert(history.Commits[0].Committer.Email, gocheck.Equals, "much@email.com") - c.Assert(history.Commits[0].Author.Name, gocheck.Equals, "doge") - c.Assert(history.Commits[0].Author.Email, gocheck.Equals, "much@email.com") - c.Assert(history.Commits[0].Subject, gocheck.Equals, "You should read this README") - c.Assert(history.Commits[0].CreatedAt, gocheck.Equals, history.Commits[0].Author.Date) - c.Assert(history.Next, gocheck.Matches, "[a-f0-9]{40}") + c.Assert(err, check.IsNil) + c.Assert(history.Commits, check.HasLen, 1) + c.Assert(history.Commits[0].Ref, check.Matches, "[a-f0-9]{40}") + c.Assert(history.Commits[0].Parent, check.HasLen, 1) + c.Assert(history.Commits[0].Parent[0], check.Matches, "[a-f0-9]{40}") + c.Assert(history.Commits[0].Committer.Name, check.Equals, "doge") + c.Assert(history.Commits[0].Committer.Email, check.Equals, "much@email.com") + c.Assert(history.Commits[0].Author.Name, check.Equals, "doge") + c.Assert(history.Commits[0].Author.Email, check.Equals, "much@email.com") + c.Assert(history.Commits[0].Subject, check.Equals, "You should read this README") + c.Assert(history.Commits[0].CreatedAt, check.Equals, history.Commits[0].Author.Date) + c.Assert(history.Next, check.Matches, "[a-f0-9]{40}") // Next history, err = GetLogs(repo, history.Next, 1, "") - c.Assert(err, gocheck.IsNil) - c.Assert(history.Commits, gocheck.HasLen, 1) - c.Assert(history.Commits[0].Ref, gocheck.Matches, "[a-f0-9]{40}") - c.Assert(history.Commits[0].Parent, gocheck.HasLen, 0) - c.Assert(history.Commits[0].Committer.Name, gocheck.Equals, "doge") - c.Assert(history.Commits[0].Committer.Email, gocheck.Equals, "much@email.com") - c.Assert(history.Commits[0].Author.Name, gocheck.Equals, "doge") - c.Assert(history.Commits[0].Author.Email, gocheck.Equals, "much@email.com") - c.Assert(history.Commits[0].Subject, gocheck.Equals, "will\tbark") - c.Assert(history.Commits[0].CreatedAt, gocheck.Equals, history.Commits[0].Author.Date) - c.Assert(history.Next, gocheck.Equals, "") -} - -func (s *S) TestGetLogsWithFile(c *gocheck.C) { + c.Assert(err, check.IsNil) + c.Assert(history.Commits, check.HasLen, 1) + c.Assert(history.Commits[0].Ref, check.Matches, "[a-f0-9]{40}") + c.Assert(history.Commits[0].Parent, check.HasLen, 0) + c.Assert(history.Commits[0].Committer.Name, check.Equals, "doge") + c.Assert(history.Commits[0].Committer.Email, check.Equals, "much@email.com") + c.Assert(history.Commits[0].Author.Name, check.Equals, "doge") + c.Assert(history.Commits[0].Author.Email, check.Equals, "much@email.com") + c.Assert(history.Commits[0].Subject, check.Equals, "will\tbark") + c.Assert(history.Commits[0].CreatedAt, check.Equals, history.Commits[0].Author.Date) + c.Assert(history.Next, check.Equals, "") +} + +func (s *S) TestGetLogsWithFile(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -2113,27 +2113,27 @@ func (s *S) TestGetLogsWithFile(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) errCreateCommit := CreateCommit(bare, repo, file, object1) - c.Assert(errCreateCommit, gocheck.IsNil) + c.Assert(errCreateCommit, check.IsNil) errCreateCommit = CreateCommit(bare, repo, file, object2) - c.Assert(errCreateCommit, gocheck.IsNil) + c.Assert(errCreateCommit, check.IsNil) history, err := GetLogs(repo, "master", 1, "README") - c.Assert(err, gocheck.IsNil) - c.Assert(history.Commits, gocheck.HasLen, 1) - c.Assert(history.Commits[0].Ref, gocheck.Matches, "[a-f0-9]{40}") - c.Assert(history.Commits[0].Parent, gocheck.HasLen, 1) - c.Assert(history.Commits[0].Parent[0], gocheck.Matches, "[a-f0-9]{40}") - c.Assert(history.Commits[0].Committer.Name, gocheck.Equals, "doge") - c.Assert(history.Commits[0].Committer.Email, gocheck.Equals, "much@email.com") - c.Assert(history.Commits[0].Author.Name, gocheck.Equals, "doge") - c.Assert(history.Commits[0].Author.Email, gocheck.Equals, "much@email.com") - c.Assert(history.Commits[0].Subject, gocheck.Equals, "Seriously, read this file!") - c.Assert(history.Commits[0].CreatedAt, gocheck.Equals, history.Commits[0].Author.Date) - c.Assert(history.Next, gocheck.Matches, "[a-f0-9]{40}") -} - -func (s *S) TestGetLogsWithFileAndEmptyParameters(c *gocheck.C) { + c.Assert(err, check.IsNil) + c.Assert(history.Commits, check.HasLen, 1) + c.Assert(history.Commits[0].Ref, check.Matches, "[a-f0-9]{40}") + c.Assert(history.Commits[0].Parent, check.HasLen, 1) + c.Assert(history.Commits[0].Parent[0], check.Matches, "[a-f0-9]{40}") + c.Assert(history.Commits[0].Committer.Name, check.Equals, "doge") + c.Assert(history.Commits[0].Committer.Email, check.Equals, "much@email.com") + c.Assert(history.Commits[0].Author.Name, check.Equals, "doge") + c.Assert(history.Commits[0].Author.Email, check.Equals, "much@email.com") + c.Assert(history.Commits[0].Subject, check.Equals, "Seriously, read this file!") + c.Assert(history.Commits[0].CreatedAt, check.Equals, history.Commits[0].Author.Date) + c.Assert(history.Next, check.Matches, "[a-f0-9]{40}") +} + +func (s *S) TestGetLogsWithFileAndEmptyParameters(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -2144,22 +2144,22 @@ func (s *S) TestGetLogsWithFileAndEmptyParameters(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) history, err := GetLogs(repo, "", 0, "") - c.Assert(err, gocheck.IsNil) - c.Assert(history.Commits, gocheck.HasLen, 1) - c.Assert(history.Commits[0].Ref, gocheck.Matches, "[a-f0-9]{40}") - c.Assert(history.Commits[0].Parent, gocheck.HasLen, 0) - c.Assert(history.Commits[0].Committer.Name, gocheck.Equals, "doge") - c.Assert(history.Commits[0].Committer.Email, gocheck.Equals, "much@email.com") - c.Assert(history.Commits[0].Author.Name, gocheck.Equals, "doge") - c.Assert(history.Commits[0].Author.Email, gocheck.Equals, "much@email.com") - c.Assert(history.Commits[0].Subject, gocheck.Equals, "will bark") - c.Assert(history.Commits[0].CreatedAt, gocheck.Equals, history.Commits[0].Author.Date) - c.Assert(history.Next, gocheck.Equals, "") -} - -func (s *S) TestGetLogsWithAllSortsOfSubjects(c *gocheck.C) { + c.Assert(err, check.IsNil) + c.Assert(history.Commits, check.HasLen, 1) + c.Assert(history.Commits[0].Ref, check.Matches, "[a-f0-9]{40}") + c.Assert(history.Commits[0].Parent, check.HasLen, 0) + c.Assert(history.Commits[0].Committer.Name, check.Equals, "doge") + c.Assert(history.Commits[0].Committer.Email, check.Equals, "much@email.com") + c.Assert(history.Commits[0].Author.Name, check.Equals, "doge") + c.Assert(history.Commits[0].Author.Email, check.Equals, "much@email.com") + c.Assert(history.Commits[0].Subject, check.Equals, "will bark") + c.Assert(history.Commits[0].CreatedAt, check.Equals, history.Commits[0].Author.Date) + c.Assert(history.Next, check.Equals, "") +} + +func (s *S) TestGetLogsWithAllSortsOfSubjects(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -2172,44 +2172,44 @@ func (s *S) TestGetLogsWithAllSortsOfSubjects(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) errCreateCommit := CreateCommit(bare, repo, file, content2) - c.Assert(errCreateCommit, gocheck.IsNil) + c.Assert(errCreateCommit, check.IsNil) errCreateCommit = CreateCommit(bare, repo, file, content3) - c.Assert(errCreateCommit, gocheck.IsNil) + c.Assert(errCreateCommit, check.IsNil) history, err := GetLogs(repo, "master", 3, "README") - c.Assert(err, gocheck.IsNil) - c.Assert(history.Commits, gocheck.HasLen, 3) - c.Assert(history.Commits[0].Ref, gocheck.Matches, "[a-f0-9]{40}") - c.Assert(history.Commits[0].Parent, gocheck.HasLen, 1) - c.Assert(history.Commits[0].Parent[0], gocheck.Matches, "[a-f0-9]{40}") - c.Assert(history.Commits[0].Committer.Name, gocheck.Equals, "doge") - c.Assert(history.Commits[0].Committer.Email, gocheck.Equals, "much@email.com") - c.Assert(history.Commits[0].Author.Name, gocheck.Equals, "doge") - c.Assert(history.Commits[0].Author.Email, gocheck.Equals, "much@email.com") - c.Assert(history.Commits[0].Subject, gocheck.Equals, "will bark") - c.Assert(history.Commits[0].CreatedAt, gocheck.Equals, history.Commits[0].Author.Date) - c.Assert(history.Commits[1].Ref, gocheck.Matches, "[a-f0-9]{40}") - c.Assert(history.Commits[1].Parent, gocheck.HasLen, 1) - c.Assert(history.Commits[1].Parent[0], gocheck.Matches, "[a-f0-9]{40}") - c.Assert(history.Commits[1].Committer.Name, gocheck.Equals, "doge") - c.Assert(history.Commits[1].Committer.Email, gocheck.Equals, "much@email.com") - c.Assert(history.Commits[1].Author.Name, gocheck.Equals, "doge") - c.Assert(history.Commits[1].Author.Email, gocheck.Equals, "much@email.com") - c.Assert(history.Commits[1].Subject, gocheck.Equals, "will\tbark") - c.Assert(history.Commits[1].CreatedAt, gocheck.Equals, history.Commits[1].Author.Date) - c.Assert(history.Commits[2].Ref, gocheck.Matches, "[a-f0-9]{40}") - c.Assert(history.Commits[2].Parent, gocheck.HasLen, 0) - c.Assert(history.Commits[2].Committer.Name, gocheck.Equals, "doge") - c.Assert(history.Commits[2].Committer.Email, gocheck.Equals, "much@email.com") - c.Assert(history.Commits[2].Author.Name, gocheck.Equals, "doge") - c.Assert(history.Commits[2].Author.Email, gocheck.Equals, "much@email.com") - c.Assert(history.Commits[2].Subject, gocheck.Equals, "") - c.Assert(history.Commits[2].CreatedAt, gocheck.Equals, history.Commits[2].Author.Date) - c.Assert(history.Next, gocheck.Equals, "") -} - -func (s *S) TestGetLogsWhenOutputInvalid(c *gocheck.C) { + c.Assert(err, check.IsNil) + c.Assert(history.Commits, check.HasLen, 3) + c.Assert(history.Commits[0].Ref, check.Matches, "[a-f0-9]{40}") + c.Assert(history.Commits[0].Parent, check.HasLen, 1) + c.Assert(history.Commits[0].Parent[0], check.Matches, "[a-f0-9]{40}") + c.Assert(history.Commits[0].Committer.Name, check.Equals, "doge") + c.Assert(history.Commits[0].Committer.Email, check.Equals, "much@email.com") + c.Assert(history.Commits[0].Author.Name, check.Equals, "doge") + c.Assert(history.Commits[0].Author.Email, check.Equals, "much@email.com") + c.Assert(history.Commits[0].Subject, check.Equals, "will bark") + c.Assert(history.Commits[0].CreatedAt, check.Equals, history.Commits[0].Author.Date) + c.Assert(history.Commits[1].Ref, check.Matches, "[a-f0-9]{40}") + c.Assert(history.Commits[1].Parent, check.HasLen, 1) + c.Assert(history.Commits[1].Parent[0], check.Matches, "[a-f0-9]{40}") + c.Assert(history.Commits[1].Committer.Name, check.Equals, "doge") + c.Assert(history.Commits[1].Committer.Email, check.Equals, "much@email.com") + c.Assert(history.Commits[1].Author.Name, check.Equals, "doge") + c.Assert(history.Commits[1].Author.Email, check.Equals, "much@email.com") + c.Assert(history.Commits[1].Subject, check.Equals, "will\tbark") + c.Assert(history.Commits[1].CreatedAt, check.Equals, history.Commits[1].Author.Date) + c.Assert(history.Commits[2].Ref, check.Matches, "[a-f0-9]{40}") + c.Assert(history.Commits[2].Parent, check.HasLen, 0) + c.Assert(history.Commits[2].Committer.Name, check.Equals, "doge") + c.Assert(history.Commits[2].Committer.Email, check.Equals, "much@email.com") + c.Assert(history.Commits[2].Author.Name, check.Equals, "doge") + c.Assert(history.Commits[2].Author.Email, check.Equals, "much@email.com") + c.Assert(history.Commits[2].Subject, check.Equals, "") + c.Assert(history.Commits[2].CreatedAt, check.Equals, history.Commits[2].Author.Date) + c.Assert(history.Next, check.Equals, "") +} + +func (s *S) TestGetLogsWhenOutputInvalid(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -2220,15 +2220,15 @@ func (s *S) TestGetLogsWhenOutputInvalid(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) tmpdir, err := commandmocker.Add("git", "-") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(tmpdir) _, err = GetLogs(repo, "master", 3, "README") - c.Assert(err.Error(), gocheck.Equals, "Error when trying to obtain the log of repository gandalf-test-repo (Invalid git log output [-]).") + c.Assert(err.Error(), check.Equals, "Error when trying to obtain the log of repository gandalf-test-repo (Invalid git log output [-]).") } -func (s *S) TestGetLogsWhenOutputEmpty(c *gocheck.C) { +func (s *S) TestGetLogsWhenOutputEmpty(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -2239,17 +2239,17 @@ func (s *S) TestGetLogsWhenOutputEmpty(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) tmpdir, err := commandmocker.Add("git", "\n") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(tmpdir) history, err := GetLogs(repo, "master", 1, "README") - c.Assert(err, gocheck.IsNil) - c.Assert(history.Commits, gocheck.HasLen, 0) - c.Assert(history.Next, gocheck.HasLen, 0) + c.Assert(err, check.IsNil) + c.Assert(history.Commits, check.HasLen, 0) + c.Assert(history.Next, check.HasLen, 0) } -func (s *S) TestGetLogsWhenGitError(c *gocheck.C) { +func (s *S) TestGetLogsWhenGitError(c *check.C) { oldBare := bare bare = "/tmp" repo := "gandalf-test-repo" @@ -2260,17 +2260,17 @@ func (s *S) TestGetLogsWhenGitError(c *gocheck.C) { cleanUp() bare = oldBare }() - c.Assert(errCreate, gocheck.IsNil) + c.Assert(errCreate, check.IsNil) tmpdir, err := commandmocker.Error("git", "much error", 1) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer commandmocker.Remove(tmpdir) expectedErr := fmt.Sprintf("Error when trying to obtain the log of repository %s (exit status 1).", repo) _, err = GetLogs(repo, "master", 1, "README") - c.Assert(err.Error(), gocheck.Equals, expectedErr) + c.Assert(err.Error(), check.Equals, expectedErr) } -func (s *S) TestGetLogsWhenRepoInvalid(c *gocheck.C) { +func (s *S) TestGetLogsWhenRepoInvalid(c *check.C) { expectedErr := fmt.Sprintf("Error when trying to obtain the log of repository invalid-repo (Repository does not exist).") _, err := GetLogs("invalid-repo", "master", 1, "README") - c.Assert(err.Error(), gocheck.Equals, expectedErr) + c.Assert(err.Error(), check.Equals, expectedErr) } diff --git a/user/key_test.go b/user/key_test.go index e409ac8..732c607 100644 --- a/user/key_test.go +++ b/user/key_test.go @@ -1,4 +1,4 @@ -// Copyright 2014 gandalf authors. All rights reserved. +// Copyright 2015 gandalf authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -17,8 +17,8 @@ import ( "github.com/tsuru/config" "github.com/tsuru/gandalf/db" + "gopkg.in/check.v1" "gopkg.in/mgo.v2/bson" - "launchpad.net/gocheck" ) type shortWriter struct{} @@ -38,50 +38,50 @@ const body = "ssh-dss AAAAB3NzaC1kc3MAAACBAIHfSDLpSCfIIVEJ/Is3RFMQhsCi7WZtFQeeyf const comment = "f@xikinbook.local" const otherKey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCaNZSIEyP6FSdCX0WHDcUFTvebNbvqKiiLEiC7NTGvKrT15r2MtCDi4EPi4Ul+UyxWqb2D7FBnK1UmIcEFHd/ZCnBod2/FSplGOIbIb2UVVbqPX5Alv7IBCMyZJD14ex5cFh16zoqOsPOkOD803LMIlNvXPDDwKjY4TVOQV1JtA2tbZXvYUchqhTcKPxt5BDBZbeQkMMgUgHIEz6IueglFB3+dIZfrzlmM8CVSElKZOpucnJ5JOpGh3paSO/px2ZEcvY8WvjFdipvAWsis75GG/04F641I6XmYlo9fib/YytBXS23szqmvOqEqAopFnnGkDEo+LWI0+FXgPE8lc5BD" -func (s *S) TestNewKey(c *gocheck.C) { +func (s *S) TestNewKey(c *check.C) { k, err := newKey("key1", "me@tsuru.io", rawKey) - c.Assert(err, gocheck.IsNil) - c.Assert(k.Name, gocheck.Equals, "key1") - c.Assert(k.Body, gocheck.Equals, body) - c.Assert(k.Comment, gocheck.Equals, comment) - c.Assert(k.UserName, gocheck.Equals, "me@tsuru.io") + c.Assert(err, check.IsNil) + c.Assert(k.Name, check.Equals, "key1") + c.Assert(k.Body, check.Equals, body) + c.Assert(k.Comment, check.Equals, comment) + c.Assert(k.UserName, check.Equals, "me@tsuru.io") } -func (s *S) TestNewKeyInvalidKey(c *gocheck.C) { +func (s *S) TestNewKeyInvalidKey(c *check.C) { raw := "ssh-dss ASCCDD== invalid@tsuru.io" k, err := newKey("key1", "me@tsuru.io", raw) - c.Assert(k, gocheck.IsNil) - c.Assert(err, gocheck.Equals, ErrInvalidKey) + c.Assert(k, check.IsNil) + c.Assert(err, check.Equals, ErrInvalidKey) } -func (s *S) TestNewKeyCreatedAtStoresCurrentTime(c *gocheck.C) { +func (s *S) TestNewKeyCreatedAtStoresCurrentTime(c *check.C) { k, err := newKey("key1", "me@tsuru.io", rawKey) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) gotY, gotM, gotD := k.CreatedAt.Date() y, m, d := time.Now().Date() - c.Assert(gotY, gocheck.Equals, y) - c.Assert(gotM, gocheck.Equals, m) - c.Assert(gotD, gocheck.Equals, d) - c.Assert(k.CreatedAt.Hour(), gocheck.Equals, time.Now().Hour()) - c.Assert(k.CreatedAt.Minute(), gocheck.Equals, time.Now().Minute()) + c.Assert(gotY, check.Equals, y) + c.Assert(gotM, check.Equals, m) + c.Assert(gotD, check.Equals, d) + c.Assert(k.CreatedAt.Hour(), check.Equals, time.Now().Hour()) + c.Assert(k.CreatedAt.Minute(), check.Equals, time.Now().Minute()) } -func (s *S) TestKeyString(c *gocheck.C) { +func (s *S) TestKeyString(c *check.C) { k := Key{Body: "ssh-dss not-secret", Comment: "me@host"} - c.Assert(k.String(), gocheck.Equals, k.Body+" "+k.Comment) + c.Assert(k.String(), check.Equals, k.Body+" "+k.Comment) } -func (s *S) TestKeyStringNewLine(c *gocheck.C) { +func (s *S) TestKeyStringNewLine(c *check.C) { k := Key{Body: "ssh-dss not-secret\n", Comment: "me@host"} - c.Assert(k.String(), gocheck.Equals, "ssh-dss not-secret me@host") + c.Assert(k.String(), check.Equals, "ssh-dss not-secret me@host") } -func (s *S) TestKeyStringNoComment(c *gocheck.C) { +func (s *S) TestKeyStringNoComment(c *check.C) { k := Key{Body: "ssh-dss not-secret"} - c.Assert(k.String(), gocheck.Equals, k.Body) + c.Assert(k.String(), check.Equals, k.Body) } -func (s *S) TestFormatKeyShouldAddSshLoginRestrictionsAtBegining(c *gocheck.C) { +func (s *S) TestFormatKeyShouldAddSshLoginRestrictionsAtBegining(c *check.C) { key := Key{ Name: "my-key", Body: "somekey\n", @@ -90,10 +90,10 @@ func (s *S) TestFormatKeyShouldAddSshLoginRestrictionsAtBegining(c *gocheck.C) { } got := key.format() expected := fmt.Sprintf("no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty,command=.* %s\n", &key) - c.Assert(got, gocheck.Matches, expected) + c.Assert(got, check.Matches, expected) } -func (s *S) TestFormatKeyShouldAddCommandAfterSshRestrictions(c *gocheck.C) { +func (s *S) TestFormatKeyShouldAddCommandAfterSshRestrictions(c *check.C) { key := Key{ Name: "my-key", Body: "somekey\n", @@ -102,14 +102,14 @@ func (s *S) TestFormatKeyShouldAddCommandAfterSshRestrictions(c *gocheck.C) { } got := key.format() p, err := config.GetString("bin-path") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) expected := fmt.Sprintf(`no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty,command="%s brain" %s`+"\n", p, &key) - c.Assert(got, gocheck.Equals, expected) + c.Assert(got, check.Equals, expected) } -func (s *S) TestFormatKeyShouldGetCommandPathFromGandalfConf(c *gocheck.C) { +func (s *S) TestFormatKeyShouldGetCommandPathFromGandalfConf(c *check.C) { oldConf, err := config.GetString("bin-path") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) config.Set("bin-path", "/foo/bar/hi.go") defer config.Set("bin-path", oldConf) key := Key{ @@ -120,12 +120,12 @@ func (s *S) TestFormatKeyShouldGetCommandPathFromGandalfConf(c *gocheck.C) { } got := key.format() expected := fmt.Sprintf(`no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty,command="/foo/bar/hi.go dash" %s`+"\n", &key) - c.Assert(got, gocheck.Equals, expected) + c.Assert(got, check.Equals, expected) } -func (s *S) TestFormatKeyShouldAppendUserNameAsCommandParameter(c *gocheck.C) { +func (s *S) TestFormatKeyShouldAppendUserNameAsCommandParameter(c *check.C) { p, err := config.GetString("bin-path") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) key := Key{ Name: "my-key", Body: "somekey\n", @@ -134,10 +134,10 @@ func (s *S) TestFormatKeyShouldAppendUserNameAsCommandParameter(c *gocheck.C) { } got := key.format() expected := fmt.Sprintf(`no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty,command="%s someuser" %s`+"\n", p, &key) - c.Assert(got, gocheck.Equals, expected) + c.Assert(got, check.Equals, expected) } -func (s *S) TestDump(c *gocheck.C) { +func (s *S) TestDump(c *check.C) { var buf bytes.Buffer key := Key{ Name: "my-key", @@ -146,11 +146,11 @@ func (s *S) TestDump(c *gocheck.C) { UserName: "someuser", } err := key.dump(&buf) - c.Assert(err, gocheck.IsNil) - c.Assert(buf.String(), gocheck.Equals, key.format()) + c.Assert(err, check.IsNil) + c.Assert(buf.String(), check.Equals, key.format()) } -func (s *S) TestDumpShortWrite(c *gocheck.C) { +func (s *S) TestDumpShortWrite(c *check.C) { key := Key{ Name: "my-key", Body: "somekey\n", @@ -158,10 +158,10 @@ func (s *S) TestDumpShortWrite(c *gocheck.C) { UserName: "someuser", } err := key.dump(shortWriter{}) - c.Assert(err, gocheck.Equals, io.ErrShortWrite) + c.Assert(err, check.Equals, io.ErrShortWrite) } -func (s *S) TestDumpWriteFailure(c *gocheck.C) { +func (s *S) TestDumpWriteFailure(c *check.C) { key := Key{ Name: "my-key", Body: "somekey\n", @@ -169,36 +169,36 @@ func (s *S) TestDumpWriteFailure(c *gocheck.C) { UserName: "someuser", } err := key.dump(failWriter{}) - c.Assert(err, gocheck.NotNil) + c.Assert(err, check.NotNil) } -func (s *S) TestAuthKeyUnconfigured(c *gocheck.C) { +func (s *S) TestAuthKeyUnconfigured(c *check.C) { home := os.Getenv("HOME") expected := path.Join(home, ".ssh", "authorized_keys") - c.Assert(authKey(), gocheck.Equals, expected) + c.Assert(authKey(), check.Equals, expected) } -func (s *S) TestAuthKeyConfig(c *gocheck.C) { +func (s *S) TestAuthKeyConfig(c *check.C) { path := "/var/ssh/authorized_keys" config.Set("authorized-keys-path", path) defer config.Unset("authorized-keys-path") - c.Assert(authKey(), gocheck.Equals, path) + c.Assert(authKey(), check.Equals, path) } -func (s *S) TestWriteKey(c *gocheck.C) { +func (s *S) TestWriteKey(c *check.C) { key, err := newKey("my-key", "me@tsuru.io", rawKey) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) writeKey(key) f, err := s.rfs.Open(authKey()) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer f.Close() b, err := ioutil.ReadAll(f) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) got := string(b) - c.Assert(got, gocheck.Equals, key.format()) + c.Assert(got, check.Equals, key.format()) } -func (s *S) TestWriteTwoKeys(c *gocheck.C) { +func (s *S) TestWriteTwoKeys(c *check.C) { key1 := Key{ Name: "my-key", Body: "ssh-dss mykeys-not-secret", @@ -215,175 +215,175 @@ func (s *S) TestWriteTwoKeys(c *gocheck.C) { writeKey(&key2) expected := key1.format() + key2.format() f, err := s.rfs.Open(authKey()) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer f.Close() b, err := ioutil.ReadAll(f) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) got := string(b) - c.Assert(got, gocheck.Equals, expected) + c.Assert(got, check.Equals, expected) } -func (s *S) TestAddKeyStoresKeyInTheDatabase(c *gocheck.C) { +func (s *S) TestAddKeyStoresKeyInTheDatabase(c *check.C) { err := addKey("key1", rawKey, "gopher") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) var k Key conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() err = conn.Key().Find(bson.M{"name": "key1"}).One(&k) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Key().Remove(bson.M{"name": "key1"}) - c.Assert(k.Name, gocheck.Equals, "key1") - c.Assert(k.UserName, gocheck.Equals, "gopher") - c.Assert(k.Comment, gocheck.Equals, comment) - c.Assert(k.Body, gocheck.Equals, body) + c.Assert(k.Name, check.Equals, "key1") + c.Assert(k.UserName, check.Equals, "gopher") + c.Assert(k.Comment, check.Equals, comment) + c.Assert(k.Body, check.Equals, body) } -func (s *S) TestAddKeyShouldSaveTheKeyInTheAuthorizedKeys(c *gocheck.C) { +func (s *S) TestAddKeyShouldSaveTheKeyInTheAuthorizedKeys(c *check.C) { err := addKey("key1", rawKey, "gopher") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.Key().Remove(bson.M{"name": "key1"}) var k Key err = conn.Key().Find(bson.M{"name": "key1"}).One(&k) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) f, err := s.rfs.Open(authKey()) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer f.Close() b, err := ioutil.ReadAll(f) - c.Assert(err, gocheck.IsNil) - c.Assert(string(b), gocheck.Equals, k.format()) + c.Assert(err, check.IsNil) + c.Assert(string(b), check.Equals, k.format()) } -func (s *S) TestAddKeyDuplicate(c *gocheck.C) { +func (s *S) TestAddKeyDuplicate(c *check.C) { err := addKey("key1", rawKey, "gopher") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.Key().Remove(bson.M{"name": "key1"}) err = addKey("key2", rawKey, "gopher") - c.Assert(err, gocheck.Equals, ErrDuplicateKey) + c.Assert(err, check.Equals, ErrDuplicateKey) } -func (s *S) TestAddKeyInvalidKey(c *gocheck.C) { +func (s *S) TestAddKeyInvalidKey(c *check.C) { err := addKey("key1", "something-invalid", "gopher") - c.Assert(err, gocheck.Equals, ErrInvalidKey) + c.Assert(err, check.Equals, ErrInvalidKey) } -func (s *S) TestRemoveKeyDeletesFromDB(c *gocheck.C) { +func (s *S) TestRemoveKeyDeletesFromDB(c *check.C) { err := addKey("key1", rawKey, "gopher") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = removeKey("key1", "gopher") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) count, err := conn.Key().Find(bson.M{"name": "key1"}).Count() - c.Assert(err, gocheck.IsNil) - c.Assert(count, gocheck.Equals, 0) + c.Assert(err, check.IsNil) + c.Assert(count, check.Equals, 0) } -func (s *S) TestRemoveKeyDeletesOnlyTheRightKey(c *gocheck.C) { +func (s *S) TestRemoveKeyDeletesOnlyTheRightKey(c *check.C) { err := addKey("key1", rawKey, "gopher") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer removeKey("key1", "gopher") err = addKey("key1", otherKey, "glenda") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = removeKey("key1", "glenda") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) count, err := conn.Key().Find(bson.M{"name": "key1", "username": "gopher"}).Count() - c.Assert(err, gocheck.IsNil) - c.Assert(count, gocheck.Equals, 1) + c.Assert(err, check.IsNil) + c.Assert(count, check.Equals, 1) } -func (s *S) TestRemoveUnknownKey(c *gocheck.C) { +func (s *S) TestRemoveUnknownKey(c *check.C) { err := removeKey("wut", "glenda") - c.Assert(err, gocheck.Equals, ErrKeyNotFound) + c.Assert(err, check.Equals, ErrKeyNotFound) } -func (s *S) TestRemoveKeyRemovesFromAuthorizedKeys(c *gocheck.C) { +func (s *S) TestRemoveKeyRemovesFromAuthorizedKeys(c *check.C) { err := addKey("key1", rawKey, "gopher") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = removeKey("key1", "gopher") f, err := s.rfs.Open(authKey()) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer f.Close() b, err := ioutil.ReadAll(f) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) got := string(b) - c.Assert(got, gocheck.Equals, "") + c.Assert(got, check.Equals, "") } -func (s *S) TestRemoveKeyKeepOtherKeys(c *gocheck.C) { +func (s *S) TestRemoveKeyKeepOtherKeys(c *check.C) { err := addKey("key1", rawKey, "gopher") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer removeKey("key1", "gopher") err = addKey("key2", otherKey, "gopher") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = removeKey("key2", "gopher") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) var key Key conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = conn.Key().Find(bson.M{"name": "key1"}).One(&key) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) f, err := s.rfs.Open(authKey()) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer f.Close() b, err := ioutil.ReadAll(f) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) got := string(b) - c.Assert(got, gocheck.Equals, key.format()) + c.Assert(got, check.Equals, key.format()) } -func (s *S) TestRemoveUserKeys(c *gocheck.C) { +func (s *S) TestRemoveUserKeys(c *check.C) { err := addKey("key1", rawKey, "gopher") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer removeKey("key1", "gopher") err = addKey("key1", otherKey, "glenda") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = removeUserKeys("glenda") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) var key Key conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = conn.Key().Find(bson.M{"name": "key1"}).One(&key) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) f, err := s.rfs.Open(authKey()) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer f.Close() b, err := ioutil.ReadAll(f) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) got := string(b) - c.Assert(got, gocheck.Equals, key.format()) + c.Assert(got, check.Equals, key.format()) } -func (s *S) TestRemoveUserMultipleKeys(c *gocheck.C) { +func (s *S) TestRemoveUserMultipleKeys(c *check.C) { err := addKey("key1", rawKey, "glenda") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = addKey("key1", otherKey, "glenda") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = removeUserKeys("glenda") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) count, err := conn.Key().Find(nil).Count() - c.Assert(err, gocheck.IsNil) - c.Assert(count, gocheck.Equals, 0) + c.Assert(err, check.IsNil) + c.Assert(count, check.Equals, 0) f, err := s.rfs.Open(authKey()) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer f.Close() b, err := ioutil.ReadAll(f) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) got := string(b) - c.Assert(got, gocheck.Equals, "") + c.Assert(got, check.Equals, "") } -func (s *S) TestKeyListJSON(c *gocheck.C) { +func (s *S) TestKeyListJSON(c *check.C) { keys := []Key{ {Name: "key1", Body: "ssh-dss not-secret", Comment: "me@host1"}, {Name: "key2", Body: "ssh-dss not-secret1", Comment: "me@host2"}, @@ -396,71 +396,71 @@ func (s *S) TestKeyListJSON(c *gocheck.C) { } var got map[string]string b, err := KeyList(keys).MarshalJSON() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = json.Unmarshal(b, &got) - c.Assert(err, gocheck.IsNil) - c.Assert(got, gocheck.DeepEquals, expected) + c.Assert(err, check.IsNil) + c.Assert(got, check.DeepEquals, expected) } -func (s *S) TestListKeys(c *gocheck.C) { +func (s *S) TestListKeys(c *check.C) { user := map[string]string{"_id": "glenda"} conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = conn.User().Insert(user) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.User().Remove(user) err = addKey("key1", rawKey, "glenda") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = addKey("key2", otherKey, "glenda") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer removeUserKeys("glenda") var expected []Key err = conn.Key().Find(nil).All(&expected) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) got, err := ListKeys("glenda") - c.Assert(err, gocheck.IsNil) - c.Assert(got, gocheck.DeepEquals, KeyList(expected)) + c.Assert(err, check.IsNil) + c.Assert(got, check.DeepEquals, KeyList(expected)) } -func (s *S) TestListKeysUnknownUser(c *gocheck.C) { +func (s *S) TestListKeysUnknownUser(c *check.C) { got, err := ListKeys("glenda") - c.Assert(got, gocheck.IsNil) - c.Assert(err, gocheck.Equals, ErrUserNotFound) + c.Assert(got, check.IsNil) + c.Assert(err, check.Equals, ErrUserNotFound) } -func (s *S) TestListKeysEmpty(c *gocheck.C) { +func (s *S) TestListKeysEmpty(c *check.C) { user := map[string]string{"_id": "gopher"} conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = conn.User().Insert(user) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.User().Remove(user) got, err := ListKeys("gopher") - c.Assert(err, gocheck.IsNil) - c.Assert(got, gocheck.HasLen, 0) + c.Assert(err, check.IsNil) + c.Assert(got, check.HasLen, 0) } -func (s *S) TestListKeysFromTheUserOnly(c *gocheck.C) { +func (s *S) TestListKeysFromTheUserOnly(c *check.C) { user := map[string]string{"_id": "gopher"} conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = conn.User().Insert(user) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.User().Remove(user) user2 := map[string]string{"_id": "glenda"} err = conn.User().Insert(user2) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.User().Remove(user2) err = addKey("key1", rawKey, "glenda") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = addKey("key1", otherKey, "gopher") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer removeUserKeys("glenda") defer removeUserKeys("gopher") var expected []Key err = conn.Key().Find(bson.M{"username": "gopher"}).All(&expected) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) got, err := ListKeys("gopher") - c.Assert(err, gocheck.IsNil) - c.Assert(got, gocheck.DeepEquals, KeyList(expected)) + c.Assert(err, check.IsNil) + c.Assert(got, check.DeepEquals, KeyList(expected)) } diff --git a/user/user_test.go b/user/user_test.go index 3d41d6d..bc4dc67 100644 --- a/user/user_test.go +++ b/user/user_test.go @@ -15,128 +15,128 @@ import ( "github.com/tsuru/gandalf/fs" "github.com/tsuru/gandalf/repository" "github.com/tsuru/tsuru/fs/fstest" + "gopkg.in/check.v1" "gopkg.in/mgo.v2/bson" - "launchpad.net/gocheck" ) -func Test(t *testing.T) { gocheck.TestingT(t) } +func Test(t *testing.T) { check.TestingT(t) } type S struct { rfs *fstest.RecordingFs } -var _ = gocheck.Suite(&S{}) +var _ = check.Suite(&S{}) -func (s *S) authKeysContent(c *gocheck.C) string { +func (s *S) authKeysContent(c *check.C) string { authFile := path.Join(os.Getenv("HOME"), ".ssh", "authorized_keys") f, err := fs.Filesystem().OpenFile(authFile, os.O_RDWR, 0755) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer f.Close() b, err := ioutil.ReadAll(f) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) return string(b) } -func (s *S) SetUpSuite(c *gocheck.C) { +func (s *S) SetUpSuite(c *check.C) { err := config.ReadConfigFile("../etc/gandalf.conf") - c.Check(err, gocheck.IsNil) + c.Check(err, check.IsNil) config.Set("database:name", "gandalf_user_tests") } -func (s *S) SetUpTest(c *gocheck.C) { +func (s *S) SetUpTest(c *check.C) { s.rfs = &fstest.RecordingFs{} fs.Fsystem = s.rfs } -func (s *S) TearDownTest(c *gocheck.C) { +func (s *S) TearDownTest(c *check.C) { s.rfs.Remove(authKey()) } -func (s *S) TearDownSuite(c *gocheck.C) { +func (s *S) TearDownSuite(c *check.C) { fs.Fsystem = nil conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() conn.User().Database.DropDatabase() } -func (s *S) TestNewUserReturnsAStructFilled(c *gocheck.C) { +func (s *S) TestNewUserReturnsAStructFilled(c *check.C) { u, err := New("someuser", map[string]string{"somekey": rawKey}) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.User().Remove(bson.M{"_id": u.Name}) defer conn.Key().Remove(bson.M{"name": "somekey"}) - c.Assert(u.Name, gocheck.Equals, "someuser") + c.Assert(u.Name, check.Equals, "someuser") var key Key err = conn.Key().Find(bson.M{"name": "somekey"}).One(&key) - c.Assert(err, gocheck.IsNil) - c.Assert(key.Name, gocheck.Equals, "somekey") - c.Assert(key.Body, gocheck.Equals, body) - c.Assert(key.Comment, gocheck.Equals, comment) - c.Assert(key.UserName, gocheck.Equals, u.Name) + c.Assert(err, check.IsNil) + c.Assert(key.Name, check.Equals, "somekey") + c.Assert(key.Body, check.Equals, body) + c.Assert(key.Comment, check.Equals, comment) + c.Assert(key.UserName, check.Equals, u.Name) } -func (s *S) TestNewDuplicateUser(c *gocheck.C) { +func (s *S) TestNewDuplicateUser(c *check.C) { u, err := New("someuser", map[string]string{"somekey": rawKey}) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.User().Remove(bson.M{"_id": u.Name}) defer conn.Key().Remove(bson.M{"name": "somekey"}) u, err = New("someuser", map[string]string{"somekey": rawKey}) - c.Assert(err, gocheck.ErrorMatches, "Could not create user: user already exists") + c.Assert(err, check.ErrorMatches, "Could not create user: user already exists") } -func (s *S) TestNewDuplicateUserDifferentKey(c *gocheck.C) { +func (s *S) TestNewDuplicateUserDifferentKey(c *check.C) { u, err := New("someuser", map[string]string{"somekey": rawKey}) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.User().Remove(bson.M{"_id": u.Name}) defer conn.Key().Remove(bson.M{"name": "somekey"}) u, err = New("someuser", map[string]string{"somedifferentkey": rawKey + "fakeKey"}) - c.Assert(err, gocheck.ErrorMatches, "Could not create user: user already exists") + c.Assert(err, check.ErrorMatches, "Could not create user: user already exists") } -func (s *S) TestNewUserShouldStoreUserInDatabase(c *gocheck.C) { +func (s *S) TestNewUserShouldStoreUserInDatabase(c *check.C) { u, err := New("someuser", map[string]string{"somekey": rawKey}) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.User().Remove(bson.M{"_id": u.Name}) defer conn.Key().Remove(bson.M{"name": "somekey"}) err = conn.User().FindId(u.Name).One(&u) - c.Assert(err, gocheck.IsNil) - c.Assert(u.Name, gocheck.Equals, "someuser") + c.Assert(err, check.IsNil) + c.Assert(u.Name, check.Equals, "someuser") n, err := conn.Key().Find(bson.M{"name": "somekey"}).Count() - c.Assert(err, gocheck.IsNil) - c.Assert(n, gocheck.Equals, 1) + c.Assert(err, check.IsNil) + c.Assert(n, check.Equals, 1) } -func (s *S) TestNewChecksIfUserIsValidBeforeStoring(c *gocheck.C) { +func (s *S) TestNewChecksIfUserIsValidBeforeStoring(c *check.C) { _, err := New("", map[string]string{}) - c.Assert(err, gocheck.NotNil) + c.Assert(err, check.NotNil) got := err.Error() expected := "Validation Error: user name is not valid" - c.Assert(got, gocheck.Equals, expected) + c.Assert(got, check.Equals, expected) } -func (s *S) TestNewWritesKeyInAuthorizedKeys(c *gocheck.C) { +func (s *S) TestNewWritesKeyInAuthorizedKeys(c *check.C) { u, err := New("piccolo", map[string]string{"somekey": rawKey}) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.User().Remove(bson.M{"_id": u.Name}) defer conn.Key().Remove(bson.M{"name": "somekey"}) var key Key err = conn.Key().Find(bson.M{"name": "somekey"}).One(&key) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) keys := s.authKeysContent(c) - c.Assert(keys, gocheck.Equals, key.format()) + c.Assert(keys, check.Equals, key.format()) } -func (s *S) TestIsValid(c *gocheck.C) { +func (s *S) TestIsValid(c *check.C) { var tests = []struct { input string expected bool @@ -158,191 +158,191 @@ func (s *S) TestIsValid(c *gocheck.C) { } } -func (s *S) TestRemove(c *gocheck.C) { +func (s *S) TestRemove(c *check.C) { u, err := New("someuser", map[string]string{}) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = Remove(u.Name) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) lenght, err := conn.User().FindId(u.Name).Count() - c.Assert(err, gocheck.IsNil) - c.Assert(lenght, gocheck.Equals, 0) + c.Assert(err, check.IsNil) + c.Assert(lenght, check.Equals, 0) } -func (s *S) TestRemoveRemovesKeyFromAuthorizedKeysFile(c *gocheck.C) { +func (s *S) TestRemoveRemovesKeyFromAuthorizedKeysFile(c *check.C) { u, err := New("gandalf", map[string]string{"somekey": rawKey}) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Key().Remove(bson.M{"name": "somekey"}) err = Remove(u.Name) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) got := s.authKeysContent(c) - c.Assert(got, gocheck.Equals, "") + c.Assert(got, check.Equals, "") } -func (s *S) TestRemoveInexistentUserReturnsDescriptiveMessage(c *gocheck.C) { +func (s *S) TestRemoveInexistentUserReturnsDescriptiveMessage(c *check.C) { err := Remove("otheruser") - c.Assert(err, gocheck.ErrorMatches, "Could not remove user: not found") + c.Assert(err, check.ErrorMatches, "Could not remove user: not found") } -func (s *S) TestRemoveDoesNotRemovesUserWhenUserIsTheOnlyOneAssciatedWithOneRepository(c *gocheck.C) { +func (s *S) TestRemoveDoesNotRemovesUserWhenUserIsTheOnlyOneAssciatedWithOneRepository(c *check.C) { u, err := New("silver", map[string]string{}) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) r := s.createRepo("run", []string{u.Name}, c) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Repository().Remove(bson.M{"_id": r.Name}) defer conn.User().Remove(bson.M{"_id": u.Name}) err = Remove(u.Name) - c.Assert(err, gocheck.ErrorMatches, "^Could not remove user: user is the only one with access to at least one of it's repositories$") + c.Assert(err, check.ErrorMatches, "^Could not remove user: user is the only one with access to at least one of it's repositories$") } -func (s *S) TestRemoveRevokesAccessToReposWithMoreThanOneUserAssociated(c *gocheck.C) { +func (s *S) TestRemoveRevokesAccessToReposWithMoreThanOneUserAssociated(c *check.C) { u, r, r2 := s.userPlusRepos(c) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Repository().Remove(bson.M{"_id": r.Name}) defer conn.Repository().Remove(bson.M{"_id": r2.Name}) defer conn.User().Remove(bson.M{"_id": u.Name}) err = Remove(u.Name) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) s.retrieveRepos(r, r2, c) - c.Assert(r.Users, gocheck.DeepEquals, []string{"slot"}) - c.Assert(r2.Users, gocheck.DeepEquals, []string{"cnot"}) + c.Assert(r.Users, check.DeepEquals, []string{"slot"}) + c.Assert(r2.Users, check.DeepEquals, []string{"cnot"}) } -func (s *S) retrieveRepos(r, r2 *repository.Repository, c *gocheck.C) { +func (s *S) retrieveRepos(r, r2 *repository.Repository, c *check.C) { conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = conn.Repository().FindId(r.Name).One(&r) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = conn.Repository().FindId(r2.Name).One(&r2) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) } -func (s *S) userPlusRepos(c *gocheck.C) (*User, *repository.Repository, *repository.Repository) { +func (s *S) userPlusRepos(c *check.C) (*User, *repository.Repository, *repository.Repository) { u, err := New("silver", map[string]string{}) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) r := s.createRepo("run", []string{u.Name, "slot"}, c) r2 := s.createRepo("stay", []string{u.Name, "cnot"}, c) return u, &r, &r2 } -func (s *S) createRepo(name string, users []string, c *gocheck.C) repository.Repository { +func (s *S) createRepo(name string, users []string, c *check.C) repository.Repository { r := repository.Repository{Name: name, Users: users} conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) err = conn.Repository().Insert(&r) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) return r } -func (s *S) TestHandleAssociatedRepositoriesShouldRevokeAccessToRepoWithMoreThanOneUserAssociated(c *gocheck.C) { +func (s *S) TestHandleAssociatedRepositoriesShouldRevokeAccessToRepoWithMoreThanOneUserAssociated(c *check.C) { u, r, r2 := s.userPlusRepos(c) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Repository().RemoveId(r.Name) defer conn.Repository().RemoveId(r2.Name) defer conn.User().RemoveId(u.Name) err = u.handleAssociatedRepositories() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) s.retrieveRepos(r, r2, c) - c.Assert(r.Users, gocheck.DeepEquals, []string{"slot"}) - c.Assert(r2.Users, gocheck.DeepEquals, []string{"cnot"}) + c.Assert(r.Users, check.DeepEquals, []string{"slot"}) + c.Assert(r2.Users, check.DeepEquals, []string{"cnot"}) } -func (s *S) TestHandleAssociateRepositoriesReturnsErrorWhenUserIsOnlyOneWithAccessToAtLeastOneRepo(c *gocheck.C) { +func (s *S) TestHandleAssociateRepositoriesReturnsErrorWhenUserIsOnlyOneWithAccessToAtLeastOneRepo(c *check.C) { u, err := New("umi", map[string]string{}) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) r := s.createRepo("proj1", []string{"umi"}, c) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.User().RemoveId(u.Name) defer conn.Repository().RemoveId(r.Name) err = u.handleAssociatedRepositories() expected := "^Could not remove user: user is the only one with access to at least one of it's repositories$" - c.Assert(err, gocheck.ErrorMatches, expected) + c.Assert(err, check.ErrorMatches, expected) } -func (s *S) TestAddKeyShouldSaveTheKeyInTheDatabase(c *gocheck.C) { +func (s *S) TestAddKeyShouldSaveTheKeyInTheDatabase(c *check.C) { u, err := New("umi", map[string]string{}) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.User().RemoveId(u.Name) k := map[string]string{"somekey": rawKey} err = AddKey("umi", k) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Key().Remove(bson.M{"name": "somekey"}) var key Key err = conn.Key().Find(bson.M{"name": "somekey"}).One(&key) - c.Assert(err, gocheck.IsNil) - c.Assert(key.Name, gocheck.Equals, "somekey") - c.Assert(key.Body, gocheck.Equals, body) - c.Assert(key.Comment, gocheck.Equals, comment) - c.Assert(key.UserName, gocheck.Equals, u.Name) + c.Assert(err, check.IsNil) + c.Assert(key.Name, check.Equals, "somekey") + c.Assert(key.Body, check.Equals, body) + c.Assert(key.Comment, check.Equals, comment) + c.Assert(key.UserName, check.Equals, u.Name) } -func (s *S) TestAddKeyShouldWriteKeyInAuthorizedKeys(c *gocheck.C) { +func (s *S) TestAddKeyShouldWriteKeyInAuthorizedKeys(c *check.C) { u, err := New("umi", map[string]string{}) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.User().RemoveId(u.Name) defer conn.Key().Remove(bson.M{"name": "somekey"}) k := map[string]string{"somekey": rawKey} err = AddKey("umi", k) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) var key Key err = conn.Key().Find(bson.M{"name": "somekey"}).One(&key) content := s.authKeysContent(c) - c.Assert(content, gocheck.Equals, key.format()) + c.Assert(content, check.Equals, key.format()) } -func (s *S) TestAddKeyShouldReturnCustomErrorWhenUserDoesNotExist(c *gocheck.C) { +func (s *S) TestAddKeyShouldReturnCustomErrorWhenUserDoesNotExist(c *check.C) { err := AddKey("umi", map[string]string{"somekey": "ssh-rsa mykey umi@host"}) - c.Assert(err, gocheck.Equals, ErrUserNotFound) + c.Assert(err, check.Equals, ErrUserNotFound) } -func (s *S) TestRemoveKeyShouldRemoveKeyFromTheDatabase(c *gocheck.C) { +func (s *S) TestRemoveKeyShouldRemoveKeyFromTheDatabase(c *check.C) { u, err := New("luke", map[string]string{"homekey": rawKey}) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.User().RemoveId(u.Name) err = RemoveKey("luke", "homekey") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) count, err := conn.Key().Find(bson.M{"name": "homekey", "username": u.Name}).Count() - c.Assert(err, gocheck.IsNil) - c.Assert(count, gocheck.Equals, 0) + c.Assert(err, check.IsNil) + c.Assert(count, check.Equals, 0) } -func (s *S) TestRemoveKeyShouldRemoveFromAuthorizedKeysFile(c *gocheck.C) { +func (s *S) TestRemoveKeyShouldRemoveFromAuthorizedKeysFile(c *check.C) { u, err := New("luke", map[string]string{"homekey": rawKey}) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.User().RemoveId(u.Name) defer conn.Key().Remove(bson.M{"name": "homekey"}) err = RemoveKey("luke", "homekey") - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) content := s.authKeysContent(c) - c.Assert(content, gocheck.Equals, "") + c.Assert(content, check.Equals, "") } -func (s *S) TestRemoveUnknownKeyFromUser(c *gocheck.C) { +func (s *S) TestRemoveUnknownKeyFromUser(c *check.C) { u, err := New("luke", map[string]string{}) - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) conn, err := db.Conn() - c.Assert(err, gocheck.IsNil) + c.Assert(err, check.IsNil) defer conn.Close() defer conn.User().RemoveId(u.Name) err = RemoveKey("luke", "homekey") - c.Assert(err, gocheck.Equals, ErrKeyNotFound) + c.Assert(err, check.Equals, ErrKeyNotFound) } -func (s *S) TestRemoveKeyShouldReturnFormatedErrorMsgWhenUserDoesNotExist(c *gocheck.C) { +func (s *S) TestRemoveKeyShouldReturnFormatedErrorMsgWhenUserDoesNotExist(c *check.C) { err := RemoveKey("luke", "homekey") - c.Assert(err, gocheck.Equals, ErrUserNotFound) + c.Assert(err, check.Equals, ErrUserNotFound) }