本文整理汇总了Golang中github.com/araddon/gou.Assert函数的典型用法代码示例。如果您正苦于以下问题:Golang Assert函数的具体用法?Golang Assert怎么用?Golang Assert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Assert函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestUrlGenerationNoIndices
func TestUrlGenerationNoIndices(t *testing.T) {
expectedUrl := "/_cluster/health?level=cluster&pretty=true&timeout=30s&wait_for_nodes=1&wait_for_relocating_shards=1&wait_for_status=green"
indices := []string{}
url, err := getHealthUrl(true, "cluster", "green", "30s", 1, 1, indices...)
u.Assert(err == nil, t, fmt.Sprintf("err was not nil: %v", err))
u.Assert(url == expectedUrl, t, fmt.Sprintf("TestUrlGeneration Should get %s, instead got %s", expectedUrl, url))
}
示例2: TestUrlGenerationNoWaits
func TestUrlGenerationNoWaits(t *testing.T) {
expectedUrl := "/_cluster/health/Indice1,Indice2,Indice3?level=cluster&pretty=true&timeout=30s&wait_for_status=green"
indices := []string{"Indice1", "Indice2", "Indice3"}
url, err := getHealthUrl(true, "cluster", "green", "30s", 0, 0, indices...)
u.Assert(err == nil, t, fmt.Sprintf("err was not nil: %v", err))
u.Assert(url == expectedUrl, t, fmt.Sprintf("TestUrlGeneration Should get %s, instead got %s", expectedUrl, url))
}
示例3: TestSearchFields
func TestSearchFields(t *testing.T) {
// same as terms, search using fields:
// how many different docs have jasmine in repository.name?
qry := Search("github").Query(
Query().Fields("repository.name", "jasmine", "", ""),
)
out, _ := qry.Result()
u.Assert(out.Hits.Len() == 4, t, "Should have 4 docs %v", out.Hits.Len())
u.Assert(out.Hits.Total == 4, t, "Should have 4 total= %v", out.Hits.Total)
}
示例4: TestSearchRequest
func TestSearchRequest(t *testing.T) {
qry := map[string]interface{}{
"query": map[string]interface{}{
"wildcard": map[string]string{"actor": "a*"},
},
}
out, err := core.SearchRequest(true, "github", "", qry, "", 0)
//log.Println(out)
u.Assert(&out != nil && err == nil, t, "Should get docs")
u.Assert(out.Hits.Total == 616 && out.Hits.Len() == 10, t, "Should have 616 hits but was %v", out.Hits.Total)
}
示例5: TestSearchTerm
func TestSearchTerm(t *testing.T) {
// ok, now lets try searching with term query (specific field/term)
qry := Search("github").Query(
Query().Term("repository.name", "jasmine"),
)
out, _ := qry.Result()
// how many different docs have jasmine in repository.name?
u.Assert(out.Hits.Len() == 4, t, "Should have 4 docs %v", out.Hits.Len())
u.Assert(out.Hits.Total == 4, t, "Should have 4 total= %v", out.Hits.Total)
}
示例6: TestSearchRange
func TestSearchRange(t *testing.T) {
// now lets filter by a subset of the total time
out, _ := Search("github").Size("25").Query(
Query().Range(
Range().Field("created_at").From("2012-12-10T15:00:00-08:00").To("2012-12-10T15:10:00-08:00"),
).Search("add"),
).Result()
u.Assert(out != nil && &out.Hits != nil, t, "Must not have nil results, or hits")
u.Assert(out.Hits.Len() == 25, t, "Should have 25 docs %v", out.Hits.Len())
u.Assert(out.Hits.Total == 92, t, "Should have total=92 but was %v", out.Hits.Total)
}
示例7: TestBulkErrors
func TestBulkErrors(t *testing.T) {
// lets set a bad port, and hope we get a connection refused error?
api.Port = "27845"
defer func() {
api.Port = "9200"
}()
BulkDelaySeconds = 1
indexor := NewBulkIndexorErrors(10, 1)
done := make(chan bool)
indexor.Run(done)
errorCt := 0
go func() {
for i := 0; i < 20; i++ {
date := time.Unix(1257894000, 0)
data := map[string]interface{}{"name": "smurfs", "age": 22, "date": time.Unix(1257894000, 0)}
indexor.Index("users", "user", strconv.Itoa(i), "", &date, data)
}
}()
for errBuf := range indexor.ErrorChannel {
errorCt++
u.Debug(errBuf.Err)
break
}
u.Assert(errorCt > 0, t, "ErrorCt should be > 0 %d", errorCt)
}
示例8: TestSearchSimple
func TestSearchSimple(t *testing.T) {
// searching without faceting
qry := Search("github").Pretty().Query(
Query().Search("add"),
)
out, _ := qry.Result()
// how many different docs used the word "add"
u.Assert(out.Hits.Len() == 10, t, "Should have 10 docs %v", out.Hits.Len())
u.Assert(out.Hits.Total == 494, t, "Should have 494 total= %v", out.Hits.Total)
// now the same result from a "Simple" search
out, _ = Search("github").Search("add").Result()
u.Assert(out.Hits.Len() == 10, t, "Should have 10 docs %v", out.Hits.Len())
u.Assert(out.Hits.Total == 494, t, "Should have 494 total= %v", out.Hits.Total)
}
示例9: TestSearchFilterQuery
func TestSearchFilterQuery(t *testing.T) {
// compound query + filter with query being wildcard
out, _ := Search("github").Size("25").Query(
Query().Fields("repository.name", "jas*", "", ""),
).Filter(
Filter().Terms("repository.has_wiki", true),
).Result()
if out == nil || &out.Hits == nil {
t.Fail()
return
}
u.Assert(out.Hits.Len() == 7, t, "Should have 7 docs %v", out.Hits.Len())
u.Assert(out.Hits.Total == 7, t, "Should have total=7 but was %v", out.Hits.Total)
}
示例10: TestSearchMissingExists
func TestSearchMissingExists(t *testing.T) {
// search for docs that are missing repository.name
qry := Search("github").Filter(
Filter().Exists("repository.name"),
)
out, _ := qry.Result()
u.Assert(out.Hits.Len() == 10, t, "Should have 10 docs %v", out.Hits.Len())
u.Assert(out.Hits.Total == 7695, t, "Should have 7695 total= %v", out.Hits.Total)
qry = Search("github").Filter(
Filter().Missing("repository.name"),
)
out, _ = qry.Result()
u.Assert(out.Hits.Len() == 10, t, "Should have 10 docs %v", out.Hits.Len())
u.Assert(out.Hits.Total == 389, t, "Should have 389 total= %v", out.Hits.Total)
}
示例11: TestBulkUpdate
func TestBulkUpdate(t *testing.T) {
InitTests(true)
api.Port = "9200"
indexor := NewBulkIndexor(3)
indexor.BulkSendor = func(buf *bytes.Buffer) error {
messageSets += 1
totalBytesSent += buf.Len()
buffers = append(buffers, buf)
u.Debug(string(buf.Bytes()))
return BulkSend(buf)
}
done := make(chan bool)
indexor.Run(done)
date := time.Unix(1257894000, 0)
user := map[string]interface{}{
"name": "smurfs", "age": 22, "date": time.Unix(1257894000, 0), "count": 1,
}
// Lets make sure the data is in the index ...
_, err := Index(true, "users", "user", "5", user)
// script and params
data := map[string]interface{}{
"script": "ctx._source.count += 2",
}
err = indexor.Update("users", "user", "5", "", &date, data)
// So here's the deal. Flushing does seem to work, you just have to give the
// channel a moment to recieve the message ...
// <- time.After(time.Millisecond * 20)
// indexor.Flush()
done <- true
WaitFor(func() bool {
return len(buffers) > 0
}, 5)
u.Assert(BulkErrorCt == 0 && err == nil, t, "Should not have any errors %v", err)
response, err := Get(true, "users", "user", "5")
u.Assert(err == nil, t, "Should not have any errors %v", err)
newCount := response.Source.(map[string]interface{})["count"]
u.Assert(newCount.(float64) == 3, t, "Should have update count: %#v ... %#v", response.Source.(map[string]interface{})["count"], response)
}
示例12: TestSearchSortOrder
func TestSearchSortOrder(t *testing.T) {
// ok, now lets try sorting by repository watchers descending
qry := Search("github").Pretty().Query(
Query().All(),
).Sort(
Sort("repository.watchers").Desc(),
)
out, _ := qry.Result()
// how many different docs used the word "add", during entire time range
u.Assert(out.Hits.Len() == 10, t, "Should have 10 docs %v", out.Hits.Len())
u.Assert(out.Hits.Total == 8084, t, "Should have 8084 total= %v", out.Hits.Total)
h1 := u.NewJsonHelper(out.Hits.Hits[0].Source)
u.Assert(h1.Int("repository.watchers") == 41377, t, "Should have 41377 watchers= %v", h1.Int("repository.watchers"))
// ascending
out, _ = Search("github").Pretty().Query(
Query().All(),
).Sort(
Sort("repository.watchers"),
).Result()
// how many different docs used the word "add", during entire time range
u.Assert(out.Hits.Len() == 10, t, "Should have 10 docs %v", out.Hits.Len())
u.Assert(out.Hits.Total == 8084, t, "Should have 8084 total= %v", out.Hits.Total)
h2 := u.NewJsonHelper(out.Hits.Hits[0].Source)
u.Assert(h2.Int("repository.watchers") == 0, t, "Should have 0 watchers= %v", h2.Int("repository.watchers"))
// sort descending with search
out, _ = Search("github").Pretty().Size("5").Query(
Query().Search("python"),
).Sort(
Sort("repository.watchers").Desc(),
).Result()
//log.Println(out)
//log.Println(err)
// how many different docs used the word "add", during entire time range
u.Assert(out.Hits.Len() == 5, t, "Should have 5 docs %v", out.Hits.Len())
u.Assert(out.Hits.Total == 734, t, "Should have 734 total= %v", out.Hits.Total)
h3 := u.NewJsonHelper(out.Hits.Hits[0].Source)
u.Assert(h3.Int("repository.watchers") == 8659, t, "Should have 8659 watchers= %v", h3.Int("repository.watchers"))
}
示例13: TestLRUTtlEvict
func TestLRUTtlEvict(t *testing.T) {
// ttl = 1 second, 100 ms heartbeats, should check 10 times
l := NewTimeEvictLru(10000, 200*time.Millisecond, 50*time.Millisecond)
var evictCt int = 0
l.EvictCallback = func(key string, v Value) {
evictCt++
//u.Debug("evicting ", key)
}
for i := 0; i < 100; i++ {
istr := strconv.FormatInt(int64(i), 10)
l.Set("key"+istr, &CacheValue{i})
}
u.WaitFor(func() bool {
return l.Len() == 0
}, 10)
u.Assert(l.Len() == 0, t, "should have evicted all items but still have %d", l.Len())
u.Assert(evictCt == 100, t, "Should have evicted 100 items but have %d", evictCt)
}
示例14: TestSearchFacetRange
func TestSearchFacetRange(t *testing.T) {
// ok, now lets try facet but on actor field with a range
qry := Search("github").Pretty().Facet(
Facet().Fields("actor").Size("500"),
).Query(
Query().Search("add"),
)
out, err := qry.Result()
u.Assert(out != nil && err == nil, t, "Should have output")
if out == nil {
t.Fail()
return
}
//log.Println(string(out.Facets))
h := u.NewJsonHelper(out.Facets)
// how many different docs used the word "add", during entire time range
u.Assert(h.Int("actor.total") == 521, t, "Should have 521 results %v", h.Int("actor.total"))
// make sure size worked
u.Assert(len(h.List("actor.terms")) == 366, t, "Should have 366 unique userids, %v", len(h.List("actor.terms")))
// ok, repeat but with a range showing different results
qry = Search("github").Pretty().Facet(
Facet().Fields("actor").Size("500"),
).Query(
Query().Range(
Range().Field("created_at").From("2012-12-10T15:00:00-08:00").To("2012-12-10T15:10:00-08:00"),
).Search("add"),
)
out, err = qry.Result()
u.Assert(out != nil && err == nil, t, "Should have output")
if out == nil {
t.Fail()
return
}
//log.Println(string(out.Facets))
h = u.NewJsonHelper(out.Facets)
// how many different events used the word "add", during time range?
u.Assert(h.Int("actor.total") == 97, t, "Should have 97 results %v", h.Int("actor.total"))
// make sure size worked
u.Assert(len(h.List("actor.terms")) == 71, t, "Should have 71 event types, %v", len(h.List("actor.terms")))
}
示例15: TestBulkIndexorBasic
func TestBulkIndexorBasic(t *testing.T) {
InitTests(true)
indexor := NewBulkIndexor(3)
indexor.BulkSendor = func(buf *bytes.Buffer) error {
messageSets += 1
totalBytesSent += buf.Len()
buffers = append(buffers, buf)
u.Debug(string(buf.Bytes()))
return BulkSend(buf)
}
done := make(chan bool)
indexor.Run(done)
date := time.Unix(1257894000, 0)
data := map[string]interface{}{"name": "smurfs", "age": 22, "date": time.Unix(1257894000, 0)}
err := indexor.Index("users", "user", "1", "", &date, data)
WaitFor(func() bool {
return len(buffers) > 0
}, 5)
// part of request is url, so lets factor that in
//totalBytesSent = totalBytesSent - len(*eshost)
u.Assert(len(buffers) == 1, t, "Should have sent one operation but was %d", len(buffers))
u.Assert(BulkErrorCt == 0 && err == nil, t, "Should not have any errors %v", err)
u.Assert(totalBytesSent == 145, t, "Should have sent 135 bytes but was %v", totalBytesSent)
err = indexor.Index("users", "user", "2", "", nil, data)
<-time.After(time.Millisecond * 10) // we need to wait for doc to hit send channel
// this will test to ensure that Flush actually catches a doc
indexor.Flush()
totalBytesSent = totalBytesSent - len(*eshost)
u.Assert(err == nil, t, "Should have nil error =%v", err)
u.Assert(len(buffers) == 2, t, "Should have another buffer ct=%d", len(buffers))
u.Assert(BulkErrorCt == 0, t, "Should not have any errors %d", BulkErrorCt)
u.Assert(u.CloseInt(totalBytesSent, 257), t, "Should have sent 257 bytes but was %v", totalBytesSent)
}