本文整理匯總了Golang中github.com/github/hub/Godeps/_workspace/src/github.com/bmizerany/assert.Equal函數的典型用法代碼示例。如果您正苦於以下問題:Golang Equal函數的具體用法?Golang Equal怎麽用?Golang Equal使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Equal函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestArgs_Words
func TestArgs_Words(t *testing.T) {
args := NewArgs([]string{"--no-ff", "master"})
a := args.Words()
assert.Equal(t, 1, len(a))
assert.Equal(t, "master", a[0])
}
示例2: TestDecode
func TestDecode(t *testing.T) {
input := `
{ "Login": "bob"
, "Url": "/foo/bar{/arg}"
, "_links":
{ "self": { "href": "/foo/bar{/arg}" }
}
}`
user := &HypermediaUser{}
decode(t, input, user)
assert.Equal(t, "bob", user.Login)
assert.Equal(t, 1, len(user.Links))
hl := user.Url
url, err := hl.Expand(M{"arg": "baz"})
if err != nil {
t.Errorf("Errors parsing %s: %s", hl, err)
}
assert.Equal(t, "/foo/bar/baz", url.String())
hl = user.Links["self"].Href
url, err = hl.Expand(M{"arg": "baz"})
if err != nil {
t.Errorf("Errors parsing %s: %s", hl, err)
}
assert.Equal(t, "/foo/bar/baz", url.String())
}
示例3: 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))
}
示例4: TestConfigService_TomlSave
func TestConfigService_TomlSave(t *testing.T) {
file, _ := ioutil.TempFile("", "test-gh-config-")
defer os.RemoveAll(file.Name())
host := &Host{
Host: "github.com",
User: "jingweno",
AccessToken: "123",
Protocol: "https",
}
c := &Config{Hosts: []*Host{host}}
cs := &configService{
Encoder: &tomlConfigEncoder{},
Decoder: &tomlConfigDecoder{},
}
err := cs.Save(file.Name(), c)
assert.Equal(t, nil, err)
b, _ := ioutil.ReadFile(file.Name())
content := `[[hosts]]
host = "github.com"
user = "jingweno"
access_token = "123"
protocol = "https"`
assert.Equal(t, content, strings.TrimSpace(string(b)))
}
示例5: TestSuccessfulGetWithoutOutput
func TestSuccessfulGetWithoutOutput(t *testing.T) {
setup := Setup(t)
defer setup.Teardown()
setup.Mux.HandleFunc("/user", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "GET", r.Method)
head := w.Header()
head.Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"id": 1, "login": "sawyer"}`))
})
client := setup.Client
user := &TestUser{}
req, err := client.NewRequest("user")
assert.Equal(t, nil, err)
res := req.Get()
assert.Equal(t, false, res.IsError())
assert.Equal(t, false, res.IsApiError())
assert.Tf(t, !res.IsError(), "Response shouldn't have error")
assert.Equal(t, 200, res.StatusCode)
assert.Equal(t, false, res.BodyClosed)
assert.Equal(t, 0, user.Id)
assert.Equal(t, "", user.Login)
dec := json.NewDecoder(res.Body)
dec.Decode(user)
assert.Equal(t, 1, user.Id)
assert.Equal(t, "sawyer", user.Login)
}
示例6: TestEditor_EditTitleAndBody
func TestEditor_EditTitleAndBody(t *testing.T) {
tempFile, _ := ioutil.TempFile("", "PULLREQ")
tempFile.Close()
editor := Editor{
Program: "memory",
File: tempFile.Name(),
CS: "#",
openEditor: func(program string, file string) error {
assert.Equal(t, "memory", program)
assert.Equal(t, tempFile.Name(), file)
message := `A title
A title continues
A body
A body continues
# comment
`
return ioutil.WriteFile(file, []byte(message), 0644)
},
}
title, body, err := editor.EditTitleAndBody()
assert.Equal(t, nil, err)
assert.Equal(t, "A title A title continues", title)
assert.Equal(t, "A body\nA body continues", body)
}
示例7: TestSuccessfulGet
func TestSuccessfulGet(t *testing.T) {
setup := Setup(t)
defer setup.Teardown()
setup.Mux.HandleFunc("/user", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "GET", r.Method)
head := w.Header()
head.Set("Content-Type", "application/json")
link := `<https://api.github.com/user/repos?page=3&per_page=100>; rel="next", <https://api.github.com/user/repos?page=50&per_page=100>; rel="last"`
head.Set("Link", link)
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"id": 1, "login": "sawyer"}`))
})
client := setup.Client
user := &TestUser{}
req, err := client.NewRequest("user")
assert.Equal(t, nil, err)
res := req.Get()
assert.Equal(t, false, res.IsError())
assert.Equal(t, false, res.IsApiError())
assert.Equal(t, nil, res.Decode(user))
assert.Equal(t, 200, res.StatusCode)
assert.Equal(t, 1, user.Id)
assert.Equal(t, "sawyer", user.Login)
mheader := res.MediaHeader
assert.Equal(t, "https://api.github.com/user/repos?page=3&per_page=100", string(mheader.Relations["next"]))
assert.Equal(t, "https://api.github.com/user/repos?page=50&per_page=100", string(mheader.Relations["last"]))
}
示例8: TestResolveRequestQuery
func TestResolveRequestQuery(t *testing.T) {
setup := Setup(t)
defer setup.Teardown()
setup.Mux.HandleFunc("/q", func(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
assert.Equal(t, "1", q.Get("a"))
assert.Equal(t, "4", q.Get("b"))
assert.Equal(t, "3", q.Get("c"))
assert.Equal(t, "2", q.Get("d"))
assert.Equal(t, "1", q.Get("e"))
w.WriteHeader(123)
w.Write([]byte("ok"))
})
assert.Equal(t, "1", setup.Client.Query.Get("a"))
assert.Equal(t, "1", setup.Client.Query.Get("b"))
setup.Client.Query.Set("b", "2")
setup.Client.Query.Set("c", "3")
req, err := setup.Client.NewRequest("/q?d=4")
assert.Equal(t, nil, err)
req.Query.Set("b", "4")
req.Query.Set("c", "3")
req.Query.Set("d", "2")
req.Query.Set("e", "1")
res := req.Get()
assert.Equal(t, nil, err)
assert.Equal(t, 123, res.StatusCode)
}
示例9: 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))
}
示例10: 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)
}
示例11: 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))
}
示例12: 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))
}
示例13: TestRepositoresService_One
func TestRepositoresService_One(t *testing.T) {
setup()
defer tearDown()
mux.HandleFunc("/repos/jingweno/octokat", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
respondWithJSON(w, loadFixture("repository.json"))
})
url, err := RepositoryURL.Expand(M{"owner": "jingweno", "repo": "octokat"})
assert.Equal(t, nil, err)
repo, result := client.Repositories(url).One()
assert.T(t, !result.HasError())
assert.Equal(t, 10575811, repo.ID)
assert.Equal(t, "octokat", repo.Name)
assert.Equal(t, "jingweno/octokat", repo.FullName)
assert.T(t, !repo.Private)
assert.T(t, !repo.Fork)
assert.Equal(t, "https://api.github.com/repos/jingweno/octokat", repo.URL)
assert.Equal(t, "https://github.com/jingweno/octokat", repo.HTMLURL)
assert.Equal(t, "https://github.com/jingweno/octokat.git", repo.CloneURL)
assert.Equal(t, "git://github.com/jingweno/octokat.git", repo.GitURL)
assert.Equal(t, "[email protected]:jingweno/octokat.git", repo.SSHURL)
assert.Equal(t, "master", repo.MasterBranch)
assert.T(t, !repo.Permissions.Admin)
assert.T(t, !repo.Permissions.Push)
assert.T(t, repo.Permissions.Pull)
}
示例14: 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))
}
示例15: TestArgs_GlobalFlags_Repeated
func TestArgs_GlobalFlags_Repeated(t *testing.T) {
args := NewArgs([]string{"-C", "mydir", "-c", "a=b", "--bare", "-c", "c=d", "-c", "e=f", "status"})
assert.Equal(t, "status", args.Command)
assert.Equal(t, []string{"-C", "mydir", "-c", "a=b", "--bare", "-c", "c=d", "-c", "e=f"}, args.GlobalFlags)
assert.Equal(t, 0, len(args.Params))
assert.Equal(t, false, args.Noop)
}