本文整理汇总了Golang中github.com/convox/rack/Godeps/_workspace/src/github.com/stretchr/testify/assert.Nil函数的典型用法代码示例。如果您正苦于以下问题:Golang Nil函数的具体用法?Golang Nil怎么用?Golang Nil使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Nil函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestCanSupportStructWithNestedPointers
func TestCanSupportStructWithNestedPointers(t *testing.T) {
assert := assert.New(t)
data := struct{ A *struct{ B int } }{}
result, err := Search("A.B", data)
assert.Nil(err)
assert.Nil(result)
}
开发者ID:kuenzaa,项目名称:rack,代码行数:7,代码来源:interpreter_test.go
示例2: TestWithFieldsShouldAllowAssignments
func TestWithFieldsShouldAllowAssignments(t *testing.T) {
var buffer bytes.Buffer
var fields Fields
logger := New()
logger.Out = &buffer
logger.Formatter = new(JSONFormatter)
localLog := logger.WithFields(Fields{
"key1": "value1",
})
localLog.WithField("key2", "value2").Info("test")
err := json.Unmarshal(buffer.Bytes(), &fields)
assert.Nil(t, err)
assert.Equal(t, "value2", fields["key2"])
assert.Equal(t, "value1", fields["key1"])
buffer = bytes.Buffer{}
fields = Fields{}
localLog.Info("test")
err = json.Unmarshal(buffer.Bytes(), &fields)
assert.Nil(t, err)
_, ok := fields["key2"]
assert.Equal(t, false, ok)
assert.Equal(t, "value1", fields["key1"])
}
开发者ID:davidcoallier,项目名称:rack-1,代码行数:29,代码来源:logrus_test.go
示例3: TestOutputService4ProtocolTestListsCase2
func TestOutputService4ProtocolTestListsCase2(t *testing.T) {
sess := session.New()
svc := NewOutputService4ProtocolTest(sess, &aws.Config{Endpoint: aws.String("https://test")})
buf := bytes.NewReader([]byte("{\"ListMember\": [\"a\", null], \"ListMemberMap\": [{}, null, null, {}], \"ListMemberStruct\": [{}, null, null, {}]}"))
req, out := svc.OutputService4TestCaseOperation2Request(nil)
req.HTTPResponse = &http.Response{StatusCode: 200, Body: ioutil.NopCloser(buf), Header: http.Header{}}
// set headers
// unmarshal response
jsonrpc.UnmarshalMeta(req)
jsonrpc.Unmarshal(req)
assert.NoError(t, req.Error)
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "a", *out.ListMember[0])
assert.Nil(t, out.ListMember[1])
assert.Nil(t, out.ListMemberMap[1])
assert.Nil(t, out.ListMemberMap[2])
assert.Nil(t, out.ListMemberStruct[1])
assert.Nil(t, out.ListMemberStruct[2])
}
开发者ID:kuenzaa,项目名称:rack,代码行数:25,代码来源:unmarshal_test.go
示例4: TestValidPrecompiledExpressionSearches
func TestValidPrecompiledExpressionSearches(t *testing.T) {
assert := assert.New(t)
data := make(map[string]interface{})
data["foo"] = "bar"
precompiled, err := Compile("foo")
assert.Nil(err)
result, err := precompiled.Search(data)
assert.Nil(err)
assert.Equal("bar", result)
}
开发者ID:kuenzaa,项目名称:rack,代码行数:10,代码来源:api_test.go
示例5: TestPagination
// Use DynamoDB methods for simplicity
func TestPagination(t *testing.T) {
db := dynamodb.New(unit.Session)
tokens, pages, numPages, gotToEnd := []string{}, []string{}, 0, false
reqNum := 0
resps := []*dynamodb.ListTablesOutput{
{TableNames: []*string{aws.String("Table1"), aws.String("Table2")}, LastEvaluatedTableName: aws.String("Table2")},
{TableNames: []*string{aws.String("Table3"), aws.String("Table4")}, LastEvaluatedTableName: aws.String("Table4")},
{TableNames: []*string{aws.String("Table5")}},
}
db.Handlers.Send.Clear() // mock sending
db.Handlers.Unmarshal.Clear()
db.Handlers.UnmarshalMeta.Clear()
db.Handlers.ValidateResponse.Clear()
db.Handlers.Build.PushBack(func(r *request.Request) {
in := r.Params.(*dynamodb.ListTablesInput)
if in == nil {
tokens = append(tokens, "")
} else if in.ExclusiveStartTableName != nil {
tokens = append(tokens, *in.ExclusiveStartTableName)
}
})
db.Handlers.Unmarshal.PushBack(func(r *request.Request) {
r.Data = resps[reqNum]
reqNum++
})
params := &dynamodb.ListTablesInput{Limit: aws.Int64(2)}
err := db.ListTablesPages(params, func(p *dynamodb.ListTablesOutput, last bool) bool {
numPages++
for _, t := range p.TableNames {
pages = append(pages, *t)
}
if last {
if gotToEnd {
assert.Fail(t, "last=true happened twice")
}
gotToEnd = true
}
return true
})
assert.Equal(t, []string{"Table2", "Table4"}, tokens)
assert.Equal(t, []string{"Table1", "Table2", "Table3", "Table4", "Table5"}, pages)
assert.Equal(t, 3, numPages)
assert.True(t, gotToEnd)
assert.Nil(t, err)
assert.Nil(t, params.ExclusiveStartTableName)
}
开发者ID:kuenzaa,项目名称:rack,代码行数:51,代码来源:request_pagination_test.go
示例6: TestCanSupportStructWithSlice
func TestCanSupportStructWithSlice(t *testing.T) {
assert := assert.New(t)
data := sliceType{A: "foo", B: []scalars{scalars{"f1", "b1"}, scalars{"correct", "b2"}}}
result, err := Search("B[-1].Foo", data)
assert.Nil(err)
assert.Equal("correct", result)
}
开发者ID:kuenzaa,项目名称:rack,代码行数:7,代码来源:interpreter_test.go
示例7: TestManifestInvalid
func TestManifestInvalid(t *testing.T) {
manifest, err := LoadManifest("invalid-manifest")
assert.Nil(t, manifest)
assert.NotNil(t, err)
assert.Regexp(t, "^invalid manifest: ", err.Error())
}
开发者ID:cozmo,项目名称:rack,代码行数:7,代码来源:manifest_test.go
示例8: TestAppCreate
// Test the primary path: creating an app on a `convox` rack
// Return to testing against a `convox-test` rack afterwards
func TestAppCreate(t *testing.T) {
r := os.Getenv("RACK")
os.Setenv("RACK", "convox")
defer os.Setenv("RACK", r)
aws := test.StubAws(
test.DescribeStackNotFound("application"),
test.CreateAppStackCycle("convox-application"),
test.DescribeAppStackCycle("convox-application"),
)
defer aws.Close()
val := url.Values{"name": []string{"application"}}
body := test.HTTPBody("POST", "http://convox/apps", val)
if assert.NotEqual(t, "", body) {
var resp map[string]string
err := json.Unmarshal([]byte(body), &resp)
if assert.Nil(t, err) {
assert.Equal(t, "application", resp["name"])
assert.Equal(t, "running", resp["status"])
}
}
}
开发者ID:soulware,项目名称:rack,代码行数:27,代码来源:apps_test.go
示例9: TestCanSupportUserDefinedStructsRef
func TestCanSupportUserDefinedStructsRef(t *testing.T) {
assert := assert.New(t)
s := scalars{Foo: "one", Bar: "bar"}
result, err := Search("Foo", &s)
assert.Nil(err)
assert.Equal("one", result)
}
开发者ID:kuenzaa,项目名称:rack,代码行数:7,代码来源:interpreter_test.go
示例10: TestCanSupportStructWithFilterProjection
func TestCanSupportStructWithFilterProjection(t *testing.T) {
assert := assert.New(t)
data := sliceType{A: "foo", B: []scalars{scalars{"f1", "b1"}, scalars{"correct", "b2"}}}
result, err := Search("B[? `true` ].Foo", data)
assert.Nil(err)
assert.Equal([]interface{}{"f1", "correct"}, result)
}
开发者ID:kuenzaa,项目名称:rack,代码行数:7,代码来源:interpreter_test.go
示例11: TestEC2RoleProviderExpiryWindowIsExpired
func TestEC2RoleProviderExpiryWindowIsExpired(t *testing.T) {
server := initTestServer("2014-12-16T01:51:37Z", false)
defer server.Close()
p := &ec2rolecreds.EC2RoleProvider{
Client: ec2metadata.New(session.New(), &aws.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, %v", err)
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.")
}
开发者ID:kuenzaa,项目名称:rack,代码行数:25,代码来源:ec2_role_provider_test.go
示例12: TestCanSupportStructWithOrExpressions
func TestCanSupportStructWithOrExpressions(t *testing.T) {
assert := assert.New(t)
data := sliceType{A: "foo", C: nil}
result, err := Search("C || A", data)
assert.Nil(err)
assert.Equal("foo", result)
}
开发者ID:kuenzaa,项目名称:rack,代码行数:7,代码来源:interpreter_test.go
示例13: TestDoubleLoggingDoesntPrefixPreviousFields
func TestDoubleLoggingDoesntPrefixPreviousFields(t *testing.T) {
var buffer bytes.Buffer
var fields Fields
logger := New()
logger.Out = &buffer
logger.Formatter = new(JSONFormatter)
llog := logger.WithField("context", "eating raw fish")
llog.Info("looks delicious")
err := json.Unmarshal(buffer.Bytes(), &fields)
assert.NoError(t, err, "should have decoded first message")
assert.Equal(t, len(fields), 4, "should only have msg/time/level/context fields")
assert.Equal(t, fields["msg"], "looks delicious")
assert.Equal(t, fields["context"], "eating raw fish")
buffer.Reset()
llog.Warn("omg it is!")
err = json.Unmarshal(buffer.Bytes(), &fields)
assert.NoError(t, err, "should have decoded second message")
assert.Equal(t, len(fields), 4, "should only have msg/time/level/context fields")
assert.Equal(t, fields["msg"], "omg it is!")
assert.Equal(t, fields["context"], "eating raw fish")
assert.Nil(t, fields["fields.msg"], "should not have prefixed previous `msg` entry")
}
开发者ID:davidcoallier,项目名称:rack-1,代码行数:31,代码来源:logrus_test.go
示例14: TestCanSupportEmptyInterface
func TestCanSupportEmptyInterface(t *testing.T) {
assert := assert.New(t)
data := make(map[string]interface{})
data["foo"] = "bar"
result, err := Search("foo", data)
assert.Nil(err)
assert.Equal("bar", result)
}
开发者ID:kuenzaa,项目名称:rack,代码行数:8,代码来源:interpreter_test.go
示例15: TestParseLevel
func TestParseLevel(t *testing.T) {
l, err := ParseLevel("panic")
assert.Nil(t, err)
assert.Equal(t, PanicLevel, l)
l, err = ParseLevel("fatal")
assert.Nil(t, err)
assert.Equal(t, FatalLevel, l)
l, err = ParseLevel("error")
assert.Nil(t, err)
assert.Equal(t, ErrorLevel, l)
l, err = ParseLevel("warn")
assert.Nil(t, err)
assert.Equal(t, WarnLevel, l)
l, err = ParseLevel("warning")
assert.Nil(t, err)
assert.Equal(t, WarnLevel, l)
l, err = ParseLevel("info")
assert.Nil(t, err)
assert.Equal(t, InfoLevel, l)
l, err = ParseLevel("debug")
assert.Nil(t, err)
assert.Equal(t, DebugLevel, l)
l, err = ParseLevel("invalid")
assert.Equal(t, "not a valid logrus Level: \"invalid\"", err.Error())
}
开发者ID:davidcoallier,项目名称:rack-1,代码行数:32,代码来源:logrus_test.go
示例16: TestCanSupportProjectionsWithStructs
func TestCanSupportProjectionsWithStructs(t *testing.T) {
assert := assert.New(t)
data := nestedSlice{A: []sliceType{
{A: "first"}, {A: "second"}, {A: "third"},
}}
result, err := Search("A[*].A", data)
assert.Nil(err)
assert.Equal([]interface{}{"first", "second", "third"}, result)
}
开发者ID:kuenzaa,项目名称:rack,代码行数:9,代码来源:interpreter_test.go
示例17: TestCanSupportFlattenNestedEmptySlice
func TestCanSupportFlattenNestedEmptySlice(t *testing.T) {
assert := assert.New(t)
data := nestedSlice{A: []sliceType{
{}, {B: []scalars{{Foo: "a"}}},
}}
result, err := Search("A[].B[].Foo", data)
assert.Nil(err)
assert.Equal([]interface{}{"a"}, result)
}
开发者ID:kuenzaa,项目名称:rack,代码行数:9,代码来源:interpreter_test.go
示例18: Test
func (er ExecRun) Test(t *testing.T) {
stdout, stderr, code, err := er.exec()
assert.Nil(t, err, "should be nil")
assert.Equal(t, er.Exit, code, "exit code should be equal")
assert.Equal(t, er.Stdout, stdout, "stdout should be equal")
assert.Contains(t, stderr, er.Stderr,
fmt.Sprintf("stderr should contain %q", stderr))
}
开发者ID:inconshreveable,项目名称:rack,代码行数:9,代码来源:exec.go
示例19: TestResolve
func TestResolve(t *testing.T) {
vs := Versions{
Version{
Version: "1",
Published: true,
Required: false,
},
Version{
Version: "2",
Published: false,
Required: false,
},
Version{
Version: "3",
Published: true,
Required: false,
},
Version{
Version: "4",
Published: false,
Required: false,
},
Version{
Version: "5",
Published: false,
Required: false,
},
}
resolved, err := vs.Resolve("latest")
if assert.Nil(t, err) {
assert.Equal(t, "3", resolved.Version)
}
resolved, err = vs.Resolve("stable")
if assert.Nil(t, err) {
assert.Equal(t, "3", resolved.Version)
}
resolved, err = vs.Resolve("edge")
if assert.Nil(t, err) {
assert.Equal(t, "5", resolved.Version)
}
}
开发者ID:kuenzaa,项目名称:rack,代码行数:44,代码来源:version_test.go
示例20: TestPaginationTruncation
// Use S3 for simplicity
func TestPaginationTruncation(t *testing.T) {
client := s3.New(unit.Session)
reqNum := 0
resps := []*s3.ListObjectsOutput{
{IsTruncated: aws.Bool(true), Contents: []*s3.Object{{Key: aws.String("Key1")}}},
{IsTruncated: aws.Bool(true), Contents: []*s3.Object{{Key: aws.String("Key2")}}},
{IsTruncated: aws.Bool(false), Contents: []*s3.Object{{Key: aws.String("Key3")}}},
{IsTruncated: aws.Bool(true), Contents: []*s3.Object{{Key: aws.String("Key4")}}},
}
client.Handlers.Send.Clear() // mock sending
client.Handlers.Unmarshal.Clear()
client.Handlers.UnmarshalMeta.Clear()
client.Handlers.ValidateResponse.Clear()
client.Handlers.Unmarshal.PushBack(func(r *request.Request) {
r.Data = resps[reqNum]
reqNum++
})
params := &s3.ListObjectsInput{Bucket: aws.String("bucket")}
results := []string{}
err := client.ListObjectsPages(params, func(p *s3.ListObjectsOutput, last bool) bool {
results = append(results, *p.Contents[0].Key)
return true
})
assert.Equal(t, []string{"Key1", "Key2", "Key3"}, results)
assert.Nil(t, err)
// Try again without truncation token at all
reqNum = 0
resps[1].IsTruncated = nil
resps[2].IsTruncated = aws.Bool(true)
results = []string{}
err = client.ListObjectsPages(params, func(p *s3.ListObjectsOutput, last bool) bool {
results = append(results, *p.Contents[0].Key)
return true
})
assert.Equal(t, []string{"Key1", "Key2"}, results)
assert.Nil(t, err)
}
开发者ID:kuenzaa,项目名称:rack,代码行数:45,代码来源:request_pagination_test.go
注:本文中的github.com/convox/rack/Godeps/_workspace/src/github.com/stretchr/testify/assert.Nil函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论