本文整理汇总了Golang中github.com/stretchr/testify/assert.True函数的典型用法代码示例。如果您正苦于以下问题:Golang True函数的具体用法?Golang True怎么用?Golang True使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了True函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestCompoundSetFilter
func TestCompoundSetFilter(t *testing.T) {
assert := assert.New(t)
doTest := func(ts testSet) {
set := ts.toCompoundSet()
sort.Sort(ts)
pivotPoint := 10
pivot := ts.values[pivotPoint]
actual := set.Filter(func(v Value) bool {
return ts.less(v, pivot)
})
assert.True(newTypedSet(ts.tr, ts.values[:pivotPoint+1]...).Equals(actual))
idx := 0
actual.IterAll(func(v Value) {
assert.True(ts.values[idx].Equals(v), "%v != %v", v, ts.values[idx])
idx++
})
}
doTest(getTestNativeOrderSet(16))
doTest(getTestRefValueOrderSet(2))
doTest(getTestRefToNativeOrderSet(2))
doTest(getTestRefToValueOrderSet(2))
}
示例2: TestFormIsValid
// TestFormIsValid tests data that come from request (url.Values)
func TestFormIsValid(t *testing.T) {
postData := url.Values{
"field1": []string{"Foo"},
"field2": []string{"Bar"},
"fieldX": []string{"Ham"},
}
f := Form{
Fields: map[string]*Field{
"field1": &Field{
Type: &Input{},
},
"field2": &Field{
Type: &Input{},
},
},
}
assert.Equal(
t, f.CleanedData, *new(Data),
"CleanedData should be empty at beggining")
assert.True(t, f.IsValid(postData), "Form should pass")
assert.Equal(
t, f.CleanedData, Data{"field1": "Foo", "field2": "Bar"},
"Forms CleanedData field should contain cleaned data")
assert.True(t, f.IsValid(url.Values{}), "Form should pass")
assert.Equal(
t, f.CleanedData, Data{"field1": "", "field2": ""},
"Form should pass")
}
示例3: testAtomicPutCreate
func testAtomicPutCreate(t *testing.T, kv store.Store) {
// Use a key in a new directory to ensure Stores will create directories
// that don't yet exist.
key := "testAtomicPutCreate/create"
value := []byte("putcreate")
// AtomicPut the key, previous = nil indicates create.
success, _, err := kv.AtomicPut(key, value, nil, nil)
assert.NoError(t, err)
assert.True(t, success)
// Get should return the value and an incremented index
pair, err := kv.Get(key)
assert.NoError(t, err)
if assert.NotNil(t, pair) {
assert.NotNil(t, pair.Value)
}
assert.Equal(t, pair.Value, value)
// Attempting to create again should fail.
success, _, err = kv.AtomicPut(key, value, nil, nil)
assert.Error(t, err)
assert.False(t, success)
// This CAS should succeed, since it has the value from Get()
success, _, err = kv.AtomicPut(key, []byte("PUTCREATE"), pair, nil)
assert.NoError(t, err)
assert.True(t, success)
}
示例4: TestEC2RoleProviderExpiryWindowIsExpired
func TestEC2RoleProviderExpiryWindowIsExpired(t *testing.T) {
server := initTestServer("2014-12-16T01:51:37Z", false)
defer server.Close()
p := &ec2rolecreds.EC2RoleProvider{
Client: ec2metadata.New(&ec2metadata.Config{Endpoint: aws.String(server.URL + "/latest")}),
ExpiryWindow: time.Hour * 1,
}
p.CurrentTime = func() time.Time {
return time.Date(2014, 12, 15, 0, 51, 37, 0, time.UTC)
}
assert.True(t, p.IsExpired(), "Expect creds to be expired before retrieve.")
_, err := p.Retrieve()
assert.Nil(t, err, "Expect no error")
assert.False(t, p.IsExpired(), "Expect creds to not be expired after retrieve.")
p.CurrentTime = func() time.Time {
return time.Date(2014, 12, 16, 0, 55, 37, 0, time.UTC)
}
assert.True(t, p.IsExpired(), "Expect creds to be expired.")
}
示例5: TestTypeResolver_AdditionalItems
func TestTypeResolver_AdditionalItems(t *testing.T) {
_, resolver, err := basicTaskListResolver(t)
tpe := spec.StringProperty()
if assert.NoError(t, err) {
// arrays of primitives and string formats with additional formats
for _, val := range schTypeVals {
var sch spec.Schema
sch.Typed(val.Type, val.Format)
var coll spec.Schema
coll.Type = []string{"array"}
coll.Items = new(spec.SchemaOrArray)
coll.Items.Schema = tpe
coll.AdditionalItems = new(spec.SchemaOrBool)
coll.AdditionalItems.Schema = &sch
rt, err := resolver.ResolveSchema(&coll, true)
if assert.NoError(t, err) && assert.True(t, rt.IsArray) {
assert.True(t, rt.HasAdditionalItems)
assert.False(t, rt.IsNullable)
//if assert.NotNil(t, rt.ElementType) {
//assertPrimitiveResolve(t, "string", "", "string", *rt.ElementType)
//}
}
}
}
}
示例6: TestIsSameFile
func TestIsSameFile(t *testing.T) {
absPath, err := filepath.Abs("../tests/files/")
assert.NotNil(t, absPath)
assert.Nil(t, err)
fileInfo1, err := os.Stat(absPath + "/logs/test.log")
fileInfo2, err := os.Stat(absPath + "/logs/system.log")
assert.Nil(t, err)
assert.NotNil(t, fileInfo1)
assert.NotNil(t, fileInfo2)
file1 := &File{
FileInfo: fileInfo1,
}
file2 := &File{
FileInfo: fileInfo2,
}
file3 := &File{
FileInfo: fileInfo2,
}
assert.False(t, file1.IsSameFile(file2))
assert.False(t, file2.IsSameFile(file1))
assert.True(t, file1.IsSameFile(file1))
assert.True(t, file2.IsSameFile(file2))
assert.True(t, file3.IsSameFile(file2))
assert.True(t, file2.IsSameFile(file3))
}
示例7: TestLoadBagValidationConfig
func TestLoadBagValidationConfig(t *testing.T) {
configFilePath := path.Join("testdata", "json_objects", "bag_validation_config.json")
conf, errors := validation.LoadBagValidationConfig(configFilePath)
if errors != nil && len(errors) > 0 {
assert.Fail(t, errors[0].Error())
}
assert.True(t, conf.AllowMiscTopLevelFiles)
assert.True(t, conf.AllowMiscDirectories)
assert.True(t, conf.TopLevelDirMustMatchBagName)
assert.Equal(t, 7, len(conf.FileSpecs))
assert.Equal(t, 3, len(conf.TagSpecs))
assert.Equal(t, 2, len(conf.FixityAlgorithms))
// Spot checks
if _, ok := conf.FileSpecs["manifest-md5.txt"]; !ok {
assert.Fail(t, "FileSpec for manifest-md5.txt is missing")
}
if _, ok := conf.FileSpecs["manifest-sha256.txt"]; !ok {
assert.Fail(t, "FileSpec for manifest-sha256.txt is missing")
}
if _, ok := conf.TagSpecs["Title"]; !ok {
assert.Fail(t, "TagSpec for Title is missing")
}
if len(conf.FixityAlgorithms) > 1 {
assert.Equal(t, "md5", conf.FixityAlgorithms[0])
assert.Equal(t, "sha256", conf.FixityAlgorithms[1])
}
assert.Equal(t, validation.REQUIRED, conf.FileSpecs["manifest-md5.txt"].Presence)
assert.Equal(t, validation.OPTIONAL, conf.FileSpecs["manifest-sha256.txt"].Presence)
assert.Equal(t, "aptrust-info.txt", conf.TagSpecs["Title"].FilePath)
assert.Equal(t, validation.REQUIRED, conf.TagSpecs["Title"].Presence)
assert.False(t, conf.TagSpecs["Title"].EmptyOK)
assert.Equal(t, 3, len(conf.TagSpecs["Access"].AllowedValues))
}
示例8: TestHttpParser_301_response
func TestHttpParser_301_response(t *testing.T) {
if testing.Verbose() {
logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"http"})
}
data := "HTTP/1.1 301 Moved Permanently\r\n" +
"Date: Sun, 29 Sep 2013 16:53:59 GMT\r\n" +
"Server: Apache\r\n" +
"Location: http://www.hotnews.ro/\r\n" +
"Vary: Accept-Encoding\r\n" +
"Content-Length: 290\r\n" +
"Connection: close\r\n" +
"Content-Type: text/html; charset=iso-8859-1\r\n" +
"\r\n" +
"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n" +
"<html><head>\r\n" +
"<title>301 Moved Permanently</title>\r\n" +
"</head><body>\r\n" +
"<h1>Moved Permanently</h1>\r\n" +
"<p>The document has moved <a href=\"http://www.hotnews.ro/\">here</a>.</p>\r\n" +
"<hr>\r\n" +
"<address>Apache Server at hotnews.ro Port 80</address>\r\n" +
"</body></html>"
msg, ok, complete := testParse(nil, data)
assert.True(t, ok)
assert.True(t, complete)
assert.Equal(t, 290, msg.contentLength)
}
示例9: TestHttpParser_censorPasswordPOST
func TestHttpParser_censorPasswordPOST(t *testing.T) {
if testing.Verbose() {
logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"http", "httpdetailed"})
}
http := httpModForTests()
http.hideKeywords = []string{"password"}
http.parserConfig.sendHeaders = true
http.parserConfig.sendAllHeaders = true
data1 :=
"POST /users/login HTTP/1.1\r\n" +
"HOST: www.example.com\r\n" +
"Content-Type: application/x-www-form-urlencoded\r\n" +
"Content-Length: 28\r\n" +
"\r\n" +
"username=ME&password=secret\r\n"
tp := newTestParser(http, data1)
msg, ok, complete := tp.parse()
assert.True(t, ok)
assert.True(t, complete)
rawMsg := tp.stream.data[tp.stream.message.start:tp.stream.message.end]
path, params, err := http.extractParameters(msg, rawMsg)
assert.Nil(t, err)
assert.Equal(t, "/users/login", path)
assert.False(t, strings.Contains(params, "secret"))
}
示例10: TestHttpParser_splitResponse_midHeaderName
func TestHttpParser_splitResponse_midHeaderName(t *testing.T) {
http := httpModForTests()
http.parserConfig.sendHeaders = true
http.parserConfig.sendAllHeaders = true
data1 := "HTTP/1.1 200 OK\r\n" +
"Date: Tue, 14 Aug 2012 22:31:45 GMT\r\n" +
"Expires: -1\r\n" +
"Cache-Control: private, max-age=0\r\n" +
"Content-Type: text/html; charset=UTF-8\r\n" +
"Content-En"
data2 := "coding: gzip\r\n" +
"Server: gws\r\n" +
"Content-Length: 0\r\n" +
"X-XSS-Protection: 1; mode=block\r\n" +
"X-Frame-Options: SAMEORIGIN\r\n" +
"\r\n"
tp := newTestParser(http, data1, data2)
_, ok, complete := tp.parse()
assert.True(t, ok)
assert.False(t, complete)
message, ok, complete := tp.parse()
assert.True(t, ok)
assert.True(t, complete)
assert.False(t, message.isRequest)
assert.Equal(t, 200, int(message.statusCode))
assert.Equal(t, "OK", string(message.statusPhrase))
assert.True(t, isVersion(message.version, 1, 1))
assert.Equal(t, 262, int(message.size))
assert.Equal(t, 0, message.contentLength)
}
示例11: TestHttpParser_splitResponse_midBody
func TestHttpParser_splitResponse_midBody(t *testing.T) {
data1 := "HTTP/1.1 200 OK\r\n" +
"Date: Tue, 14 Aug 2012 22:31:45 GMT\r\n" +
"Expires: -1\r\n" +
"Cache-Control: private, max-age=0\r\n" +
"Content-Type: text/html; charset=UTF-8\r\n" +
"Content-Encoding: gzip\r\n" +
"Server: gws\r\n" +
"Content-Length: 3"
data2 := "0\r\n" +
"X-XSS-Protection: 1; mode=block\r\n" +
"X-Frame-Options: SAMEORIGIN\r\n" +
"\r\n" +
"xxxxxxxxxx"
data3 := "xxxxxxxxxxxxxxxxxxxx"
tp := newTestParser(nil, data1, data2, data3)
_, ok, complete := tp.parse()
assert.True(t, ok)
assert.False(t, complete)
_, ok, complete = tp.parse()
assert.True(t, ok)
assert.False(t, complete)
message, ok, complete := tp.parse()
assert.True(t, ok)
assert.True(t, complete)
assert.Equal(t, 30, message.contentLength)
assert.Equal(t, []byte(""), tp.stream.data[tp.stream.parseOffset:])
}
示例12: TestHttpParser_eatBody_connclose
func TestHttpParser_eatBody_connclose(t *testing.T) {
if testing.Verbose() {
logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"http", "httpdetailed"})
}
http := httpModForTests()
http.parserConfig.sendHeaders = true
http.parserConfig.sendAllHeaders = true
data := []byte("HTTP/1.1 200 ok\r\n" +
"user-agent: curl/7.35.0\r\n" +
"host: localhost:9000\r\n" +
"accept: */*\r\n" +
"authorization: Company 1\r\n" +
"connection: close\r\n" +
"\r\n" +
"0123456789")
st := &stream{data: data, message: new(message)}
ok, complete := testParseStream(http, st, 0)
assert.True(t, ok)
assert.False(t, complete)
assert.Equal(t, st.bodyReceived, 10)
ok, complete = testParseStream(http, st, 5)
assert.True(t, ok)
assert.False(t, complete)
assert.Equal(t, st.bodyReceived, 15)
ok, complete = testParseStream(http, st, 5)
assert.True(t, ok)
assert.False(t, complete)
assert.Equal(t, st.bodyReceived, 20)
}
示例13: TestHttpParser_simpleRequest
func TestHttpParser_simpleRequest(t *testing.T) {
http := httpModForTests()
http.parserConfig.sendHeaders = true
http.parserConfig.sendAllHeaders = true
data := "GET / HTTP/1.1\r\n" +
"Host: www.google.ro\r\n" +
"Connection: keep-alive\r\n" +
"User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.75 Safari/537.1\r\n" +
"Accept: */*\r\n" +
"X-Chrome-Variations: CLa1yQEIj7bJAQiftskBCKS2yQEIp7bJAQiptskBCLSDygE=\r\n" +
"Referer: http://www.google.ro/\r\n" +
"Accept-Encoding: gzip,deflate,sdch\r\n" +
"Accept-Language: en-US,en;q=0.8\r\n" +
"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3\r\n" +
"Cookie: PREF=ID=6b67d166417efec4:U=69097d4080ae0e15:FF=0:TM=1340891937:LM=1340891938:S=8t97UBiUwKbESvVX; NID=61=sf10OV-t02wu5PXrc09AhGagFrhSAB2C_98ZaI53-uH4jGiVG_yz9WmE3vjEBcmJyWUogB1ZF5puyDIIiB-UIdLd4OEgPR3x1LHNyuGmEDaNbQ_XaxWQqqQ59mX1qgLQ\r\n" +
"\r\n" +
"garbage"
message, ok, complete := testParse(http, data)
assert.True(t, ok)
assert.True(t, complete)
assert.True(t, message.isRequest)
assert.True(t, isVersion(message.version, 1, 1))
assert.Equal(t, 669, int(message.size))
assert.Equal(t, "GET", string(message.method))
assert.Equal(t, "/", string(message.requestURI))
assert.Equal(t, "www.google.ro", string(message.headers["host"]))
}
示例14: TestHttp_configsSettingAll
func TestHttp_configsSettingAll(t *testing.T) {
http := httpModForTests()
config := defaultConfig
// Assign config vars
config.Ports = []int{80, 8080}
config.SendRequest = true
config.SendResponse = true
config.HideKeywords = []string{"a", "b"}
config.RedactAuthorization = true
config.SendAllHeaders = true
config.SplitCookie = true
config.RealIPHeader = "X-Forwarded-For"
// Set config
http.setFromConfig(&config)
// Check if http config is set correctly
assert.Equal(t, config.Ports, http.ports)
assert.Equal(t, config.Ports, http.GetPorts())
assert.Equal(t, config.SendRequest, http.sendRequest)
assert.Equal(t, config.SendResponse, http.sendResponse)
assert.Equal(t, config.HideKeywords, http.hideKeywords)
assert.Equal(t, config.RedactAuthorization, http.redactAuthorization)
assert.True(t, http.parserConfig.sendHeaders)
assert.True(t, http.parserConfig.sendAllHeaders)
assert.Equal(t, config.SplitCookie, http.splitCookie)
assert.Equal(t, strings.ToLower(config.RealIPHeader), http.parserConfig.realIPHeader)
}
示例15: TestDoNotDeleteMirrorPods
func TestDoNotDeleteMirrorPods(t *testing.T) {
staticPod := getTestPod()
staticPod.Annotations = map[string]string{kubetypes.ConfigSourceAnnotationKey: "file"}
mirrorPod := getTestPod()
mirrorPod.UID = "mirror-12345678"
mirrorPod.Annotations = map[string]string{
kubetypes.ConfigSourceAnnotationKey: "api",
kubetypes.ConfigMirrorAnnotationKey: "mirror",
}
// Set the deletion timestamp.
mirrorPod.DeletionTimestamp = new(unversioned.Time)
client := fake.NewSimpleClientset(mirrorPod)
m := newTestManager(client)
m.podManager.AddPod(staticPod)
m.podManager.AddPod(mirrorPod)
// Verify setup.
assert.True(t, kubepod.IsStaticPod(staticPod), "SetUp error: staticPod")
assert.True(t, kubepod.IsMirrorPod(mirrorPod), "SetUp error: mirrorPod")
assert.Equal(t, m.podManager.TranslatePodUID(mirrorPod.UID), staticPod.UID)
status := getRandomPodStatus()
now := unversioned.Now()
status.StartTime = &now
m.SetPodStatus(staticPod, status)
m.testSyncBatch()
// Expect not to see an delete action.
verifyActions(t, m.kubeClient, []core.Action{
core.GetActionImpl{ActionImpl: core.ActionImpl{Verb: "get", Resource: "pods"}},
core.UpdateActionImpl{ActionImpl: core.ActionImpl{Verb: "update", Resource: "pods", Subresource: "status"}},
})
}