本文整理匯總了Golang中github.com/github/hub/Godeps/_workspace/src/github.com/bmizerany/assert.T函數的典型用法代碼示例。如果您正苦於以下問題:Golang T函數的具體用法?Golang T怎麽用?Golang T使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了T函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestUsersService_All
func TestUsersService_All(t *testing.T) {
setup()
defer tearDown()
mux.HandleFunc("/users", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
rr := regexp.MustCompile(`users\?since=\d+`)
assert.Tf(t, rr.MatchString(r.URL.String()), "Regexp should match users?since=\\d+")
header := w.Header()
link := fmt.Sprintf(`<%s>; rel="next", <%s>; rel="first"`, testURLOf("users?since=135"), testURLOf("users{?since}"))
header.Set("Link", link)
respondWithJSON(w, loadFixture("users.json"))
})
url, err := UserURL.Expand(M{"since": 1})
assert.Equal(t, nil, err)
q := url.Query()
q.Set("since", "1")
url.RawQuery = q.Encode()
allUsers, result := client.Users(url).All()
assert.T(t, !result.HasError())
assert.Equal(t, 1, len(allUsers))
assert.Equal(t, testURLStringOf("users?since=135"), string(*result.NextPage))
nextPageURL, err := result.NextPage.Expand(nil)
assert.Equal(t, nil, err)
allUsers, result = client.Users(nextPageURL).All()
assert.T(t, !result.HasError())
assert.Equal(t, 1, len(allUsers))
}
示例2: TestAuthorizationsService_All
func TestAuthorizationsService_All(t *testing.T) {
setup()
defer tearDown()
mux.HandleFunc("/authorizations", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
respondWithJSON(w, loadFixture("authorizations.json"))
})
url, err := AuthorizationsURL.Expand(nil)
assert.Equal(t, nil, err)
auths, result := client.Authorizations(url).All()
assert.T(t, !result.HasError())
firstAuth := auths[0]
assert.Equal(t, 1, firstAuth.ID)
assert.Equal(t, "https://api.github.com/authorizations/1", firstAuth.URL)
assert.Equal(t, "456", firstAuth.Token)
assert.Equal(t, "", firstAuth.Note)
assert.Equal(t, "", firstAuth.NoteURL)
assert.Equal(t, "2012-11-16 01:05:51 +0000 UTC", firstAuth.CreatedAt.String())
assert.Equal(t, "2013-08-21 03:29:51 +0000 UTC", firstAuth.UpdatedAt.String())
app := App{ClientID: "123", URL: "http://localhost:8080", Name: "Test"}
assert.Equal(t, app, firstAuth.App)
assert.Equal(t, 2, len(firstAuth.Scopes))
scopes := []string{"repo", "user"}
assert.T(t, reflect.DeepEqual(firstAuth.Scopes, scopes))
}
示例3: TestNewArgs
func TestNewArgs(t *testing.T) {
args := NewArgs([]string{})
assert.Equal(t, "", args.Command)
assert.Equal(t, 0, args.ParamsSize())
args = NewArgs([]string{"command"})
assert.Equal(t, "command", args.Command)
assert.Equal(t, 0, args.ParamsSize())
args = NewArgs([]string{"command", "args"})
assert.Equal(t, "command", args.Command)
assert.Equal(t, 1, args.ParamsSize())
args = NewArgs([]string{"--noop", "command", "args"})
assert.Equal(t, "command", args.Command)
assert.Equal(t, 1, args.ParamsSize())
assert.T(t, args.Noop)
args = NewArgs([]string{"--version"})
assert.Equal(t, "version", args.Command)
assert.Equal(t, 0, args.ParamsSize())
args = NewArgs([]string{"--help"})
assert.Equal(t, "help", args.Command)
assert.Equal(t, 0, args.ParamsSize())
args = NewArgs([]string{"--noop", "--version"})
assert.T(t, args.Noop)
assert.Equal(t, "version", args.Command)
args = NewArgs([]string{"-c", "foo=bar", "--git-dir=path", "--bare"})
assert.Equal(t, 5, len(args.GlobalFlags))
assert.Equal(t, "-c foo=bar --bare --git-dir path", strings.Join(args.GlobalFlags, " "))
}
示例4: TestAuthorizationsService_Create
func TestAuthorizationsService_Create(t *testing.T) {
setup()
defer tearDown()
params := AuthorizationParams{Scopes: []string{"public_repo"}}
mux.HandleFunc("/authorizations", func(w http.ResponseWriter, r *http.Request) {
var authParams AuthorizationParams
json.NewDecoder(r.Body).Decode(&authParams)
assert.T(t, reflect.DeepEqual(authParams, params))
testMethod(t, r, "POST")
respondWithJSON(w, loadFixture("create_authorization.json"))
})
url, err := AuthorizationsURL.Expand(nil)
assert.Equal(t, nil, err)
auth, _ := client.Authorizations(url).Create(params)
assert.Equal(t, 3844190, auth.ID)
assert.Equal(t, "https://api.github.com/authorizations/3844190", auth.URL)
assert.Equal(t, "123", auth.Token)
assert.Equal(t, "", auth.Note)
assert.Equal(t, "", auth.NoteURL)
assert.Equal(t, "2013-09-28 18:44:39 +0000 UTC", auth.CreatedAt.String())
assert.Equal(t, "2013-09-28 18:44:39 +0000 UTC", auth.UpdatedAt.String())
app := App{ClientID: "00000000000000000000", URL: "http://developer.github.com/v3/oauth/#oauth-authorizations-api", Name: "GitHub API"}
assert.Equal(t, app, auth.App)
assert.Equal(t, 1, len(auth.Scopes))
scopes := []string{"public_repo"}
assert.T(t, reflect.DeepEqual(auth.Scopes, scopes))
}
示例5: TestRepositoresService_CreateFork
func TestRepositoresService_CreateFork(t *testing.T) {
setup()
defer tearDown()
mux.HandleFunc("/repos/jingweno/octokat/forks", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
testBody(t, r, "{\"organization\":\"github\"}\n")
respondWithJSON(w, loadFixture("create_repository.json"))
})
url, err := ForksURL.Expand(M{"owner": "jingweno", "repo": "octokat"})
assert.Equal(t, nil, err)
repo, result := client.Repositories(url).Create(M{"organization": "github"})
assert.T(t, !result.HasError())
assert.Equal(t, 1296269, repo.ID)
assert.Equal(t, "Hello-World", repo.Name)
assert.Equal(t, "octocat/Hello-World", repo.FullName)
assert.Equal(t, "This is your first repo", repo.Description)
assert.T(t, !repo.Private)
assert.T(t, repo.Fork)
assert.Equal(t, "https://api.github.com/repos/octocat/Hello-World", repo.URL)
assert.Equal(t, "https://github.com/octocat/Hello-World", repo.HTMLURL)
assert.Equal(t, "https://github.com/octocat/Hello-World.git", repo.CloneURL)
assert.Equal(t, "git://github.com/octocat/Hello-World.git", repo.GitURL)
assert.Equal(t, "[email protected]:octocat/Hello-World.git", repo.SSHURL)
assert.Equal(t, "master", repo.MasterBranch)
}
示例6: TestNewResult_Pageable
func TestNewResult_Pageable(t *testing.T) {
resp := &Response{MediaHeader: &mediaheader.MediaHeader{Relations: hypermedia.Relations{"next": hypermedia.Hyperlink("/path")}}}
result := newResult(resp, nil)
assert.Equal(t, "/path", string(*result.NextPage))
assert.T(t, result.PrevPage == nil)
assert.T(t, result.LastPage == nil)
assert.T(t, result.FirstPage == nil)
}
示例7: TestTransformRemoteArgs
func TestTransformRemoteArgs(t *testing.T) {
os.Setenv("HUB_PROTOCOL", "git")
github.CreateTestConfigs("jingweno", "123")
args := NewArgs([]string{"remote", "add", "jingweno"})
transformRemoteArgs(args)
assert.Equal(t, 3, args.ParamsSize())
assert.Equal(t, "add", args.FirstParam())
assert.Equal(t, "jingweno", args.GetParam(1))
reg := regexp.MustCompile("^[email protected]\\.com:jingweno/.+\\.git$")
assert.T(t, reg.MatchString(args.GetParam(2)))
args = NewArgs([]string{"remote", "add", "mislav"})
transformRemoteArgs(args)
assert.Equal(t, 3, args.ParamsSize())
assert.Equal(t, "add", args.FirstParam())
assert.Equal(t, "mislav", args.GetParam(1))
reg = regexp.MustCompile("^git://github\\.com/mislav/.+\\.git$")
assert.T(t, reg.MatchString(args.GetParam(2)))
args = NewArgs([]string{"remote", "add", "-p", "mislav"})
transformRemoteArgs(args)
assert.Equal(t, 3, args.ParamsSize())
assert.Equal(t, "add", args.FirstParam())
assert.Equal(t, "mislav", args.GetParam(1))
reg = regexp.MustCompile("^[email protected]\\.com:mislav/.+\\.git$")
assert.T(t, reg.MatchString(args.GetParam(2)))
args = NewArgs([]string{"remote", "add", "origin"})
transformRemoteArgs(args)
assert.Equal(t, 3, args.ParamsSize())
assert.Equal(t, "add", args.FirstParam())
assert.Equal(t, "origin", args.GetParam(1))
reg = regexp.MustCompile("^[email protected]\\.com:jingweno/.+\\.git$")
assert.T(t, reg.MatchString(args.GetParam(2)))
args = NewArgs([]string{"remote", "add", "jingweno", "[email protected]:jingweno/gh.git"})
transformRemoteArgs(args)
assert.Equal(t, 3, args.ParamsSize())
assert.Equal(t, "jingweno", args.GetParam(1))
assert.Equal(t, "add", args.FirstParam())
assert.Equal(t, "[email protected]:jingweno/gh.git", args.GetParam(2))
args = NewArgs([]string{"remote", "add", "-p", "origin", "org/foo"})
transformRemoteArgs(args)
assert.Equal(t, 3, args.ParamsSize())
assert.Equal(t, "origin", args.GetParam(1))
assert.Equal(t, "add", args.FirstParam())
assert.Equal(t, "[email protected]:org/foo.git", args.GetParam(2))
}
示例8: TestAuthTokenNote
func TestAuthTokenNote(t *testing.T) {
note, err := authTokenNote(1)
assert.Equal(t, nil, err)
reg := regexp.MustCompile("hub for (.+)@(.+)")
assert.T(t, reg.MatchString(note))
note, err = authTokenNote(2)
assert.Equal(t, nil, err)
reg = regexp.MustCompile("hub for (.+)@(.+) 2")
assert.T(t, reg.MatchString(note))
}
示例9: TestEditor_openAndEdit_deleteFileWhenOpeningEditorFails
func TestEditor_openAndEdit_deleteFileWhenOpeningEditorFails(t *testing.T) {
tempFile, _ := ioutil.TempFile("", "editor-test")
tempFile.Close()
ioutil.WriteFile(tempFile.Name(), []byte("hello"), 0644)
editor := Editor{
Program: "memory",
File: tempFile.Name(),
Topic: "test",
openEditor: func(program string, file string) error {
assert.Equal(t, "memory", program)
assert.Equal(t, tempFile.Name(), file)
return fmt.Errorf("error")
},
}
_, err := os.Stat(tempFile.Name())
assert.Equal(t, nil, err)
_, err = editor.openAndEdit()
assert.Equal(t, "error using text editor for test message", fmt.Sprintf("%s", err))
// file is removed if there's error
_, err = os.Stat(tempFile.Name())
assert.T(t, os.IsNotExist(err))
}
示例10: TestGitDir
func TestGitDir(t *testing.T) {
repo := fixtures.SetupTestRepo()
defer repo.TearDown()
gitDir, _ := Dir()
assert.T(t, strings.Contains(gitDir, ".git"))
}
示例11: TestUploadsService_UploadAsset
func TestUploadsService_UploadAsset(t *testing.T) {
setup()
defer tearDown()
file, err := ioutil.TempFile("", "octokit-test-upload-")
assert.Equal(t, nil, err)
file.WriteString("this is a test")
fi, err := file.Stat()
assert.Equal(t, nil, err)
file.Close()
mux.HandleFunc("/repos/octokit/Hello-World/releases/123/assets", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
testHeader(t, r, "Content-Type", "text/plain")
assert.Equal(t, fi.Size(), r.ContentLength)
respondWithStatus(w, 201)
})
link := Hyperlink("/repos/octokit/Hello-World/releases/123/assets{?name}")
url, err := link.Expand(M{"name": fi.Name()})
assert.Equal(t, nil, err)
open, _ := os.Open(file.Name())
result := client.Uploads(url).UploadAsset(open, "text/plain", fi.Size())
fmt.Println(result)
assert.T(t, !result.HasError())
assert.Equal(t, 201, result.Response.StatusCode)
}
示例12: TestGitTreesService_One_Recursive
func TestGitTreesService_One_Recursive(t *testing.T) {
setup()
defer tearDown()
mux.HandleFunc("/repos/pengwynn/flint/git/trees/master", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
respondWithJSON(w, loadFixture("tree_recursive.json"))
})
url, err := GitTreesURL.Expand(M{
"owner": "pengwynn",
"repo": "flint",
"sha": "master",
"recursive": "1",
})
assert.Equal(t, nil, err)
tree, result := client.GitTrees(url).One()
assert.T(t, !result.HasError())
assert.Equal(t, "9c1337e761bbd517f3cc1b5acb9373b17f4810e8", tree.Sha)
assert.Equal(t, "https://api.github.com/repos/pengwynn/flint/git/trees/9c1337e761bbd517f3cc1b5acb9373b17f4810e8", tree.URL)
entries := tree.Tree
assert.Equal(t, 15, len(entries))
}
示例13: TestDirIsNotEmpty
func TestDirIsNotEmpty(t *testing.T) {
dir := createTempDir(t)
defer os.RemoveAll(dir)
ioutil.TempFile(dir, "gh-utils-test-")
assert.T(t, !isEmptyDir(dir))
}
示例14: TestRepositoresService_Create
func TestRepositoresService_Create(t *testing.T) {
setup()
defer tearDown()
params := Repository{}
params.Name = "Hello-World"
params.Description = "This is your first repo"
params.Homepage = "https://github.com"
params.Private = false
params.HasIssues = true
params.HasWiki = true
params.HasDownloads = true
mux.HandleFunc("/user/repos", func(w http.ResponseWriter, r *http.Request) {
var repoParams Repository
json.NewDecoder(r.Body).Decode(&repoParams)
assert.Equal(t, params.Name, repoParams.Name)
assert.Equal(t, params.Description, repoParams.Description)
assert.Equal(t, params.Homepage, repoParams.Homepage)
assert.Equal(t, params.Private, repoParams.Private)
assert.Equal(t, params.HasIssues, repoParams.HasIssues)
assert.Equal(t, params.HasWiki, repoParams.HasWiki)
assert.Equal(t, params.HasDownloads, repoParams.HasDownloads)
testMethod(t, r, "POST")
respondWithJSON(w, loadFixture("create_repository.json"))
})
url, err := UserRepositoriesURL.Expand(nil)
assert.Equal(t, nil, err)
repo, result := client.Repositories(url).Create(params)
assert.T(t, !result.HasError())
assert.Equal(t, 1296269, repo.ID)
assert.Equal(t, "Hello-World", repo.Name)
assert.Equal(t, "octocat/Hello-World", repo.FullName)
assert.Equal(t, "This is your first repo", repo.Description)
assert.T(t, !repo.Private)
assert.T(t, repo.Fork)
assert.Equal(t, "https://api.github.com/repos/octocat/Hello-World", repo.URL)
assert.Equal(t, "https://github.com/octocat/Hello-World", repo.HTMLURL)
assert.Equal(t, "https://github.com/octocat/Hello-World.git", repo.CloneURL)
assert.Equal(t, "git://github.com/octocat/Hello-World.git", repo.GitURL)
assert.Equal(t, "[email protected]:octocat/Hello-World.git", repo.SSHURL)
assert.Equal(t, "master", repo.MasterBranch)
}
示例15: TestPullRequestService_Post
func TestPullRequestService_Post(t *testing.T) {
setup()
defer tearDown()
mux.HandleFunc("/repos/octokit/go-octokit/pulls", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
testBody(t, r,
"{\"base\":\"base\",\"head\":\"head\",\"title\":\"title\",\"body\":\"body\"}\n")
respondWithJSON(w, loadFixture("pull_request.json"))
})
url, err := PullRequestsURL.Expand(M{"owner": "octokit", "repo": "go-octokit"})
assert.Equal(t, nil, err)
params := PullRequestParams{
Base: "base",
Head: "head",
Title: "title",
Body: "body",
}
pr, result := client.PullRequests(url).Create(params)
assert.T(t, !result.HasError())
assert.Equal(t, 1, pr.ChangedFiles)
assert.Equal(t, 1, pr.Deletions)
assert.Equal(t, 1, pr.Additions)
assert.Equal(t, "aafce5dfc44270f35270b24677abbb859b20addf", pr.MergeCommitSha)
assert.Equal(t, "2013-06-09 00:53:38 +0000 UTC", pr.MergedAt.String())
assert.Equal(t, "2013-06-09 00:53:38 +0000 UTC", pr.ClosedAt.String())
assert.Equal(t, "2013-06-19 00:35:24 +0000 UTC", pr.UpdatedAt.String())
assert.Equal(t, "2013-06-09 00:52:12 +0000 UTC", pr.CreatedAt.String())
assert.Equal(t, "typo", pr.Body)
assert.Equal(t, "Update README.md", pr.Title)
assert.Equal(t, "https://api.github.com/repos/jingweno/octokat/pulls/1", pr.URL)
assert.Equal(t, 6206442, pr.ID)
assert.Equal(t, "https://github.com/jingweno/octokat/pull/1", pr.HTMLURL)
assert.Equal(t, "https://github.com/jingweno/octokat/pull/1.diff", pr.DiffURL)
assert.Equal(t, "https://github.com/jingweno/octokat/pull/1.patch", pr.PatchURL)
assert.Equal(t, "https://github.com/jingweno/octokat/pull/1", pr.IssueURL)
assert.Equal(t, 1, pr.Number)
assert.Equal(t, "closed", pr.State)
assert.T(t, nil == pr.Assignee)
assert.Equal(t, "https://github.com/jingweno/octokat/pull/1/commits", pr.CommitsURL)
assert.Equal(t, "https://github.com/jingweno/octokat/pull/1/comments", pr.ReviewCommentsURL)
assert.Equal(t, "/repos/jingweno/octokat/pulls/comments/{number}", pr.ReviewCommentURL)
assert.Equal(t, "https://api.github.com/repos/jingweno/octokat/issues/1/comments", pr.CommentsURL)
}