本文整理匯總了Golang中github.com/MG-RAST/golib/stretchr/testify/assert.True函數的典型用法代碼示例。如果您正苦於以下問題:Golang True函數的具體用法?Golang True怎麽用?Golang True使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了True函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestMapStaticFile
func TestMapStaticFile(t *testing.T) {
codecService := codecsservices.NewWebCodecService()
h := NewHttpHandler(codecService)
h.MapStaticFile("/static-file", "/location/of/static-file")
assert.Equal(t, 1, len(h.HandlersPipe()))
staticHandler := h.HandlersPipe()[0].(*PathMatchHandler)
if assert.Equal(t, 1, len(staticHandler.HttpMethods)) {
assert.Equal(t, goweb_http.MethodGet, staticHandler.HttpMethods[0])
}
var ctx context.Context
var willHandle bool
ctx = context_test.MakeTestContextWithPath("/static-file")
willHandle, _ = staticHandler.WillHandle(ctx)
assert.True(t, willHandle, "Static handler should handle")
ctx = context_test.MakeTestContextWithPath("static-file")
willHandle, _ = staticHandler.WillHandle(ctx)
assert.True(t, willHandle, "Static handler should handle")
ctx = context_test.MakeTestContextWithPath("static-file/")
willHandle, _ = staticHandler.WillHandle(ctx)
assert.True(t, willHandle, "Static handler should handle")
ctx = context_test.MakeTestContextWithPath("static-file/something-else")
willHandle, _ = staticHandler.WillHandle(ctx)
assert.False(t, willHandle, "Static handler NOT should handle")
}
示例2: TestUnMarshal_ObjxMap
func TestUnMarshal_ObjxMap(t *testing.T) {
obj1 := objx.MSI("name", "Mat", "age", 30, "language", "en")
obj2 := objx.MSI("obj", obj1)
obj3 := objx.MSI("another_obj", obj2)
csvCodec := new(CsvCodec)
bytes, _ := csvCodec.Marshal(obj3, nil)
log.Printf("bytes = %s", string(bytes))
// unmarshal it back
var obj interface{}
csvCodec.Unmarshal(bytes, &obj)
if objmap, ok := obj.(map[string]interface{}); ok {
if objmap2, ok := objmap["another_obj"].(map[string]interface{}); ok {
if objmap3, ok := objmap2["obj"].(map[string]interface{}); ok {
assert.Equal(t, "Mat", objmap3["name"])
assert.Equal(t, 30, objmap3["age"])
assert.Equal(t, "en", objmap3["language"])
} else {
assert.True(t, false, "another_obj.obj should be msi")
}
} else {
assert.True(t, false, "another_obj should be msi")
}
} else {
assert.True(t, false, "obj should be msi")
}
}
示例3: 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
}
示例4: TestUnMarshal_ComplexMap
func TestUnMarshal_ComplexMap(t *testing.T) {
obj1 := map[string]interface{}{"name": "Mat", "age": 30, "language": "en"}
obj2 := map[string]interface{}{"obj": obj1}
obj3 := map[string]interface{}{"another_obj": obj2}
csvCodec := new(CsvCodec)
bytes, _ := csvCodec.Marshal(obj3, nil)
// unmarshal it back
var obj interface{}
csvCodec.Unmarshal(bytes, &obj)
if objmap, ok := obj.(map[string]interface{}); ok {
if objmap2, ok := objmap["another_obj"].(map[string]interface{}); ok {
if objmap3, ok := objmap2["obj"].(map[string]interface{}); ok {
assert.Equal(t, "Mat", objmap3["name"])
assert.Equal(t, 30, objmap3["age"])
assert.Equal(t, "en", objmap3["language"])
} else {
assert.True(t, false, "another_obj.obj should be msi")
}
} else {
assert.True(t, false, "another_obj should be msi")
}
} else {
assert.True(t, false, "obj should be msi")
}
}
示例5: TestPathMatchHandler
func TestPathMatchHandler(t *testing.T) {
pathPattern, _ := paths.NewPathPattern("collection/{id}/name")
var called bool = false
h := NewPathMatchHandler(pathPattern, HandlerExecutionFunc(func(c context.Context) error {
called = true
return nil
}))
ctx1 := context_test.MakeTestContextWithPath("/collection/123/name")
will, _ := h.WillHandle(ctx1)
assert.True(t, will)
h.Handle(ctx1)
assert.True(t, called, "Method should be called")
assert.Equal(t, "123", ctx1.Data().Get(context.DataKeyPathParameters).ObjxMap().Get("id").Data())
ctx2 := context_test.MakeTestContextWithPath("/collection")
will, _ = h.WillHandle(ctx2)
assert.False(t, will)
assert.Nil(t, ctx2.Data().Get(context.DataKeyPathParameters).Data())
h.BreakCurrentPipeline = true
shouldStop, handleErr := h.Handle(ctx2)
assert.Nil(t, handleErr)
assert.True(t, shouldStop)
assert.True(t, called, "Handler func should get called")
}
示例6: TestAcceptEntry_Specificity
func TestAcceptEntry_Specificity(t *testing.T) {
greater := &AcceptEntry{
Quality: 1.0,
specificityCount: 2,
}
lesser := &AcceptEntry{
Quality: 1.0,
specificityCount: 1,
}
assert.True(t, greater.CompareTo(lesser) > 0, "At equal quality, higher specificity should come out greater")
assert.True(t, lesser.CompareTo(greater) < 0, "Comparing in opposite direction should provide opposite result")
}
示例7: TestAcceptEntry_Quality
func TestAcceptEntry_Quality(t *testing.T) {
greater := &AcceptEntry{
Quality: 0.8,
specificityCount: 0,
}
lesser := &AcceptEntry{
Quality: 0.3,
specificityCount: 10,
}
assert.True(t, greater.CompareTo(lesser) > 0, "Higher quality should come out greater")
assert.True(t, lesser.CompareTo(greater) < 0, "Comparing in opposite direction should provide opposite result")
}
示例8: Test_Mock_AssertNumberOfCalls
func Test_Mock_AssertNumberOfCalls(t *testing.T) {
var mockedService *TestExampleImplementation = new(TestExampleImplementation)
mockedService.Mock.On("Test_Mock_AssertNumberOfCalls", 1, 2, 3).Return(5, 6, 7)
mockedService.Mock.Called(1, 2, 3)
assert.True(t, mockedService.AssertNumberOfCalls(t, "Test_Mock_AssertNumberOfCalls", 1))
mockedService.Mock.Called(1, 2, 3)
assert.True(t, mockedService.AssertNumberOfCalls(t, "Test_Mock_AssertNumberOfCalls", 2))
}
示例9: TestMapStatic
func TestMapStatic(t *testing.T) {
codecService := codecsservices.NewWebCodecService()
h := NewHttpHandler(codecService)
h.MapStatic("/static", "/location/of/static")
assert.Equal(t, 1, len(h.HandlersPipe()))
staticHandler := h.HandlersPipe()[0].(*PathMatchHandler)
if assert.Equal(t, 1, len(staticHandler.HttpMethods)) {
assert.Equal(t, goweb_http.MethodGet, staticHandler.HttpMethods[0])
}
var ctx context.Context
var willHandle bool
ctx = context_test.MakeTestContextWithPath("/static/some/deep/file.dat")
willHandle, _ = staticHandler.WillHandle(ctx)
assert.True(t, willHandle, "Static handler should handle")
ctx = context_test.MakeTestContextWithPath("/static/../static/some/deep/file.dat")
willHandle, _ = staticHandler.WillHandle(ctx)
assert.True(t, willHandle, "Static handler should handle")
ctx = context_test.MakeTestContextWithPath("/static/some/../file.dat")
willHandle, _ = staticHandler.WillHandle(ctx)
assert.True(t, willHandle, "Static handler should handle")
ctx = context_test.MakeTestContextWithPath("/static/../file.dat")
willHandle, _ = staticHandler.WillHandle(ctx)
assert.False(t, willHandle, "Static handler should not handle")
ctx = context_test.MakeTestContextWithPath("/static")
willHandle, _ = staticHandler.WillHandle(ctx)
assert.True(t, willHandle, "Static handler should handle")
ctx = context_test.MakeTestContextWithPath("/static/")
willHandle, _ = staticHandler.WillHandle(ctx)
assert.True(t, willHandle, "Static handler should handle")
ctx = context_test.MakeTestContextWithPath("/static/doc.go")
willHandle, _ = staticHandler.WillHandle(ctx)
_, staticHandleErr := staticHandler.Handle(ctx)
if assert.NoError(t, staticHandleErr) {
}
}
示例10: TestSimpleExample
func TestSimpleExample(t *testing.T) {
// build a map from a JSON object
o := MustFromJSON(`{"name":"Mat","foods":["indian","chinese"], "location":{"county":"hobbiton","city":"the shire"}}`)
// Map can be used as a straight map[string]interface{}
assert.Equal(t, o["name"], "Mat")
// Get an Value object
v := o.Get("name")
assert.Equal(t, v, &Value{data: "Mat"})
// Test the contained value
assert.False(t, v.IsInt())
assert.False(t, v.IsBool())
assert.True(t, v.IsStr())
// Get the contained value
assert.Equal(t, v.Str(), "Mat")
// Get a default value if the contained value is not of the expected type or does not exist
assert.Equal(t, 1, v.Int(1))
// Get a value by using array notation
assert.Equal(t, "indian", o.Get("foods[0]").Data())
// Set a value by using array notation
o.Set("foods[0]", "italian")
assert.Equal(t, "italian", o.Get("foods[0]").Str())
// Get a value by using dot notation
assert.Equal(t, "hobbiton", o.Get("location.county").Str())
}
示例11: Test_Arguments_Assert
func Test_Arguments_Assert(t *testing.T) {
var args Arguments = []interface{}{"string", 123, true}
assert.True(t, args.Assert(t, "string", 123, true))
}
示例12: AssertCalled
// AssertCalled asserts that the method was called.
func (m *Mock) AssertCalled(t TestingT, methodName string, arguments ...interface{}) bool {
if !assert.True(t, m.methodWasCalled(methodName, arguments), fmt.Sprintf("The \"%s\" method should have been called with %d argument(s), but was not.", methodName, len(arguments))) {
t.Logf("%s", m.ExpectedCalls)
return false
}
return true
}
示例13: Test_Mock_AssertCalled_WithArguments_With_Repeatability
func Test_Mock_AssertCalled_WithArguments_With_Repeatability(t *testing.T) {
var mockedService *TestExampleImplementation = new(TestExampleImplementation)
mockedService.Mock.On("Test_Mock_AssertCalled_WithArguments_With_Repeatability", 1, 2, 3).Return(5, 6, 7).Once()
mockedService.Mock.On("Test_Mock_AssertCalled_WithArguments_With_Repeatability", 2, 3, 4).Return(5, 6, 7).Once()
mockedService.Mock.Called(1, 2, 3)
mockedService.Mock.Called(2, 3, 4)
tt := new(testing.T)
assert.True(t, mockedService.AssertCalled(tt, "Test_Mock_AssertCalled_WithArguments_With_Repeatability", 1, 2, 3))
assert.True(t, mockedService.AssertCalled(tt, "Test_Mock_AssertCalled_WithArguments_With_Repeatability", 2, 3, 4))
assert.False(t, mockedService.AssertCalled(tt, "Test_Mock_AssertCalled_WithArguments_With_Repeatability", 3, 4, 5))
}
示例14: TestPathMatchHandler_BreakCurrentPipeline
func TestPathMatchHandler_BreakCurrentPipeline(t *testing.T) {
pathPattern, _ := paths.NewPathPattern("collection/{id}/name")
h := NewPathMatchHandler(pathPattern, HandlerExecutionFunc(func(c context.Context) error {
return nil
}))
h.BreakCurrentPipeline = true
ctx1 := context_test.MakeTestContextWithPath("/collection/123/name")
breakCurrentPipeline, _ := h.Handle(ctx1)
assert.True(t, breakCurrentPipeline)
h = NewPathMatchHandler(pathPattern, HandlerExecutionFunc(func(c context.Context) error {
return nil
}))
h.BreakCurrentPipeline = false
ctx1 = context_test.MakeTestContextWithPath("/collection/123/name")
breakCurrentPipeline, _ = h.Handle(ctx1)
assert.False(t, breakCurrentPipeline)
}
示例15: Test_Arguments_Is
func Test_Arguments_Is(t *testing.T) {
var args Arguments = []interface{}{"string", 123, true}
assert.True(t, args.Is("string", 123, true))
assert.False(t, args.Is("wrong", 456, false))
}