...

Source file src/go.mongodb.org/mongo-driver/internal/require/require.go

Documentation: go.mongodb.org/mongo-driver/internal/require

     1  // Copied from https://github.com/stretchr/testify/blob/1333b5d3bda8cf5aedcf3e1aaa95cac28aaab892/require/require.go
     2  
     3  // Copyright 2020 Mat Ryer, Tyler Bunnell and all contributors. All rights reserved.
     4  // Use of this source code is governed by an MIT-style license that can be found in
     5  // the THIRD-PARTY-NOTICES file.
     6  
     7  package require
     8  
     9  import (
    10  	time "time"
    11  
    12  	assert "go.mongodb.org/mongo-driver/internal/assert"
    13  )
    14  
    15  // TestingT is an interface wrapper around *testing.T
    16  type TestingT interface {
    17  	Errorf(format string, args ...interface{})
    18  	FailNow()
    19  }
    20  
    21  type tHelper interface {
    22  	Helper()
    23  }
    24  
    25  // Contains asserts that the specified string, list(array, slice...) or map contains the
    26  // specified substring or element.
    27  //
    28  //	assert.Contains(t, "Hello World", "World")
    29  //	assert.Contains(t, ["Hello", "World"], "World")
    30  //	assert.Contains(t, {"Hello": "World"}, "Hello")
    31  func Contains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) {
    32  	if h, ok := t.(tHelper); ok {
    33  		h.Helper()
    34  	}
    35  	if assert.Contains(t, s, contains, msgAndArgs...) {
    36  		return
    37  	}
    38  	t.FailNow()
    39  }
    40  
    41  // Containsf asserts that the specified string, list(array, slice...) or map contains the
    42  // specified substring or element.
    43  //
    44  //	assert.Containsf(t, "Hello World", "World", "error message %s", "formatted")
    45  //	assert.Containsf(t, ["Hello", "World"], "World", "error message %s", "formatted")
    46  //	assert.Containsf(t, {"Hello": "World"}, "Hello", "error message %s", "formatted")
    47  func Containsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) {
    48  	if h, ok := t.(tHelper); ok {
    49  		h.Helper()
    50  	}
    51  	if assert.Containsf(t, s, contains, msg, args...) {
    52  		return
    53  	}
    54  	t.FailNow()
    55  }
    56  
    57  // ElementsMatch asserts that the specified listA(array, slice...) is equal to specified
    58  // listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,
    59  // the number of appearances of each of them in both lists should match.
    60  //
    61  // assert.ElementsMatch(t, [1, 3, 2, 3], [1, 3, 3, 2])
    62  func ElementsMatch(t TestingT, listA interface{}, listB interface{}, msgAndArgs ...interface{}) {
    63  	if h, ok := t.(tHelper); ok {
    64  		h.Helper()
    65  	}
    66  	if assert.ElementsMatch(t, listA, listB, msgAndArgs...) {
    67  		return
    68  	}
    69  	t.FailNow()
    70  }
    71  
    72  // ElementsMatchf asserts that the specified listA(array, slice...) is equal to specified
    73  // listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,
    74  // the number of appearances of each of them in both lists should match.
    75  //
    76  // assert.ElementsMatchf(t, [1, 3, 2, 3], [1, 3, 3, 2], "error message %s", "formatted")
    77  func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, args ...interface{}) {
    78  	if h, ok := t.(tHelper); ok {
    79  		h.Helper()
    80  	}
    81  	if assert.ElementsMatchf(t, listA, listB, msg, args...) {
    82  		return
    83  	}
    84  	t.FailNow()
    85  }
    86  
    87  // Equal asserts that two objects are equal.
    88  //
    89  //	assert.Equal(t, 123, 123)
    90  //
    91  // Pointer variable equality is determined based on the equality of the
    92  // referenced values (as opposed to the memory addresses). Function equality
    93  // cannot be determined and will always fail.
    94  func Equal(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
    95  	if h, ok := t.(tHelper); ok {
    96  		h.Helper()
    97  	}
    98  	if assert.Equal(t, expected, actual, msgAndArgs...) {
    99  		return
   100  	}
   101  	t.FailNow()
   102  }
   103  
   104  // EqualError asserts that a function returned an error (i.e. not `nil`)
   105  // and that it is equal to the provided error.
   106  //
   107  //	actualObj, err := SomeFunction()
   108  //	assert.EqualError(t, err,  expectedErrorString)
   109  func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) {
   110  	if h, ok := t.(tHelper); ok {
   111  		h.Helper()
   112  	}
   113  	if assert.EqualError(t, theError, errString, msgAndArgs...) {
   114  		return
   115  	}
   116  	t.FailNow()
   117  }
   118  
   119  // EqualErrorf asserts that a function returned an error (i.e. not `nil`)
   120  // and that it is equal to the provided error.
   121  //
   122  //	actualObj, err := SomeFunction()
   123  //	assert.EqualErrorf(t, err,  expectedErrorString, "error message %s", "formatted")
   124  func EqualErrorf(t TestingT, theError error, errString string, msg string, args ...interface{}) {
   125  	if h, ok := t.(tHelper); ok {
   126  		h.Helper()
   127  	}
   128  	if assert.EqualErrorf(t, theError, errString, msg, args...) {
   129  		return
   130  	}
   131  	t.FailNow()
   132  }
   133  
   134  // EqualValues asserts that two objects are equal or convertible to the same types
   135  // and equal.
   136  //
   137  //	assert.EqualValues(t, uint32(123), int32(123))
   138  func EqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
   139  	if h, ok := t.(tHelper); ok {
   140  		h.Helper()
   141  	}
   142  	if assert.EqualValues(t, expected, actual, msgAndArgs...) {
   143  		return
   144  	}
   145  	t.FailNow()
   146  }
   147  
   148  // EqualValuesf asserts that two objects are equal or convertible to the same types
   149  // and equal.
   150  //
   151  //	assert.EqualValuesf(t, uint32(123), int32(123), "error message %s", "formatted")
   152  func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {
   153  	if h, ok := t.(tHelper); ok {
   154  		h.Helper()
   155  	}
   156  	if assert.EqualValuesf(t, expected, actual, msg, args...) {
   157  		return
   158  	}
   159  	t.FailNow()
   160  }
   161  
   162  // Equalf asserts that two objects are equal.
   163  //
   164  //	assert.Equalf(t, 123, 123, "error message %s", "formatted")
   165  //
   166  // Pointer variable equality is determined based on the equality of the
   167  // referenced values (as opposed to the memory addresses). Function equality
   168  // cannot be determined and will always fail.
   169  func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {
   170  	if h, ok := t.(tHelper); ok {
   171  		h.Helper()
   172  	}
   173  	if assert.Equalf(t, expected, actual, msg, args...) {
   174  		return
   175  	}
   176  	t.FailNow()
   177  }
   178  
   179  // Error asserts that a function returned an error (i.e. not `nil`).
   180  //
   181  //	  actualObj, err := SomeFunction()
   182  //	  if assert.Error(t, err) {
   183  //		   assert.Equal(t, expectedError, err)
   184  //	  }
   185  func Error(t TestingT, err error, msgAndArgs ...interface{}) {
   186  	if h, ok := t.(tHelper); ok {
   187  		h.Helper()
   188  	}
   189  	if assert.Error(t, err, msgAndArgs...) {
   190  		return
   191  	}
   192  	t.FailNow()
   193  }
   194  
   195  // ErrorContains asserts that a function returned an error (i.e. not `nil`)
   196  // and that the error contains the specified substring.
   197  //
   198  //	actualObj, err := SomeFunction()
   199  //	assert.ErrorContains(t, err,  expectedErrorSubString)
   200  func ErrorContains(t TestingT, theError error, contains string, msgAndArgs ...interface{}) {
   201  	if h, ok := t.(tHelper); ok {
   202  		h.Helper()
   203  	}
   204  	if assert.ErrorContains(t, theError, contains, msgAndArgs...) {
   205  		return
   206  	}
   207  	t.FailNow()
   208  }
   209  
   210  // ErrorContainsf asserts that a function returned an error (i.e. not `nil`)
   211  // and that the error contains the specified substring.
   212  //
   213  //	actualObj, err := SomeFunction()
   214  //	assert.ErrorContainsf(t, err,  expectedErrorSubString, "error message %s", "formatted")
   215  func ErrorContainsf(t TestingT, theError error, contains string, msg string, args ...interface{}) {
   216  	if h, ok := t.(tHelper); ok {
   217  		h.Helper()
   218  	}
   219  	if assert.ErrorContainsf(t, theError, contains, msg, args...) {
   220  		return
   221  	}
   222  	t.FailNow()
   223  }
   224  
   225  // Errorf asserts that a function returned an error (i.e. not `nil`).
   226  //
   227  //	  actualObj, err := SomeFunction()
   228  //	  if assert.Errorf(t, err, "error message %s", "formatted") {
   229  //		   assert.Equal(t, expectedErrorf, err)
   230  //	  }
   231  func Errorf(t TestingT, err error, msg string, args ...interface{}) {
   232  	if h, ok := t.(tHelper); ok {
   233  		h.Helper()
   234  	}
   235  	if assert.Errorf(t, err, msg, args...) {
   236  		return
   237  	}
   238  	t.FailNow()
   239  }
   240  
   241  // Eventually asserts that given condition will be met in waitFor time,
   242  // periodically checking target function each tick.
   243  //
   244  //	assert.Eventually(t, func() bool { return true; }, time.Second, 10*time.Millisecond)
   245  func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) {
   246  	if h, ok := t.(tHelper); ok {
   247  		h.Helper()
   248  	}
   249  	if assert.Eventually(t, condition, waitFor, tick, msgAndArgs...) {
   250  		return
   251  	}
   252  	t.FailNow()
   253  }
   254  
   255  // Eventuallyf asserts that given condition will be met in waitFor time,
   256  // periodically checking target function each tick.
   257  //
   258  //	assert.Eventuallyf(t, func() bool { return true; }, time.Second, 10*time.Millisecond, "error message %s", "formatted")
   259  func Eventuallyf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) {
   260  	if h, ok := t.(tHelper); ok {
   261  		h.Helper()
   262  	}
   263  	if assert.Eventuallyf(t, condition, waitFor, tick, msg, args...) {
   264  		return
   265  	}
   266  	t.FailNow()
   267  }
   268  
   269  // Fail reports a failure through
   270  func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) {
   271  	if h, ok := t.(tHelper); ok {
   272  		h.Helper()
   273  	}
   274  	if assert.Fail(t, failureMessage, msgAndArgs...) {
   275  		return
   276  	}
   277  	t.FailNow()
   278  }
   279  
   280  // FailNow fails test
   281  func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) {
   282  	if h, ok := t.(tHelper); ok {
   283  		h.Helper()
   284  	}
   285  	if assert.FailNow(t, failureMessage, msgAndArgs...) {
   286  		return
   287  	}
   288  	t.FailNow()
   289  }
   290  
   291  // FailNowf fails test
   292  func FailNowf(t TestingT, failureMessage string, msg string, args ...interface{}) {
   293  	if h, ok := t.(tHelper); ok {
   294  		h.Helper()
   295  	}
   296  	if assert.FailNowf(t, failureMessage, msg, args...) {
   297  		return
   298  	}
   299  	t.FailNow()
   300  }
   301  
   302  // Failf reports a failure through
   303  func Failf(t TestingT, failureMessage string, msg string, args ...interface{}) {
   304  	if h, ok := t.(tHelper); ok {
   305  		h.Helper()
   306  	}
   307  	if assert.Failf(t, failureMessage, msg, args...) {
   308  		return
   309  	}
   310  	t.FailNow()
   311  }
   312  
   313  // False asserts that the specified value is false.
   314  //
   315  //	assert.False(t, myBool)
   316  func False(t TestingT, value bool, msgAndArgs ...interface{}) {
   317  	if h, ok := t.(tHelper); ok {
   318  		h.Helper()
   319  	}
   320  	if assert.False(t, value, msgAndArgs...) {
   321  		return
   322  	}
   323  	t.FailNow()
   324  }
   325  
   326  // Falsef asserts that the specified value is false.
   327  //
   328  //	assert.Falsef(t, myBool, "error message %s", "formatted")
   329  func Falsef(t TestingT, value bool, msg string, args ...interface{}) {
   330  	if h, ok := t.(tHelper); ok {
   331  		h.Helper()
   332  	}
   333  	if assert.Falsef(t, value, msg, args...) {
   334  		return
   335  	}
   336  	t.FailNow()
   337  }
   338  
   339  // Greater asserts that the first element is greater than the second
   340  //
   341  //	assert.Greater(t, 2, 1)
   342  //	assert.Greater(t, float64(2), float64(1))
   343  //	assert.Greater(t, "b", "a")
   344  func Greater(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) {
   345  	if h, ok := t.(tHelper); ok {
   346  		h.Helper()
   347  	}
   348  	if assert.Greater(t, e1, e2, msgAndArgs...) {
   349  		return
   350  	}
   351  	t.FailNow()
   352  }
   353  
   354  // GreaterOrEqual asserts that the first element is greater than or equal to the second
   355  //
   356  //	assert.GreaterOrEqual(t, 2, 1)
   357  //	assert.GreaterOrEqual(t, 2, 2)
   358  //	assert.GreaterOrEqual(t, "b", "a")
   359  //	assert.GreaterOrEqual(t, "b", "b")
   360  func GreaterOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) {
   361  	if h, ok := t.(tHelper); ok {
   362  		h.Helper()
   363  	}
   364  	if assert.GreaterOrEqual(t, e1, e2, msgAndArgs...) {
   365  		return
   366  	}
   367  	t.FailNow()
   368  }
   369  
   370  // GreaterOrEqualf asserts that the first element is greater than or equal to the second
   371  //
   372  //	assert.GreaterOrEqualf(t, 2, 1, "error message %s", "formatted")
   373  //	assert.GreaterOrEqualf(t, 2, 2, "error message %s", "formatted")
   374  //	assert.GreaterOrEqualf(t, "b", "a", "error message %s", "formatted")
   375  //	assert.GreaterOrEqualf(t, "b", "b", "error message %s", "formatted")
   376  func GreaterOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) {
   377  	if h, ok := t.(tHelper); ok {
   378  		h.Helper()
   379  	}
   380  	if assert.GreaterOrEqualf(t, e1, e2, msg, args...) {
   381  		return
   382  	}
   383  	t.FailNow()
   384  }
   385  
   386  // Greaterf asserts that the first element is greater than the second
   387  //
   388  //	assert.Greaterf(t, 2, 1, "error message %s", "formatted")
   389  //	assert.Greaterf(t, float64(2), float64(1), "error message %s", "formatted")
   390  //	assert.Greaterf(t, "b", "a", "error message %s", "formatted")
   391  func Greaterf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) {
   392  	if h, ok := t.(tHelper); ok {
   393  		h.Helper()
   394  	}
   395  	if assert.Greaterf(t, e1, e2, msg, args...) {
   396  		return
   397  	}
   398  	t.FailNow()
   399  }
   400  
   401  // InDelta asserts that the two numerals are within delta of each other.
   402  //
   403  //	assert.InDelta(t, math.Pi, 22/7.0, 0.01)
   404  func InDelta(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
   405  	if h, ok := t.(tHelper); ok {
   406  		h.Helper()
   407  	}
   408  	if assert.InDelta(t, expected, actual, delta, msgAndArgs...) {
   409  		return
   410  	}
   411  	t.FailNow()
   412  }
   413  
   414  // InDeltaf asserts that the two numerals are within delta of each other.
   415  //
   416  //	assert.InDeltaf(t, math.Pi, 22/7.0, 0.01, "error message %s", "formatted")
   417  func InDeltaf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) {
   418  	if h, ok := t.(tHelper); ok {
   419  		h.Helper()
   420  	}
   421  	if assert.InDeltaf(t, expected, actual, delta, msg, args...) {
   422  		return
   423  	}
   424  	t.FailNow()
   425  }
   426  
   427  // IsType asserts that the specified objects are of the same type.
   428  func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) {
   429  	if h, ok := t.(tHelper); ok {
   430  		h.Helper()
   431  	}
   432  	if assert.IsType(t, expectedType, object, msgAndArgs...) {
   433  		return
   434  	}
   435  	t.FailNow()
   436  }
   437  
   438  // IsTypef asserts that the specified objects are of the same type.
   439  func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg string, args ...interface{}) {
   440  	if h, ok := t.(tHelper); ok {
   441  		h.Helper()
   442  	}
   443  	if assert.IsTypef(t, expectedType, object, msg, args...) {
   444  		return
   445  	}
   446  	t.FailNow()
   447  }
   448  
   449  // Len asserts that the specified object has specific length.
   450  // Len also fails if the object has a type that len() not accept.
   451  //
   452  //	assert.Len(t, mySlice, 3)
   453  func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) {
   454  	if h, ok := t.(tHelper); ok {
   455  		h.Helper()
   456  	}
   457  	if assert.Len(t, object, length, msgAndArgs...) {
   458  		return
   459  	}
   460  	t.FailNow()
   461  }
   462  
   463  // Lenf asserts that the specified object has specific length.
   464  // Lenf also fails if the object has a type that len() not accept.
   465  //
   466  //	assert.Lenf(t, mySlice, 3, "error message %s", "formatted")
   467  func Lenf(t TestingT, object interface{}, length int, msg string, args ...interface{}) {
   468  	if h, ok := t.(tHelper); ok {
   469  		h.Helper()
   470  	}
   471  	if assert.Lenf(t, object, length, msg, args...) {
   472  		return
   473  	}
   474  	t.FailNow()
   475  }
   476  
   477  // Less asserts that the first element is less than the second
   478  //
   479  //	assert.Less(t, 1, 2)
   480  //	assert.Less(t, float64(1), float64(2))
   481  //	assert.Less(t, "a", "b")
   482  func Less(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) {
   483  	if h, ok := t.(tHelper); ok {
   484  		h.Helper()
   485  	}
   486  	if assert.Less(t, e1, e2, msgAndArgs...) {
   487  		return
   488  	}
   489  	t.FailNow()
   490  }
   491  
   492  // LessOrEqual asserts that the first element is less than or equal to the second
   493  //
   494  //	assert.LessOrEqual(t, 1, 2)
   495  //	assert.LessOrEqual(t, 2, 2)
   496  //	assert.LessOrEqual(t, "a", "b")
   497  //	assert.LessOrEqual(t, "b", "b")
   498  func LessOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) {
   499  	if h, ok := t.(tHelper); ok {
   500  		h.Helper()
   501  	}
   502  	if assert.LessOrEqual(t, e1, e2, msgAndArgs...) {
   503  		return
   504  	}
   505  	t.FailNow()
   506  }
   507  
   508  // LessOrEqualf asserts that the first element is less than or equal to the second
   509  //
   510  //	assert.LessOrEqualf(t, 1, 2, "error message %s", "formatted")
   511  //	assert.LessOrEqualf(t, 2, 2, "error message %s", "formatted")
   512  //	assert.LessOrEqualf(t, "a", "b", "error message %s", "formatted")
   513  //	assert.LessOrEqualf(t, "b", "b", "error message %s", "formatted")
   514  func LessOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) {
   515  	if h, ok := t.(tHelper); ok {
   516  		h.Helper()
   517  	}
   518  	if assert.LessOrEqualf(t, e1, e2, msg, args...) {
   519  		return
   520  	}
   521  	t.FailNow()
   522  }
   523  
   524  // Lessf asserts that the first element is less than the second
   525  //
   526  //	assert.Lessf(t, 1, 2, "error message %s", "formatted")
   527  //	assert.Lessf(t, float64(1), float64(2), "error message %s", "formatted")
   528  //	assert.Lessf(t, "a", "b", "error message %s", "formatted")
   529  func Lessf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) {
   530  	if h, ok := t.(tHelper); ok {
   531  		h.Helper()
   532  	}
   533  	if assert.Lessf(t, e1, e2, msg, args...) {
   534  		return
   535  	}
   536  	t.FailNow()
   537  }
   538  
   539  // Negative asserts that the specified element is negative
   540  //
   541  //	assert.Negative(t, -1)
   542  //	assert.Negative(t, -1.23)
   543  func Negative(t TestingT, e interface{}, msgAndArgs ...interface{}) {
   544  	if h, ok := t.(tHelper); ok {
   545  		h.Helper()
   546  	}
   547  	if assert.Negative(t, e, msgAndArgs...) {
   548  		return
   549  	}
   550  	t.FailNow()
   551  }
   552  
   553  // Negativef asserts that the specified element is negative
   554  //
   555  //	assert.Negativef(t, -1, "error message %s", "formatted")
   556  //	assert.Negativef(t, -1.23, "error message %s", "formatted")
   557  func Negativef(t TestingT, e interface{}, msg string, args ...interface{}) {
   558  	if h, ok := t.(tHelper); ok {
   559  		h.Helper()
   560  	}
   561  	if assert.Negativef(t, e, msg, args...) {
   562  		return
   563  	}
   564  	t.FailNow()
   565  }
   566  
   567  // Nil asserts that the specified object is nil.
   568  //
   569  //	assert.Nil(t, err)
   570  func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) {
   571  	if h, ok := t.(tHelper); ok {
   572  		h.Helper()
   573  	}
   574  	if assert.Nil(t, object, msgAndArgs...) {
   575  		return
   576  	}
   577  	t.FailNow()
   578  }
   579  
   580  // Nilf asserts that the specified object is nil.
   581  //
   582  //	assert.Nilf(t, err, "error message %s", "formatted")
   583  func Nilf(t TestingT, object interface{}, msg string, args ...interface{}) {
   584  	if h, ok := t.(tHelper); ok {
   585  		h.Helper()
   586  	}
   587  	if assert.Nilf(t, object, msg, args...) {
   588  		return
   589  	}
   590  	t.FailNow()
   591  }
   592  
   593  // NoError asserts that a function returned no error (i.e. `nil`).
   594  //
   595  //	  actualObj, err := SomeFunction()
   596  //	  if assert.NoError(t, err) {
   597  //		   assert.Equal(t, expectedObj, actualObj)
   598  //	  }
   599  func NoError(t TestingT, err error, msgAndArgs ...interface{}) {
   600  	if h, ok := t.(tHelper); ok {
   601  		h.Helper()
   602  	}
   603  	if assert.NoError(t, err, msgAndArgs...) {
   604  		return
   605  	}
   606  	t.FailNow()
   607  }
   608  
   609  // NoErrorf asserts that a function returned no error (i.e. `nil`).
   610  //
   611  //	  actualObj, err := SomeFunction()
   612  //	  if assert.NoErrorf(t, err, "error message %s", "formatted") {
   613  //		   assert.Equal(t, expectedObj, actualObj)
   614  //	  }
   615  func NoErrorf(t TestingT, err error, msg string, args ...interface{}) {
   616  	if h, ok := t.(tHelper); ok {
   617  		h.Helper()
   618  	}
   619  	if assert.NoErrorf(t, err, msg, args...) {
   620  		return
   621  	}
   622  	t.FailNow()
   623  }
   624  
   625  // NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the
   626  // specified substring or element.
   627  //
   628  //	assert.NotContains(t, "Hello World", "Earth")
   629  //	assert.NotContains(t, ["Hello", "World"], "Earth")
   630  //	assert.NotContains(t, {"Hello": "World"}, "Earth")
   631  func NotContains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) {
   632  	if h, ok := t.(tHelper); ok {
   633  		h.Helper()
   634  	}
   635  	if assert.NotContains(t, s, contains, msgAndArgs...) {
   636  		return
   637  	}
   638  	t.FailNow()
   639  }
   640  
   641  // NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the
   642  // specified substring or element.
   643  //
   644  //	assert.NotContainsf(t, "Hello World", "Earth", "error message %s", "formatted")
   645  //	assert.NotContainsf(t, ["Hello", "World"], "Earth", "error message %s", "formatted")
   646  //	assert.NotContainsf(t, {"Hello": "World"}, "Earth", "error message %s", "formatted")
   647  func NotContainsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) {
   648  	if h, ok := t.(tHelper); ok {
   649  		h.Helper()
   650  	}
   651  	if assert.NotContainsf(t, s, contains, msg, args...) {
   652  		return
   653  	}
   654  	t.FailNow()
   655  }
   656  
   657  // NotEqual asserts that the specified values are NOT equal.
   658  //
   659  //	assert.NotEqual(t, obj1, obj2)
   660  //
   661  // Pointer variable equality is determined based on the equality of the
   662  // referenced values (as opposed to the memory addresses).
   663  func NotEqual(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
   664  	if h, ok := t.(tHelper); ok {
   665  		h.Helper()
   666  	}
   667  	if assert.NotEqual(t, expected, actual, msgAndArgs...) {
   668  		return
   669  	}
   670  	t.FailNow()
   671  }
   672  
   673  // NotEqualValues asserts that two objects are not equal even when converted to the same type
   674  //
   675  //	assert.NotEqualValues(t, obj1, obj2)
   676  func NotEqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
   677  	if h, ok := t.(tHelper); ok {
   678  		h.Helper()
   679  	}
   680  	if assert.NotEqualValues(t, expected, actual, msgAndArgs...) {
   681  		return
   682  	}
   683  	t.FailNow()
   684  }
   685  
   686  // NotEqualValuesf asserts that two objects are not equal even when converted to the same type
   687  //
   688  //	assert.NotEqualValuesf(t, obj1, obj2, "error message %s", "formatted")
   689  func NotEqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {
   690  	if h, ok := t.(tHelper); ok {
   691  		h.Helper()
   692  	}
   693  	if assert.NotEqualValuesf(t, expected, actual, msg, args...) {
   694  		return
   695  	}
   696  	t.FailNow()
   697  }
   698  
   699  // NotEqualf asserts that the specified values are NOT equal.
   700  //
   701  //	assert.NotEqualf(t, obj1, obj2, "error message %s", "formatted")
   702  //
   703  // Pointer variable equality is determined based on the equality of the
   704  // referenced values (as opposed to the memory addresses).
   705  func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {
   706  	if h, ok := t.(tHelper); ok {
   707  		h.Helper()
   708  	}
   709  	if assert.NotEqualf(t, expected, actual, msg, args...) {
   710  		return
   711  	}
   712  	t.FailNow()
   713  }
   714  
   715  // NotNil asserts that the specified object is not nil.
   716  //
   717  //	assert.NotNil(t, err)
   718  func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) {
   719  	if h, ok := t.(tHelper); ok {
   720  		h.Helper()
   721  	}
   722  	if assert.NotNil(t, object, msgAndArgs...) {
   723  		return
   724  	}
   725  	t.FailNow()
   726  }
   727  
   728  // NotNilf asserts that the specified object is not nil.
   729  //
   730  //	assert.NotNilf(t, err, "error message %s", "formatted")
   731  func NotNilf(t TestingT, object interface{}, msg string, args ...interface{}) {
   732  	if h, ok := t.(tHelper); ok {
   733  		h.Helper()
   734  	}
   735  	if assert.NotNilf(t, object, msg, args...) {
   736  		return
   737  	}
   738  	t.FailNow()
   739  }
   740  
   741  // Positive asserts that the specified element is positive
   742  //
   743  //	assert.Positive(t, 1)
   744  //	assert.Positive(t, 1.23)
   745  func Positive(t TestingT, e interface{}, msgAndArgs ...interface{}) {
   746  	if h, ok := t.(tHelper); ok {
   747  		h.Helper()
   748  	}
   749  	if assert.Positive(t, e, msgAndArgs...) {
   750  		return
   751  	}
   752  	t.FailNow()
   753  }
   754  
   755  // Positivef asserts that the specified element is positive
   756  //
   757  //	assert.Positivef(t, 1, "error message %s", "formatted")
   758  //	assert.Positivef(t, 1.23, "error message %s", "formatted")
   759  func Positivef(t TestingT, e interface{}, msg string, args ...interface{}) {
   760  	if h, ok := t.(tHelper); ok {
   761  		h.Helper()
   762  	}
   763  	if assert.Positivef(t, e, msg, args...) {
   764  		return
   765  	}
   766  	t.FailNow()
   767  }
   768  
   769  // True asserts that the specified value is true.
   770  //
   771  //	assert.True(t, myBool)
   772  func True(t TestingT, value bool, msgAndArgs ...interface{}) {
   773  	if h, ok := t.(tHelper); ok {
   774  		h.Helper()
   775  	}
   776  	if assert.True(t, value, msgAndArgs...) {
   777  		return
   778  	}
   779  	t.FailNow()
   780  }
   781  
   782  // Truef asserts that the specified value is true.
   783  //
   784  //	assert.Truef(t, myBool, "error message %s", "formatted")
   785  func Truef(t TestingT, value bool, msg string, args ...interface{}) {
   786  	if h, ok := t.(tHelper); ok {
   787  		h.Helper()
   788  	}
   789  	if assert.Truef(t, value, msg, args...) {
   790  		return
   791  	}
   792  	t.FailNow()
   793  }
   794  
   795  // WithinDuration asserts that the two times are within duration delta of each other.
   796  //
   797  //	assert.WithinDuration(t, time.Now(), time.Now(), 10*time.Second)
   798  func WithinDuration(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) {
   799  	if h, ok := t.(tHelper); ok {
   800  		h.Helper()
   801  	}
   802  	if assert.WithinDuration(t, expected, actual, delta, msgAndArgs...) {
   803  		return
   804  	}
   805  	t.FailNow()
   806  }
   807  
   808  // WithinDurationf asserts that the two times are within duration delta of each other.
   809  //
   810  //	assert.WithinDurationf(t, time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted")
   811  func WithinDurationf(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{}) {
   812  	if h, ok := t.(tHelper); ok {
   813  		h.Helper()
   814  	}
   815  	if assert.WithinDurationf(t, expected, actual, delta, msg, args...) {
   816  		return
   817  	}
   818  	t.FailNow()
   819  }
   820  

View as plain text