本文整理汇总了Golang中github.com/facebookgo/ensure.True函数的典型用法代码示例。如果您正苦于以下问题:Golang True函数的具体用法?Golang True怎么用?Golang True使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了True函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CheckOpsReader
// Verify if the items being read are as expected.
func CheckOpsReader(t *testing.T, loader OpsReader) {
expectedOpsRead := 0
const startingTs = 1396456709420
for op := loader.Next(); op != nil; op = loader.Next() {
expectedOpsRead += 1
ensure.NotNil(t, op)
ensure.DeepEqual(t, loader.OpsRead(), expectedOpsRead)
// check the "ts" field
CheckTime(t, float64(startingTs+loader.OpsRead()), op.Timestamp)
// check the insert doc
// certain key exists
for i := 1; i <= 5; i++ {
logTypeKey := fmt.Sprintf("logType%d", i)
logType, ok := GetElem(op.InsertDoc, logTypeKey)
if i != expectedOpsRead {
ensure.False(t, ok)
ensure.Nil(t, logType)
} else {
ensure.True(t, ok)
ensure.NotNil(t, logType)
}
}
// check the value for the shared key
message := fmt.Sprintf("m%d", expectedOpsRead)
actualMessage, ok := GetElem(op.InsertDoc, "message")
ensure.True(t, ok)
ensure.DeepEqual(t, actualMessage.(string), message)
}
ensure.DeepEqual(t, expectedOpsRead, 5)
}
示例2: TestCmdScoreLess
func TestCmdScoreLess(t *testing.T) {
t.Parallel()
scores := cmdScores([]cmdScore{
{levenshtein: 1, jaroWinkler: 0.9},
{levenshtein: 2, jaroWinkler: 0.8},
})
ensure.True(t, scores.Less(0, 1))
scores = cmdScores([]cmdScore{
{levenshtein: 1, jaroWinkler: 0.9},
{levenshtein: 1, jaroWinkler: 0.8},
})
ensure.True(t, scores.Less(0, 1))
scores = cmdScores([]cmdScore{
{levenshtein: 1, jaroWinkler: 0.8},
{levenshtein: 1, jaroWinkler: 0.9},
})
ensure.False(t, scores.Less(0, 1))
scores = cmdScores([]cmdScore{
{levenshtein: 2, jaroWinkler: 0.9},
{levenshtein: 1, jaroWinkler: 0.8},
})
ensure.False(t, scores.Less(0, 1))
}
示例3: TestWriteBatchIterator
func TestWriteBatchIterator(t *testing.T) {
db := newTestDB(t, "TestWriteBatchIterator", nil)
defer db.Close()
var (
givenKey1 = []byte("key1")
givenVal1 = []byte("val1")
givenKey2 = []byte("key2")
)
// create and fill the write batch
wb := NewWriteBatch()
defer wb.Destroy()
wb.Put(givenKey1, givenVal1)
wb.Delete(givenKey2)
ensure.DeepEqual(t, wb.Count(), 2)
// iterate over the batch
iter := wb.NewIterator()
ensure.True(t, iter.Next())
record := iter.Record()
ensure.DeepEqual(t, record.Type, WriteBatchRecordTypeValue)
ensure.DeepEqual(t, record.Key, givenKey1)
ensure.DeepEqual(t, record.Value, givenVal1)
ensure.True(t, iter.Next())
record = iter.Record()
ensure.DeepEqual(t, record.Type, WriteBatchRecordTypeDeletion)
ensure.DeepEqual(t, record.Key, givenKey2)
// there shouldn't be any left
ensure.False(t, iter.Next())
}
示例4: TestCounters
func TestCounters(t *testing.T) {
coll := NewCounters()
coll.C("get").Incr(1)
coll.C("set").Decr(-1)
ensure.True(t, coll.C("get").Count() == 1)
ensure.True(t, coll.C("del").Count() == 0)
}
示例5: TestNewContainerError
func TestNewContainerError(t *testing.T) {
givenErr := errors.New("")
c, err := NewContainer(func(*Container) error {
return givenErr
})
ensure.True(t, err == givenErr)
ensure.True(t, c == nil)
}
示例6: TestShouldFilterOp
func TestShouldFilterOp(t *testing.T) {
t.Parallel()
ensure.True(t, shouldFilterOp(&Op{Type: Update}, []OpType{Update}))
ensure.True(t, shouldFilterOp(&Op{Type: Update}, []OpType{Update, Query}))
ensure.True(t, shouldFilterOp(&Op{Type: Query}, []OpType{Update, Query}))
ensure.False(t, shouldFilterOp(&Op{Type: Command}, []OpType{Update, Query}))
ensure.False(t, shouldFilterOp(&Op{Type: Command}, []OpType{}))
}
示例7: TestDBTypeOf
func TestDBTypeOf(t *testing.T) {
db := New(newRocksDB(t))
defer db.Close()
db.Set([]byte("name"), []byte("latermoon"))
e := db.TypeOf([]byte("name"))
ensure.True(t, e == STRING)
e = db.TypeOf([]byte("age"))
ensure.True(t, e == NONE)
}
示例8: TestIsFileName
func TestIsFileName(t *testing.T) {
t.Parallel()
ensure.True(t, isFilename("file"))
ensure.True(t, isFilename("star\\*"))
ensure.True(t, isFilename("bracket\\["))
ensure.True(t, isFilename("question\\?"))
ensure.False(t, isFilename("*"))
ensure.False(t, isFilename("?"))
ensure.False(t, isFilename("["))
}
示例9: TestApplyMakesNew
func TestApplyMakesNew(t *testing.T) {
const givenName = "x"
const givenID = "y"
givenContainerConfig := &dockerclient.ContainerConfig{Image: "foo"}
givenHostConfig := &dockerclient.HostConfig{}
var inspectCalls, createCalls, startCalls, afterCreateCalls int
container, err := NewContainer(
ContainerName(givenName),
ContainerConfig(givenContainerConfig),
ContainerHostConfig(givenHostConfig),
ContainerAfterCreate(func(containerID string) error {
afterCreateCalls++
ensure.DeepEqual(t, containerID, givenID)
return nil
}),
)
ensure.Nil(t, err)
client := &mockClient{
inspectContainer: func(name string) (*dockerclient.ContainerInfo, error) {
inspectCalls++
switch inspectCalls {
case 1:
ensure.DeepEqual(t, name, givenName)
return nil, dockerclient.ErrNotFound
case 2:
return &dockerclient.ContainerInfo{Id: givenID}, nil
}
panic("not reached")
},
createContainer: func(config *dockerclient.ContainerConfig, name string) (string, error) {
createCalls++
ensure.True(t, config == givenContainerConfig)
ensure.DeepEqual(t, name, givenName)
return "", nil
},
startContainer: func(id string, config *dockerclient.HostConfig) error {
startCalls++
ensure.DeepEqual(t, id, givenID)
ensure.True(t, config == givenHostConfig)
return nil
},
}
ensure.Nil(t, container.Apply(client))
ensure.DeepEqual(t, inspectCalls, 2)
ensure.DeepEqual(t, createCalls, 1)
ensure.DeepEqual(t, afterCreateCalls, 1)
ensure.DeepEqual(t, startCalls, 1)
}
示例10: TestApplyWithExistingRemoveError
func TestApplyWithExistingRemoveError(t *testing.T) {
const image = "x"
givenErr := errors.New("")
container := &Container{
containerConfig: &dockerclient.ContainerConfig{
Image: image,
},
removeExisting: true,
}
client := &mockClient{
inspectContainer: func(name string) (*dockerclient.ContainerInfo, error) {
return &dockerclient.ContainerInfo{
Id: "y",
Image: "z",
}, nil
},
listImages: func() ([]*dockerclient.Image, error) {
return []*dockerclient.Image{
{
RepoTags: []string{image},
Id: "y",
},
}, nil
},
removeContainer: func(id string, force, volumes bool) error {
return givenErr
},
}
err := container.Apply(client)
ensure.True(t, stackerr.HasUnderlying(err, stackerr.Equals(givenErr)))
}
示例11: TestCheckExistingWithDesiredImage
func TestCheckExistingWithDesiredImage(t *testing.T) {
const image = "x"
const id = "y"
container := &Container{
containerConfig: &dockerclient.ContainerConfig{
Image: image,
},
}
client := &mockClient{
listImages: func() ([]*dockerclient.Image, error) {
return []*dockerclient.Image{
{
RepoTags: []string{image},
Id: id,
},
}, nil
},
}
ci := &dockerclient.ContainerInfo{
Image: id,
Config: &dockerclient.ContainerConfig{},
}
ok, err := container.checkExisting(client, ci)
ensure.Nil(t, err)
ensure.True(t, ok)
}
示例12: TestApplyStartError
func TestApplyStartError(t *testing.T) {
givenErr := errors.New("")
const image = "x"
const id = "y"
container := &Container{
containerConfig: &dockerclient.ContainerConfig{
Image: image,
},
}
client := &mockClient{
inspectContainer: func(name string) (*dockerclient.ContainerInfo, error) {
return &dockerclient.ContainerInfo{
Id: "a",
Image: id,
Config: &dockerclient.ContainerConfig{},
}, nil
},
listImages: func() ([]*dockerclient.Image, error) {
return []*dockerclient.Image{
{
RepoTags: []string{image},
Id: id,
},
}, nil
},
startContainer: func(id string, config *dockerclient.HostConfig) error {
return givenErr
},
}
err := container.Apply(client)
ensure.True(t, stackerr.HasUnderlying(err, stackerr.Equals(givenErr)))
}
示例13: TestWriteBatch
func TestWriteBatch(t *testing.T) {
db := newTestDB(t, "TestWriteBatch", nil)
defer db.Close()
var (
givenKey1 = []byte("key1")
givenVal1 = []byte("val1")
givenKey2 = []byte("key2")
)
wo := NewDefaultWriteOptions()
ensure.Nil(t, db.Put(wo, givenKey2, []byte("foo")))
// create and fill the write batch
wb := NewWriteBatch()
defer wb.Destroy()
wb.Put(givenKey1, givenVal1)
wb.Delete(givenKey2)
ensure.DeepEqual(t, wb.Count(), 2)
// perform the batch
ensure.Nil(t, db.Write(wo, wb))
// check changes
ro := NewDefaultReadOptions()
v1, err := db.Get(ro, givenKey1)
defer v1.Free()
ensure.Nil(t, err)
ensure.DeepEqual(t, v1.Data(), givenVal1)
v2, err := db.Get(ro, givenKey2)
defer v2.Free()
ensure.Nil(t, err)
ensure.True(t, v2.Data() == nil)
}
示例14: TestDBCRUD
func TestDBCRUD(t *testing.T) {
db := newTestDB(t, "TestDBGet", nil)
defer db.Close()
var (
givenKey = []byte("hello")
givenVal1 = []byte("world1")
givenVal2 = []byte("world2")
wo = NewDefaultWriteOptions()
ro = NewDefaultReadOptions()
)
// create
ensure.Nil(t, db.Put(wo, givenKey, givenVal1))
// retrieve
v1, err := db.Get(ro, givenKey)
defer v1.Free()
ensure.Nil(t, err)
ensure.DeepEqual(t, v1.Data(), givenVal1)
// update
ensure.Nil(t, db.Put(wo, givenKey, givenVal2))
v2, err := db.Get(ro, givenKey)
defer v2.Free()
ensure.Nil(t, err)
ensure.DeepEqual(t, v2.Data(), givenVal2)
// delete
ensure.Nil(t, db.Delete(wo, givenKey))
v3, err := db.Get(ro, givenKey)
ensure.Nil(t, err)
ensure.True(t, v3.Data() == nil)
}
示例15: TestAcceptsPath
func TestAcceptsPath(t *testing.T) {
t.Parallel()
i := iosSymbolUploader{Path: testDwarfPath}
ensure.True(t, i.acceptsPath())
i.Path = ""
ensure.False(t, i.acceptsPath())
}