本文整理汇总了Golang中github.com/bmizerany/assert.Equal函数的典型用法代码示例。如果您正苦于以下问题:Golang Equal函数的具体用法?Golang Equal怎么用?Golang Equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Equal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestDiskQueueCorruption
func TestDiskQueueCorruption(t *testing.T) {
log.SetOutput(ioutil.Discard)
defer log.SetOutput(os.Stdout)
dqName := "test_disk_queue_corruption" + strconv.Itoa(int(time.Now().Unix()))
dq := NewDiskQueue(dqName, os.TempDir(), 1000, 5)
msg := make([]byte, 123)
for i := 0; i < 25; i++ {
dq.Put(msg)
}
assert.Equal(t, dq.Depth(), int64(25))
// corrupt the 2nd file
dqFn := dq.(*DiskQueue).fileName(1)
os.Truncate(dqFn, 500)
for i := 0; i < 19; i++ {
assert.Equal(t, <-dq.ReadChan(), msg)
}
// corrupt the 4th (current) file
dqFn = dq.(*DiskQueue).fileName(3)
os.Truncate(dqFn, 100)
dq.Put(msg)
assert.Equal(t, <-dq.ReadChan(), msg)
}
示例2: TestNew
func TestNew(t *testing.T) {
p := New()
zero := int64(0)
assert.Equal(t, zero, p.Current)
assert.Equal(t, zero, p.Total)
assert.Equal(t, zero, p.Expected)
}
示例3: TestProgressReader
func TestProgressReader(t *testing.T) {
filename := "progress_test.go"
f, err := os.Open(filename)
defer f.Close()
if err != nil {
log.Fatalln(err)
}
fs, err := os.Stat(filename)
if err != nil {
log.Fatalln(err)
}
p := New()
p.Total = fs.Size()
p.Progress = func(current, total, expected int64) {
log.Println("Reading", current, total, expected)
assert.Equal(t, true, current <= total)
}
b := new(bytes.Buffer)
r := syncreader.New(f, p)
_, err = b.ReadFrom(r)
if err != nil {
log.Fatalln(err)
}
assert.Equal(t, fs.Size(), int64(b.Len()))
}
示例4: TestDoozerGet
func TestDoozerGet(t *testing.T) {
l := mustListen()
defer l.Close()
u := mustListenUDP(l.Addr().String())
defer u.Close()
go Main("a", "X", "", "", "", nil, u, l, nil, 1e9, 2e9, 3e9, 101)
cl := dial(l.Addr().String())
_, err := cl.Set("/x", store.Missing, []byte{'a'})
assert.Equal(t, nil, err)
ents, rev, err := cl.Get("/x", nil)
assert.Equal(t, nil, err)
assert.NotEqual(t, store.Dir, rev)
assert.Equal(t, []byte{'a'}, ents)
//cl.Set("/test/a", store.Missing, []byte{'1'})
//cl.Set("/test/b", store.Missing, []byte{'2'})
//cl.Set("/test/c", store.Missing, []byte{'3'})
//ents, rev, err = cl.Get("/test", 0)
//sort.SortStrings(ents)
//assert.Equal(t, store.Dir, rev)
//assert.Equal(t, nil, err)
//assert.Equal(t, []string{"a", "b", "c"}, ents)
}
示例5: TestConnectInvalidUrl
func TestConnectInvalidUrl(t *testing.T) {
//
// Missing protocol scheme - url.Parse should fail
//
_, err := Connect("://foobar.com")
if err == nil {
t.Fatal("Expected error due to missing protocol scheme")
}
//
// Unsupported protocol scheme - restclient.Do should fail
//
_, err = Connect("foo://bar.com")
if err == nil {
t.Fatal("Expected error due to unsupported protocol scheme")
}
//
// Not Found
//
_, err = Connect("http://localhost:7474/db/datadatadata")
assert.Equal(t, InvalidDatabase, err)
//
// 200 Success and HTML returned
//
_, err = Connect("http://localhost:7474")
assert.Equal(t, InvalidDatabase, err)
}
示例6: TestRemove
func TestRemove(t *testing.T) {
c := 100
pq := newInFlightPqueue(c)
msgs := make(map[MessageID]*Message)
for i := 0; i < c; i++ {
m := &Message{pri: int64(rand.Intn(100000000))}
copy(m.ID[:], fmt.Sprintf("%016d", m.pri))
msgs[m.ID] = m
pq.Push(m)
}
for i := 0; i < 10; i++ {
idx := rand.Intn((c - 1) - i)
var fm *Message
for _, m := range msgs {
if m.index == idx {
fm = m
break
}
}
rm := pq.Remove(idx)
assert.Equal(t, fmt.Sprintf("%s", fm.ID), fmt.Sprintf("%s", rm.ID))
}
lastPriority := pq.Pop().pri
for i := 0; i < (c - 10 - 1); i++ {
msg := pq.Pop()
assert.Equal(t, lastPriority <= msg.pri, true)
lastPriority = msg.pri
}
}
示例7: subFail
func subFail(t *testing.T, conn io.ReadWriter, topicName string, channelName string) {
err := nsq.Subscribe(topicName, channelName).Write(conn)
assert.Equal(t, err, nil)
resp, err := nsq.ReadResponse(conn)
frameType, _, err := nsq.UnpackResponse(resp)
assert.Equal(t, frameType, nsq.FrameTypeError)
}
示例8: TestRouterGet
func TestRouterGet(t *testing.T) {
handlers := map[string]int{}
router := NewRouter("")
router.CreateHandle(nopeHandleFunc)
//handlers["/"] = false
router.Add("GET", "/", func(ctx *Context) { handlers["/"]++ })
router.Add("GET", "/users", func(ctx *Context) { handlers["/users"]++ })
router.Add("GET", "/users/:userId", func(ctx *Context) { handlers["/users/:userId"]++ })
router.Add("GET", "/users/:userId/sales", func(ctx *Context) { handlers["/users/:userId/sales"]++ })
router.Add("GET", "/users/:userId/sales/:saleId", func(ctx *Context) { handlers["/users/:userId/sales/:saleId"]++ })
router.handle(createContext("GET", ""))
router.handle(createContext("GET", "/users"))
router.handle(createContext("GET", "/users/1"))
router.handle(createContext("GET", "/users/1/?order=asc"))
router.handle(createContext("GET", "/users/sales"))
router.handle(createContext("GET", "/users/_sales"))
router.handle(createContext("GET", "/users/1/sales"))
router.handle(createContext("GET", "/users/1/sales/2"))
assert.Equal(t, 1, handlers["/"])
assert.Equal(t, 1, handlers["/users"])
assert.Equal(t, 3, handlers["/users/:userId"])
assert.Equal(t, 1, handlers["/users/:userId/sales"])
assert.Equal(t, 1, handlers["/users/:userId/sales/:saleId"])
}
示例9: TestNoRequestSignature
func TestNoRequestSignature(t *testing.T) {
st := NewSignatureTest()
defer st.Close()
st.MakeRequestWithExpectedKey("GET", "", "")
assert.Equal(t, 200, st.rw.Code)
assert.Equal(t, st.rw.Body.String(), "no signature received")
}
示例10: 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))
}
示例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: TestInFlightWorker
func TestInFlightWorker(t *testing.T) {
log.SetOutput(ioutil.Discard)
defer log.SetOutput(os.Stdout)
options := NewNsqdOptions()
options.msgTimeout = 300 * time.Millisecond
nsqd = NewNSQd(1, options)
defer nsqd.Exit()
topicName := "test_in_flight_worker" + strconv.Itoa(int(time.Now().Unix()))
topic := nsqd.GetTopic(topicName)
channel := topic.GetChannel("channel")
for i := 0; i < 1000; i++ {
msg := nsq.NewMessage(<-nsqd.idChan, []byte("test"))
channel.StartInFlightTimeout(msg, NewClientV2(nil))
}
assert.Equal(t, len(channel.inFlightMessages), 1000)
assert.Equal(t, len(channel.inFlightPQ), 1000)
time.Sleep(350 * time.Millisecond)
assert.Equal(t, len(channel.inFlightMessages), 0)
assert.Equal(t, len(channel.inFlightPQ), 0)
}
示例13: TestProcessCounters
func TestProcessCounters(t *testing.T) {
Config.PersistCountKeys = int64(10)
counters = make(map[string]int64)
var buffer bytes.Buffer
now := int64(1418052649)
counters["gorets"] = int64(123)
var err error
Config.StoreDb = "/tmp/stats_test.db"
removeFile(Config.StoreDb)
dbHandle, err = bolt.Open(Config.StoreDb, 0644, &bolt.Options{Timeout: 1 * time.Second})
if err != nil {
log.Fatalf("Error opening %s (%s)\n", Config.StoreDb, err)
}
defer closeAndRemove(dbHandle, Config.StoreDb)
num := processCounters(&buffer, now, true, "external", dbHandle)
assert.Equal(t, num, int64(1))
assert.Equal(t, buffer.String(), "gorets 123 1418052649\n")
// run processCounters() enough times to make sure it purges items
for i := 0; i < int(Config.PersistCountKeys)+10; i++ {
num = processCounters(&buffer, now, true, "external", dbHandle)
}
lines := bytes.Split(buffer.Bytes(), []byte("\n"))
// expect two more lines - the good one and an empty one at the end
assert.Equal(t, len(lines), int(Config.PersistCountKeys+2))
assert.Equal(t, string(lines[0]), "gorets 123 1418052649")
assert.Equal(t, string(lines[Config.PersistCountKeys]), "gorets 0 1418052649")
}
示例14: TestInFlightWorker
func TestInFlightWorker(t *testing.T) {
log.SetOutput(ioutil.Discard)
defer log.SetOutput(os.Stdout)
options := NewNSQDOptions()
options.MsgTimeout = 200 * time.Millisecond
nsqd := NewNSQD(options)
defer nsqd.Exit()
topicName := "test_in_flight_worker" + strconv.Itoa(int(time.Now().Unix()))
topic := nsqd.GetTopic(topicName)
channel := topic.GetChannel("channel")
for i := 0; i < 1000; i++ {
msg := nsq.NewMessage(<-nsqd.idChan, []byte("test"))
channel.StartInFlightTimeout(msg, 0)
}
assert.Equal(t, len(channel.inFlightMessages), 1000)
assert.Equal(t, len(channel.inFlightPQ), 1000)
// the in flight worker has a resolution of 100ms so we need to wait
// at least that much longer than our msgTimeout (in worst case)
time.Sleep(options.MsgTimeout + 100*time.Millisecond)
assert.Equal(t, len(channel.inFlightMessages), 0)
assert.Equal(t, len(channel.inFlightPQ), 0)
}
示例15: TestPathWillAugmentExisting
func TestPathWillAugmentExisting(t *testing.T) {
js, err := NewJson([]byte(`{"this":{"a":"aa","b":"bb","c":"cc"}}`))
assert.Equal(t, nil, err)
js.SetPath([]string{"this", "d"}, "dd")
cases := []struct {
path []string
outcome string
}{
{
path: []string{"this", "a"},
outcome: "aa",
},
{
path: []string{"this", "b"},
outcome: "bb",
},
{
path: []string{"this", "c"},
outcome: "cc",
},
{
path: []string{"this", "d"},
outcome: "dd",
},
}
for _, tc := range cases {
s, err := js.GetPath(tc.path...).String()
assert.Equal(t, nil, err)
assert.Equal(t, tc.outcome, s)
}
}