• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang assert.Equal函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/bmizerany/assert.Equal函数的典型用法代码示例。如果您正苦于以下问题:Golang Equal函数的具体用法?Golang Equal怎么用?Golang Equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Equal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
开发者ID:kortschak,项目名称:dilithium,代码行数:30,代码来源:disk_queue_test.go


示例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)
}
开发者ID:nkwangleiGIT,项目名称:dockerboard,代码行数:7,代码来源:progress_test.go


示例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()))
}
开发者ID:nkwangleiGIT,项目名称:dockerboard,代码行数:27,代码来源:progress_test.go


示例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)
}
开发者ID:dcjones,项目名称:doozerd,代码行数:28,代码来源:peer_test.go


示例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)
}
开发者ID:jmcvetta,项目名称:neo4j,代码行数:26,代码来源:database_test.go


示例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
	}
}
开发者ID:reqshark,项目名称:nsq,代码行数:32,代码来源:in_flight_pqueue_test.go


示例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)
}
开发者ID:sunminghong,项目名称:nsq,代码行数:7,代码来源:protocol_v2_test.go


示例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"])

}
开发者ID:erichnascimento,项目名称:rocket,代码行数:28,代码来源:router_test.go


示例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")
}
开发者ID:coreos,项目名称:oauth2_proxy,代码行数:7,代码来源:oauthproxy_test.go


示例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))
}
开发者ID:jingweno,项目名称:gh,代码行数:31,代码来源:authorizations_test.go


示例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))
}
开发者ID:jingweno,项目名称:gh,代码行数:35,代码来源:authorizations_test.go


示例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)
}
开发者ID:rblomberg,项目名称:nsq,代码行数:26,代码来源:channel_test.go


示例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")
}
开发者ID:wojtekzw,项目名称:statsdaemon,代码行数:35,代码来源:statsdaemon_test.go


示例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)
}
开发者ID:johntdyer,项目名称:golang-devops-stuff,代码行数:28,代码来源:channel_test.go


示例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)
	}
}
开发者ID:mowings,项目名称:go-simplejson,代码行数:34,代码来源:simplejson_test.go


示例16: TestConsumer_Start_Handler

func TestConsumer_Start_Handler(t *testing.T) {
	done := make(chan bool)
	b := new(bytes.Buffer)
	l := log.New(b, "", 0)

	c := queue.NewConsumer("events", "ingestion")
	c.SetLogger(l, nsq.LogLevelDebug)

	c.Set("nsqd", ":5001")
	c.Set("nsqds", []interface{}{":5001"})
	c.Set("concurrency", 5)
	c.Set("max_attempts", 10)
	c.Set("max_in_flight", 150)
	c.Set("default_requeue_delay", "15s")

	err := c.Start(nsq.HandlerFunc(func(msg *nsq.Message) error {
		done <- true
		return nil
	}))

	assert.Equal(t, nil, err)

	go func() {
		p, err := nsq.NewProducer(":5001", nsq.NewConfig())
		check(err)
		p.Publish("events", []byte("hello"))
	}()

	<-done
	assert.Equal(t, nil, c.Stop())
}
开发者ID:ibmendoza,项目名称:go-queue,代码行数:31,代码来源:consumer_test.go


示例17: TestLowerPercentile

func TestLowerPercentile(t *testing.T) {
	// Some data with expected mean of 20
	d := []byte("time:0|ms\ntime:1|ms\ntime:2|ms\ntime:3|ms")
	packets := udp.ParseMessage(d, prefix_internal, output, udp.ParseLine)

	pct, _ := timers.NewPercentiles("-75")
	ti := timers.New("", *pct)

	for _, p := range packets {
		ti.Add(p)
	}

	var buff bytes.Buffer
	var num int64
	num += ti.Process(&buff, time.Now().Unix(), 10)

	assert.Equal(t, num, int64(1))
	dataForGraphite := buff.String()

	meanRegexp := regexp.MustCompile(`time\.upper_75 1\.`)
	matched := meanRegexp.MatchString(dataForGraphite)
	assert.Equal(t, matched, false)

	meanRegexp = regexp.MustCompile(`time\.lower_75 1\.`)
	matched = meanRegexp.MatchString(dataForGraphite)
	assert.Equal(t, matched, true)
}
开发者ID:deepglint,项目名称:statsdaemon,代码行数:27,代码来源:statsdaemon_test.go


示例18: TestCountersLegacyNamespaceFalse

func TestCountersLegacyNamespaceFalse(t *testing.T) {
	cnt := counters.New("rates.", "counters.", false, true, true)
	dataForGraphite, num := getGraphiteSendForCounter(cnt, "logins:1|c\nlogins:2|c\nlogins:3|c")

	assert.Equal(t, num, int64(1))
	assert.Equal(t, "counters.logins.count 6 1\nrates.logins.rate 0.6 1\n", dataForGraphite)
}
开发者ID:vimeo,项目名称:statsdaemon,代码行数:7,代码来源:statsdaemon_test.go


示例19: TestStats

func TestStats(t *testing.T) {
	log.SetOutput(ioutil.Discard)
	defer log.SetOutput(os.Stdout)

	options := NewNsqdOptions()
	tcpAddr, _, nsqd := mustStartNSQd(options)
	defer nsqd.Exit()

	topicName := "test_stats" + strconv.Itoa(int(time.Now().Unix()))
	topic := nsqd.GetTopic(topicName)
	msg := nsq.NewMessage(<-nsqd.idChan, []byte("test body"))
	topic.PutMessage(msg)

	conn, err := mustConnectNSQd(tcpAddr)
	assert.Equal(t, err, nil)

	identify(t, conn)
	sub(t, conn, topicName, "ch")

	stats := nsqd.getStats()
	assert.Equal(t, len(stats), 1)
	assert.Equal(t, len(stats[0].Channels), 1)
	assert.Equal(t, len(stats[0].Channels[0].Clients), 1)
	log.Printf("stats: %+v", stats)
}
开发者ID:sunminghong,项目名称:nsq,代码行数:25,代码来源:stats_test.go


示例20: TestCountersLegacyNamespaceTrueFlushCountsFalse

func TestCountersLegacyNamespaceTrueFlushCountsFalse(t *testing.T) {
	cnt := counters.New("stats.", "stats_counts.", true, true, false)
	dataForGraphite, num := getGraphiteSendForCounter(cnt, "logins:1|c\nlogins:2|c\nlogins:3|c")

	assert.Equal(t, num, int64(1))
	assert.Equal(t, "stats.logins 0.6 1\n", dataForGraphite)
}
开发者ID:vimeo,项目名称:statsdaemon,代码行数:7,代码来源:statsdaemon_test.go



注:本文中的github.com/bmizerany/assert.Equal函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang assert.Equalf函数代码示例发布时间:2022-05-24
下一篇:
Golang waf.New函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap