本文整理匯總了Golang中github.com/MG-RAST/golib/stretchr/testify/assert.NotNil函數的典型用法代碼示例。如果您正苦於以下問題:Golang NotNil函數的具體用法?Golang NotNil怎麽用?Golang NotNil使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NotNil函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestGetCodec
func TestGetCodec(t *testing.T) {
service := NewWebCodecService()
var codec codecs.Codec
codec, _ = service.GetCodec(constants.ContentTypeJSON)
if assert.NotNil(t, codec, "Json should exist") {
assert.Equal(t, constants.ContentTypeJSON, codec.ContentType(), "ContentTypeJson")
}
// case insensitivity
codec, _ = service.GetCodec(strings.ToUpper(constants.ContentTypeJSON))
if assert.NotNil(t, codec, "Content case should not matter") {
assert.Equal(t, constants.ContentTypeJSON, codec.ContentType(), "ContentTypeJson")
}
// with noise
codec, _ = service.GetCodec(fmt.Sprintf("%s; charset=UTF-8", constants.ContentTypeJSON))
if assert.NotNil(t, codec, "charset in Content-Type should not matter") {
assert.Equal(t, constants.ContentTypeJSON, codec.ContentType(), "ContentTypeJson")
}
// default
codec, _ = service.GetCodec("")
if assert.NotNil(t, codec, "Empty contentType string should assume JSON") {
assert.Equal(t, constants.ContentTypeJSON, codec.ContentType(), "Should assume JSON.")
}
}
示例2: TestMapCreation
func TestMapCreation(t *testing.T) {
o := New(nil)
assert.Nil(t, o)
o = New("Tyler")
assert.Nil(t, o)
unconvertable := &Unconvertable{name: "Tyler"}
o = New(unconvertable)
assert.Nil(t, o)
convertable := &Convertable{name: "Tyler"}
o = New(convertable)
if assert.NotNil(t, convertable) {
assert.Equal(t, "Tyler", o["name"], "Tyler")
}
o = MSI()
if assert.NotNil(t, o) {
assert.NotNil(t, o)
}
o = MSI("name", "Tyler")
if assert.NotNil(t, o) {
if assert.NotNil(t, o) {
assert.Equal(t, o["name"], "Tyler")
}
}
}
示例3: TestCodecOptions
func TestCodecOptions(t *testing.T) {
c := new(WebContext)
c.codecOptions = nil
assert.NotNil(t, c.CodecOptions())
assert.NotNil(t, c.codecOptions)
}
示例4: TestData
func TestData(t *testing.T) {
c := new(WebContext)
c.data = nil
assert.NotNil(t, c.Data())
assert.NotNil(t, c.data)
}
示例5: TestMapFromJSON
func TestMapFromJSON(t *testing.T) {
o := MustFromJSON(`{"name":"Mat"}`)
if assert.NotNil(t, o) {
if assert.NotNil(t, o) {
assert.Equal(t, "Mat", o["name"])
}
}
}
示例6: TestMarshalAndUnmarshal
func TestMarshalAndUnmarshal(t *testing.T) {
// make a big object
obj := map[string]interface{}{}
obj["name"] = "Mat"
obj["age"] = 30
obj["address"] = map[string]interface{}{
"street": "Pearl Street",
"city": "Boulder",
"state": "CO",
"country": "USA",
}
obj["animals"] = map[string]interface{}{
"favourite": []string{"Dog", "Cat"},
}
bytes, marshalErr := xmlCodec.Marshal(obj, nil)
if assert.NoError(t, marshalErr) {
assert.Contains(t, string(bytes), "<?xml version=\"1.0\"?>", "Output")
}
// unmarshal it
var newObj interface{}
if assert.NoError(t, xmlCodec.Unmarshal(bytes, &newObj)) {
assert.NotNil(t, newObj)
}
}
示例7: assertPathMatchHandler
func assertPathMatchHandler(t *testing.T, handler *PathMatchHandler, path, method string, message string) bool {
if assert.NotNil(t, handler) {
ctx := context_test.MakeTestContextWithDetails(path, method)
willHandle, _ := handler.WillHandle(ctx)
if assert.True(t, willHandle, fmt.Sprintf("This handler is expected to handle it: %s", message)) {
// make sure the method is in the list
methodFound := false
for _, methodInList := range handler.HttpMethods {
if methodInList == method {
methodFound = true
break
}
}
return assert.True(t, methodFound, "Method (%s) should be in the method list (%s)", method, handler.HttpMethods)
}
}
return false
}
示例8: TestUnmarshal_MultipleObjects
func TestUnmarshal_MultipleObjects(t *testing.T) {
raw := "field_a,field_b,field_c\nrow1a,row1b,row1c\nrow2a,row2b,row2c\nrow3a,row3b,row3c"
csvCodec := new(CsvCodec)
var obj interface{}
csvCodec.Unmarshal([]byte(raw), &obj)
if assert.NotNil(t, obj, "Unmarshal should make an object") {
if array, ok := obj.([]interface{}); ok {
if assert.Equal(t, 3, len(array), "Should be 3 items") {
assert.Equal(t, "row1a", array[0].(map[string]interface{})["field_a"])
assert.Equal(t, "row1b", array[0].(map[string]interface{})["field_b"])
assert.Equal(t, "row1c", array[0].(map[string]interface{})["field_c"])
assert.Equal(t, "row2a", array[1].(map[string]interface{})["field_a"])
assert.Equal(t, "row2b", array[1].(map[string]interface{})["field_b"])
assert.Equal(t, "row2c", array[1].(map[string]interface{})["field_c"])
assert.Equal(t, "row3a", array[2].(map[string]interface{})["field_a"])
assert.Equal(t, "row3b", array[2].(map[string]interface{})["field_b"])
assert.Equal(t, "row3c", array[2].(map[string]interface{})["field_c"])
}
} else {
t.Errorf("Expected to be array type, not %s.", reflect.TypeOf(obj).Elem().Name())
}
}
}
示例9: TestUnmarshal_arrayOfMaps
func TestUnmarshal_arrayOfMaps(t *testing.T) {
xml := `<objects><object><name>Mat</name><age type="int">30</age><yesOrNo type="bool">true</yesOrNo><address><city>Boulder</city><state>CO</state></address></object><object><name>Tyler</name><age type="int">28</age><yesOrNo type="bool">false</yesOrNo><address><city>Salt Lake City</city><state>UT</state></address></object></objects>`
obj, err := unmarshal(xml, nil)
if assert.NoError(t, err) {
if assert.NotNil(t, obj) {
os := obj.([]interface{})
o1 := os[0].(map[string]interface{})
assert.Equal(t, "Mat", o1["name"])
assert.Equal(t, 30, o1["age"])
assert.Equal(t, true, o1["yesOrNo"])
o2 := os[1].(map[string]interface{})
assert.Equal(t, "Tyler", o2["name"])
assert.Equal(t, 28, o2["age"])
assert.Equal(t, false, o2["yesOrNo"])
}
}
}
示例10: TestMapFromURLQuery
func TestMapFromURLQuery(t *testing.T) {
m, err := FromURLQuery("name=tyler&state=UT")
if assert.NoError(t, err) && assert.NotNil(t, m) {
assert.Equal(t, "tyler", m.Get("name").Str())
assert.Equal(t, "UT", m.Get("state").Str())
}
}
示例11: TestNewPathPattern
func TestNewPathPattern(t *testing.T) {
path := "/people/{id}/books"
p, _ := NewPathPattern(path)
if assert.NotNil(t, p) {
assert.Equal(t, path, p.RawPath)
}
}
示例12: Test_Mock_TestData
func Test_Mock_TestData(t *testing.T) {
var mockedService *TestExampleImplementation = new(TestExampleImplementation)
if assert.NotNil(t, mockedService.TestData()) {
mockedService.TestData().Set("something", 123)
assert.Equal(t, 123, mockedService.TestData().Get("something").Data())
}
}
示例13: TestGetCodecForResponding_DefaultCodec
func TestGetCodecForResponding_DefaultCodec(t *testing.T) {
service := NewWebCodecService()
var codec codecs.Codec
codec, _ = service.GetCodecForResponding("", "", false)
if assert.NotNil(t, codec, "Return of GetCodecForAcceptStringOrExtension should default to JSON") {
assert.Equal(t, constants.ContentTypeJSON, codec.ContentType(), "Should default to JSON")
}
}
示例14: TestMapFromFieldsAndRow
func TestMapFromFieldsAndRow(t *testing.T) {
fields := []string{"field1", "field2", "field3"}
row := []string{"one", "two", "three"}
m, err := mapFromFieldsAndRow(fields, row)
if assert.NoError(t, err) && assert.NotNil(t, m) {
assert.Equal(t, "one", m["field1"])
assert.Equal(t, "two", m["field2"])
assert.Equal(t, "three", m["field3"])
}
}
示例15: TestGetAndSetErrorHandler
func TestGetAndSetErrorHandler(t *testing.T) {
codecService := codecsservices.NewWebCodecService()
handler := NewHttpHandler(codecService)
errorHandler := new(handlers_test.TestHandler)
// default one should be made
assert.NotNil(t, handler.ErrorHandler())
//... but if we set one explicitally
handler.SetErrorHandler(errorHandler)
//... it should be set!
assert.Equal(t, errorHandler, handler.ErrorHandler())
}