當前位置: 首頁>>代碼示例>>Golang>>正文


Golang assert.NoError函數代碼示例

本文整理匯總了Golang中github.com/MG-RAST/golib/stretchr/testify/assert.NoError函數的典型用法代碼示例。如果您正苦於以下問題:Golang NoError函數的具體用法?Golang NoError怎麽用?Golang NoError使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NoError函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestRequestData

func TestRequestData(t *testing.T) {

	responseWriter := new(http_test.TestResponseWriter)
	testRequest, _ := http.NewRequest("GET", "http://goweb.org/people/123", strings.NewReader("{\"something\":true}"))

	codecService := codecsservices.NewWebCodecService()

	c := NewWebContext(responseWriter, testRequest, codecService)

	bod, _ := c.RequestBody()
	assert.Equal(t, "{\"something\":true}", string(bod))
	dat, datErr := c.RequestData()

	if assert.NoError(t, datErr) {
		assert.Equal(t, true, dat.(map[string]interface{})["something"])
	}

	responseWriter = new(http_test.TestResponseWriter)
	testRequest, _ = http.NewRequest("GET", "http://goweb.org/people/123?body={\"something\":true}", nil)

	codecService = codecsservices.NewWebCodecService()

	c = NewWebContext(responseWriter, testRequest, codecService)

	bod, _ = c.RequestBody()
	assert.Equal(t, "{\"something\":true}", string(bod))
	dat, datErr = c.RequestData()

	if assert.NoError(t, datErr) {
		assert.Equal(t, true, dat.(map[string]interface{})["something"])
	}

}
開發者ID:MG-RAST,項目名稱:Shock,代碼行數:33,代碼來源:web_context_test.go

示例2: 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)

	}

}
開發者ID:MG-RAST,項目名稱:Shock,代碼行數:31,代碼來源:simple_xml_codec_test.go

示例3: 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"])

		}
	}

}
開發者ID:MG-RAST,項目名稱:Shock,代碼行數:25,代碼來源:simple_xml_codec_test.go

示例4: TestParseAccept_NoParams

func TestParseAccept_NoParams(t *testing.T) {
	acceptString := "application/json"
	accept, err := ParseAcceptEntry(acceptString)
	assert.NoError(t, err, acceptString+" should parse with no errors")
	assert.Equal(t, acceptString, accept.ContentType.MimeType)
	assert.Equal(t, accept.Quality, 1.0)
}
開發者ID:MG-RAST,項目名稱:Shock,代碼行數:7,代碼來源:accept_test.go

示例5: TestParseAccept_QualityParam

func TestParseAccept_QualityParam(t *testing.T) {
	acceptString := "application/json; q=0.4"
	expectedQuality := 0.4

	accept, err := ParseAcceptEntry(acceptString)
	assert.NoError(t, err, acceptString+" should parse with no errors")
	assert.Equal(t, accept.Quality, expectedQuality)
}
開發者ID:MG-RAST,項目名稱:Shock,代碼行數:8,代碼來源:accept_test.go

示例6: 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())
	}

}
開發者ID:MG-RAST,項目名稱:Shock,代碼行數:9,代碼來源:map_test.go

示例7: TestMarshal_map

func TestMarshal_map(t *testing.T) {

	data := map[string]interface{}{"name": "Mat", "age": 30, "yesOrNo": true}
	bytes, marshalErr := marshal(data, false, 0, nil)

	if assert.NoError(t, marshalErr) {
		assert.Equal(t, "<object><name>Mat</name><age>30</age><yesOrNo>true</yesOrNo></object>", string(bytes), "Output")
	}

}
開發者ID:MG-RAST,項目名稱:Shock,代碼行數:10,代碼來源:simple_xml_codec_test.go

示例8: TestOrderAcceptHeader_EqualQualityAndSpecificity

func TestOrderAcceptHeader_EqualQualityAndSpecificity(t *testing.T) {
	expectedOrder := []string{"application/json", "application/xml", "text/xml"}
	header := strings.Join(expectedOrder, ", ")
	orderedAccept, err := OrderAcceptHeader(header)
	assert.NoError(t, err)
	for index, expectedType := range expectedOrder {
		entry := orderedAccept[index]
		assert.Equal(t, entry.ContentType.MimeType, expectedType)
	}
}
開發者ID:MG-RAST,項目名稱:Shock,代碼行數:10,代碼來源:accept_test.go

示例9: TestWrapCodec_Marshal

