本文整理汇总了Golang中github.com/smartystreets/goconvey/convey.Convey函数的典型用法代码示例。如果您正苦于以下问题:Golang Convey函数的具体用法?Golang Convey怎么用?Golang Convey使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Convey函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestResolveAndReject
func TestResolveAndReject(t *testing.T) {
c.Convey("When Promise is resolved", t, func() {
p := NewPromise()
go func() {
time.Sleep(50 * time.Millisecond)
p.Resolve("ok")
}()
c.Convey("Should return the argument of Resolve", func() {
r, err := p.Get()
c.So(r, c.ShouldEqual, "ok")
c.So(err, c.ShouldBeNil)
})
})
c.Convey("When Promise is rejected", t, func() {
p := NewPromise()
go func() {
time.Sleep(50 * time.Millisecond)
p.Reject(errors.New("fail"))
}()
c.Convey("Should return error", func() {
r, err := p.Get()
c.So(err, c.ShouldNotBeNil)
c.So(r, c.ShouldEqual, nil)
})
})
}
示例2: TestCertGen
func TestCertGen(t *testing.T) {
origdir, tmpdir := GenTempDir()
//fmt.Printf("attempting to generate certs in tempdir: '%s'\n", tmpdir)
defer CleanupTempDir(origdir, tmpdir)
cv.Convey("Given a built generate_cert/generate_cert utility program", t, func() {
cv.Convey("it should generate certs in our temp directory of the expected file length.", func() {
c := exec.Command(origdir + "/generate_cert/generate_cert")
_, err := c.Output()
if err != nil {
panic(err)
}
certExists, certFi := FileExists(tmpdir + "/cert.pem")
keyExists, keyFi := FileExists(tmpdir + "/key.pem")
//fmt.Printf("certFi = %#v\n", certFi)
//fmt.Printf("keyFi = %#v\n", keyFi)
cv.So(certExists, cv.ShouldEqual, true)
cv.So(keyExists, cv.ShouldEqual, true)
cv.So(certFi.Size(), cv.ShouldEqual, 1074)
cv.So(keyFi.Size(), cv.ShouldBeGreaterThan, 1600)
})
})
}
示例3: TestOrderBy
func TestOrderBy(t *testing.T) {
unsorted := []*foo{&foo{"A", 5}, &foo{"B", 1}, &foo{"C", 3}}
sorted := []*foo{&foo{"B", 1}, &foo{"C", 3}, &foo{"A", 5}}
sortByNum := func(this T, that T) bool {
_this := this.(*foo)
_that := that.(*foo)
return _this.num <= _that.num
}
c.Convey("Nil comparator passed", t, func() {
_, err := From(unsorted).OrderBy(nil).Results()
c.So(err, c.ShouldEqual, ErrNilFunc)
})
c.Convey("Previous error is reflected in result", t, func() {
_, err := From(unsorted).Where(erroneusBinaryFunc).OrderBy(sortByNum).Results()
c.So(err, c.ShouldNotEqual, nil)
})
c.Convey("Sort empty", t, func() {
res, _ := From(empty).OrderBy(sortByNum).Results()
c.So(res, shouldSlicesResemble, empty)
})
c.Convey("Sort on structs", t, func() {
res, _ := From(unsorted).OrderBy(sortByNum).Results()
c.So(res, shouldSlicesResemble, sorted)
})
}
示例4: TestGroupBy
func TestGroupBy(t *testing.T) {
c.Convey("Group empty slice into empty map", t, func() {
res, err := From(empty).GroupBy(func(foo T) T { return foo }, func(foo T) T { return foo })
c.So(err, c.ShouldEqual, nil)
c.So(res, c.ShouldResemble, make(map[T][]T))
})
type Pet struct {
Name string
Owner string
}
barley := Pet{Name: "Barley", Owner: "Damon Zhao"}
boots := Pet{Name: "Boots", Owner: "Damon Zhao"}
whiskers := Pet{Name: "Whiskers", Owner: "A-limon"}
daisy := Pet{Name: "Daisy", Owner: "A-limon"}
sasha := Pet{Name: "Sasha", Owner: "Bob"}
pets := []Pet{barley, boots, whiskers, daisy, sasha}
groupByExpected := map[T][]T{
"Damon Zhao": []T{barley.Name, boots.Name},
"A-limon": []T{whiskers.Name, daisy.Name},
"Bob": []T{sasha.Name},
}
c.Convey("Pets group by owner", t, func() {
res, err := From(pets).GroupBy(func(pet T) T { return pet.(Pet).Owner }, func(pet T) T { return pet.(Pet).Name })
c.So(err, c.ShouldEqual, nil)
c.So(res, c.ShouldResemble, groupByExpected)
})
}
示例5: TestCreateQuestion
func TestCreateQuestion(t *testing.T) {
t_conn.Exec("delete from ebs_question")
var qId int64
convey.Convey("CreateQuestion", t, func() {
parse := CreateQuestionFunc(1)
fmt.Println(parse)
qId, _ = strconv.ParseInt(fmt.Sprintf("%v", parse["data"]), 10, 64)
var v url.Values = make(map[string][]string)
v.Add("id", fmt.Sprintf("%v", parse["data"]))
hs := hsBuilder("POST", "", v, 5, "liuqg")
GetQuestionInfo(hs)
json.Unmarshal(*hs.W.(writer).B, &parse)
convey.So(parse["data"].(map[string]interface{})["desc"], convey.ShouldEqual, "desc")
})
convey.Convey("CreateQuestion 50", t, func() {
parse := CreateQuestionFunc2(1)
fmt.Println(parse)
qId, _ = strconv.ParseInt(fmt.Sprintf("%v", parse["data"]), 10, 64)
var v url.Values = make(map[string][]string)
v.Add("id", fmt.Sprintf("%v", parse["data"]))
hs := hsBuilder("POST", "", v, 5, "liuqg")
GetQuestionInfo(hs)
json.Unmarshal(*hs.W.(writer).B, &parse)
fmt.Println(parse)
// convey.So(parse["data"].(map[string]interface {})["desc"],convey.ShouldEqual,"desc")
})
}
示例6: TestAnyWithParallel
func TestAnyWithParallel(t *testing.T) {
c.Convey("Previous error is reflected on result", t, func() {
_, err := From(arr0).Where(erroneusBinaryFunc).AsParallel().AnyWith(alwaysTrueDelayed)
c.So(err, c.ShouldNotEqual, nil)
})
c.Convey("Given a nil function, ErrNilFunc is returned", t, func() {
_, err := From(arr0).Where(alwaysTrueDelayed).AsParallel().AnyWith(nil)
c.So(err, c.ShouldNotEqual, nil)
})
c.Convey("An error returned from f is reflected on Result", t, func() {
_, err := From(arr0).Where(alwaysTrueDelayed).AsParallel().AnyWith(erroneusBinaryFunc)
c.So(err, c.ShouldNotEqual, nil)
_, err = From(arr0).Where(alwaysFalse).AsParallel().AnyWith(erroneusBinaryFunc)
c.So(err, c.ShouldEqual, nil)
})
c.Convey("No matches", t, func() {
r, _ := From(arr0).AsParallel().AnyWith(alwaysFalseDelayed)
c.So(r, c.ShouldEqual, false)
r, _ = From(arr0).AsParallel().Where(alwaysFalseDelayed).Any()
c.So(r, c.ShouldEqual, false)
})
c.Convey("All matches", t, func() {
r, _ := From(arr0).AsParallel().AnyWith(alwaysTrueDelayed)
c.So(r, c.ShouldEqual, true)
r, _ = From(arr0).AsParallel().Where(alwaysTrueDelayed).Any()
c.So(r, c.ShouldEqual, true)
})
}
示例7: TestFormat
func TestFormat(t *testing.T) {
c.Convey("Given format funcs", t, func() {
funcs := map[string]func(string, ...interface{}){
"Printf": Printf,
"Tracef": Tracef,
"Debugf": Debugf,
"Infof": Infof,
"Warningf": Warningf,
"Errorf": Errorf,
}
writer := &MockWriter{}
Writer = writer
Level = LevelTrace
for name, fun := range funcs {
c.Convey(name+" format should work", func() {
fun("%s answer: %d", name, 42)
c.So(writer.GetLastLog(), c.ShouldEqual, name+" answer: 42")
})
}
c.Convey("Fatalf format should work", func() {
c.So(func() { Fatalf("answer: %d", 42) }, c.ShouldPanic)
c.So(writer.GetLastLog(), c.ShouldEqual, "answer: 42")
})
})
}
示例8: TestNewUUID
func TestNewUUID(t *testing.T) {
uuid := NewUUID()
convey.Convey("uuid should not be nil", t, func() {
convey.So(uuid, convey.ShouldNotEqual, nil)
})
uuid2 := NewUUID()
convey.Convey("uuid should not be equl to uuid", t, func() {
convey.So(uuid, convey.ShouldNotEqual, uuid2)
})
for i := 0; i < 100; i++ {
u := NewUUID()
str := u.String()
version := str[14:15]
key := str[19:20]
// convey.Convey("uuid Version should not be equl to 4", t, func() {
// convey.So(version, convey.ShouldEqual, "4")
// })
if version != "4" {
t.Error("Version must Be == 4 not ", version, " in ", str)
}
if key != "8" && key != "9" && key != "a" && key != "b" {
t.Error("key must be Equal 8, 9, a, b not:", key, " in ", str)
}
}
}
示例9: TestCountParallel
func TestCountParallel(t *testing.T) {
c.Convey("Previous error is reflected on result", t, func() {
_, err := From(arr0).AsParallel().Where(erroneusBinaryFunc).CountBy(erroneusBinaryFunc)
c.So(err, c.ShouldNotEqual, nil)
})
c.Convey("Given a nil function, ErrNilFunc is returned", t, func() {
_, err := From(arr0).AsParallel().Where(alwaysTrueDelayed).CountBy(nil)
c.So(err, c.ShouldNotEqual, nil)
})
c.Convey("An error returned from f is reflected on Result", t, func() {
_, err := From(arr0).AsParallel().Where(alwaysTrueDelayed).CountBy(erroneusBinaryFunc)
c.So(err, c.ShouldNotEqual, nil)
_, err = From(arr0).AsParallel().Where(alwaysFalseDelayed).CountBy(erroneusBinaryFunc)
c.So(err, c.ShouldEqual, nil)
})
c.Convey("No matches", t, func() {
cnt, _ := From(arr0).AsParallel().CountBy(alwaysFalseDelayed)
c.So(cnt, c.ShouldEqual, 0)
cnt, _ = From(arr0).AsParallel().Where(alwaysFalseDelayed).Count()
c.So(cnt, c.ShouldEqual, 0)
})
c.Convey("All matches", t, func() {
cnt, _ := From(arr0).AsParallel().CountBy(alwaysTrueDelayed)
c.So(cnt, c.ShouldEqual, len(arr0))
cnt, _ = From(arr0).AsParallel().Count()
c.So(cnt, c.ShouldEqual, len(arr0))
})
}
示例10: TestMailBodyExtraction
func TestMailBodyExtraction(t *testing.T) {
cv.Convey("Given a GoCD success mail message", t, func() {
cv.Convey("we should be able to extract the body", func() {
cv.So(BodyOfMail(rawPassedEmail), cv.ShouldEqual, expectedPassedBody)
})
})
}
示例11: TestInsert
func TestInsert(t *testing.T) {
h := offheap.NewHashTable(8)
cv.Convey("inserting a non-zero key should enable retrieving them with Lookup", t, func() {
cv.So(h.Population, cv.ShouldEqual, 0)
cv.So(h.Lookup(23), cv.ShouldEqual, nil)
c, ok := h.Insert(23)
c.SetInt(55)
cv.So(c, cv.ShouldNotEqual, nil)
cv.So(ok, cv.ShouldEqual, true)
cv.So(h.Population, cv.ShouldEqual, 1)
cv.So(h.Lookup(23), cv.ShouldNotEqual, nil)
cell := h.Lookup(23)
cv.So(cell.Value[0], cv.ShouldEqual, 55)
})
h.Clear()
cv.Convey("inserting a zero key should also be retrievable with Lookup", t, func() {
cv.So(h.Population, cv.ShouldEqual, 0)
cv.So(h.Lookup(0), cv.ShouldEqual, nil)
c, ok := h.Insert(0)
c.SetInt(55)
cv.So(c, cv.ShouldNotEqual, nil)
cv.So(ok, cv.ShouldEqual, true)
cv.So(h.Population, cv.ShouldEqual, 1)
cv.So(h.Lookup(0), cv.ShouldNotEqual, nil)
cell := h.Lookup(0)
cv.So(cell.Value[0], cv.ShouldEqual, 55)
})
h.Clear()
cv.Convey("Insert()-ing the same key twice should return false for the 2nd param on encountering the same key again. For 0 key.", t, func() {
cv.So(h.Population, cv.ShouldEqual, 0)
c, ok := h.Insert(0)
cv.So(c, cv.ShouldNotEqual, nil)
cv.So(c.UnHashedKey, cv.ShouldEqual, 0)
cv.So(ok, cv.ShouldEqual, true)
c, ok = h.Insert(0)
cv.So(c, cv.ShouldNotEqual, nil)
cv.So(c.UnHashedKey, cv.ShouldEqual, 0)
cv.So(ok, cv.ShouldEqual, false)
})
h.Clear()
cv.Convey("Insert()-ing the same key twice should return false for the 2nd param on encountering the same key again. For not-zero key.", t, func() {
cv.So(h.Population, cv.ShouldEqual, 0)
c, ok := h.Insert(1)
cv.So(c, cv.ShouldNotEqual, nil)
cv.So(c.UnHashedKey, cv.ShouldEqual, 1)
cv.So(ok, cv.ShouldEqual, true)
c, ok = h.Insert(1)
cv.So(c, cv.ShouldNotEqual, nil)
cv.So(c.UnHashedKey, cv.ShouldEqual, 1)
cv.So(ok, cv.ShouldEqual, false)
})
}
示例12: TestErrors
func TestErrors(t *testing.T) {
con.Convey("Verbose printing tests", t, func() {
Verbose = true
stdout := os.Stdout
fname := filepath.Join(tempDir, "stdout1")
temp, err := os.Create(fname)
con.So(err, con.ShouldBeNil)
os.Stdout = temp
testString := "This is a test string"
Printf(testString)
err = temp.Close()
con.So(err, con.ShouldBeNil)
output, err := ioutil.ReadFile(fname)
con.Convey("We can print to stdout when verbose is enabled", func() {
con.So(err, con.ShouldBeNil)
con.So(string(output), con.ShouldEqual, testString)
})
Verbose = false
fname = filepath.Join(tempDir, "stdout1")
temp, err = os.Create(fname)
con.So(err, con.ShouldBeNil)
os.Stdout = temp
Printf(testString)
err = temp.Close()
con.So(err, con.ShouldBeNil)
output, err = ioutil.ReadFile(fname)
con.Convey("We can not print to stdout when verbose is enabled", func() {
con.So(err, con.ShouldBeNil)
con.So(string(output), con.ShouldEqual, "")
})
os.Stdout = stdout
})
con.Convey("Mutually exclusive parameters returns an error in the format we expect", t, func() {
err := ErrMutuallyExclusiveParameters("1", "2")
con.So(err.Error(), con.ShouldEqual, "Mutually exclusive parameters provided: 1 and 2")
})
con.Convey("We can test http formatting", t, func() {
testErr := errors.New("Test error")
errBytes := FormatHTTPError(testErr, 400)
type ErrResp struct {
Message string `json:"error"`
Code int `json:"status_code"`
}
fmt.Println(string(errBytes))
errResp := &ErrResp{}
err := json.Unmarshal(errBytes, &errResp)
con.So(err, con.ShouldBeNil)
con.So(errResp.Code, con.ShouldEqual, 400)
con.So(errResp.Message, con.ShouldEqual, testErr.Error())
})
}
示例13: TestBadWriter
func TestBadWriter(t *testing.T) {
c.Convey("Given bad writer", t, func() {
Writer = BadWriter{}
c.Convey("Log should not fail", func() {
c.So(func() { printString("hi, bad writer") }, c.ShouldNotPanic)
})
})
}
示例14: TestGitRevisionRetrieval
func TestGitRevisionRetrieval(t *testing.T) {
cv.Convey("Given a GoCD passing email message", t, func() {
cv.Convey("the git revision: line should be extracted from the body", func() {
parsedEmail := ParseEmail(rawPassedEmail)
cv.So(parsedEmail.GitRev, cv.ShouldEqual, "0111df6930fa11a28febde2197b591a5a67fb3e4, modified by Jason E. Aten <[email protected]> on 2014-07-21 15:36:00.0")
})
})
}
示例15: TestLoadConfig
func TestLoadConfig(t *testing.T) {
LoadConfig("./", "configTest")
convey.Convey("v should not be nil", t, func() {
convey.So(v, convey.ShouldNotEqual, nil)
})
convey.Convey("v should not be nil", t, func() {
convey.So(v, convey.ShouldNotEqual, nil)
})
}