func TestWrapCodec_Marshal(t *testing.T) {
	codec := new(testCodec)
	testContentType := "application/vnd.stretchr.test+json"
	wrappedCodec := wrapCodecWithContentType(codec, testContentType)

	response, err := wrappedCodec.Marshal(nil, nil)
	assert.NoError(t, err)
	expectedResponse := `{"matched_type":"` + testContentType + `"}`
	assert.Equal(t, response, []byte(expectedResponse),
		"The wrapped codec should add the matched content type to options on unmarshal")
}
開發者ID:MG-RAST,項目名稱:Shock,代碼行數:11,代碼來源:content_type_codec_wrapper_test.go

示例10: TestMarshal_mapWithTypes

func TestMarshal_mapWithTypes(t *testing.T) {

	data := map[string]interface{}{"name": "Mat", "age": 30, "yesOrNo": true}
	options := objx.MSI(OptionIncludeTypeAttributes, true)
	bytes, marshalErr := marshal(data, false, 0, options)

	if assert.NoError(t, marshalErr) {
		assert.Equal(t, "<object><name type=\"string\">Mat</name><age type=\"int\">30</age><yesOrNo type=\"bool\">true</yesOrNo></object>", string(bytes), "Output")
	}

}
開發者ID:MG-RAST,項目名稱:Shock,代碼行數:11,代碼來源:simple_xml_codec_test.go

示例11: TestConversionBase64

func TestConversionBase64(t *testing.T) {

	o := New(map[string]interface{}{"name": "Mat"})

	result, err := o.Base64()

	if assert.NoError(t, err) {
		assert.Equal(t, "eyJuYW1lIjoiTWF0In0=", result)
	}

	assert.Equal(t, "eyJuYW1lIjoiTWF0In0=", o.MustBase64())

}
開發者ID:MG-RAST,項目名稱:Shock,代碼行數:13,代碼來源:conversions_test.go

示例12: TestMapFromBase64String

func TestMapFromBase64String(t *testing.T) {

	base64String := "eyJuYW1lIjoiTWF0In0="

	o, err := FromBase64(base64String)

	if assert.NoError(t, err) {
		assert.Equal(t, o.Get("name").Str(), "Mat")
	}

	assert.Equal(t, MustFromBase64(base64String).Get("name").Str(), "Mat")

}
開發者ID:MG-RAST,項目名稱:Shock,代碼行數:13,代碼來源:map_test.go

示例13: TestMapFromSignedBase64String

func TestMapFromSignedBase64String(t *testing.T) {

	base64String := "eyJuYW1lIjoiTWF0In0=_67ee82916f90b2c0d68c903266e8998c9ef0c3d6"

	o, err := FromSignedBase64(base64String, "key")

	if assert.NoError(t, err) {
		assert.Equal(t, o.Get("name").Str(), "Mat")
	}

	assert.Equal(t, MustFromSignedBase64(base64String, "key").Get("name").Str(), "Mat")

}
開發者ID:MG-RAST,項目名稱:Shock,代碼行數:13,代碼來源:map_test.go

示例14: TestConversionSignedBase64

func TestConversionSignedBase64(t *testing.T) {

	o := New(map[string]interface{}{"name": "Mat"})

	result, err := o.SignedBase64("key")

	if assert.NoError(t, err) {
		assert.Equal(t, "eyJuYW1lIjoiTWF0In0=_67ee82916f90b2c0d68c903266e8998c9ef0c3d6", result)
	}

	assert.Equal(t, "eyJuYW1lIjoiTWF0In0=_67ee82916f90b2c0d68c903266e8998c9ef0c3d6", o.MustSignedBase64("key"))

}
開發者ID:MG-RAST,項目名稱:Shock,代碼行數:13,代碼來源:conversions_test.go

示例15: TestMarshal_arrayOfMaps

func TestMarshal_arrayOfMaps(t *testing.T) {

	data1 := map[string]interface{}{"name": "Mat"}
	data2 := map[string]interface{}{"name": "Tyler"}
	data3 := map[string]interface{}{"name": "Ryan"}
	array := []map[string]interface{}{data1, data2, data3}
	bytes, marshalErr := marshal(array, false, 0, nil)

	if assert.NoError(t, marshalErr) {
		assert.Equal(t, "<objects><object><name>Mat</name></object><object><name>Tyler</name></object><object><name>Ryan</name></object></objects>", string(bytes), "Output")
	}

}
開發者ID:MG-RAST,項目名稱:Shock,代碼行數:13,代碼來源:simple_xml_codec_test.go


注:本文中的github.com/MG-RAST/golib/stretchr/testify/assert.NoError函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。