MCPcopy
hub / github.com/stretchr/testify / TestNotEmpty

Function TestNotEmpty

assert/assertions_test.go:2052–2136  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2050}
2051
2052func TestNotEmpty(t *testing.T) {
2053 t.Parallel()
2054
2055 mockT := new(testing.T)
2056 chWithValue := make(chan struct{}, 1)
2057 chWithValue <- struct{}{}
2058
2059 False(t, NotEmpty(mockT, ""), "Empty string is empty")
2060 False(t, NotEmpty(mockT, nil), "Nil is empty")
2061 False(t, NotEmpty(mockT, []string{}), "Empty string array is empty")
2062 False(t, NotEmpty(mockT, 0), "Zero int value is empty")
2063 False(t, NotEmpty(mockT, false), "False value is empty")
2064 False(t, NotEmpty(mockT, make(chan struct{})), "Channel without values is empty")
2065 False(t, NotEmpty(mockT, [1]int{}), "array is state")
2066
2067 True(t, NotEmpty(mockT, "something"), "Non Empty string is not empty")
2068 True(t, NotEmpty(mockT, errors.New("something")), "Non nil object is not empty")
2069 True(t, NotEmpty(mockT, []string{"something"}), "Non empty string array is not empty")
2070 True(t, NotEmpty(mockT, 1), "Non-zero int value is not empty")
2071 True(t, NotEmpty(mockT, true), "True value is not empty")
2072 True(t, NotEmpty(mockT, chWithValue), "Channel with values is not empty")
2073 True(t, NotEmpty(mockT, [1]int{42}), "array is not state")
2074
2075 // error messages validation
2076 tests := []struct {
2077 name string
2078 value interface{}
2079 expectedResult bool
2080 expectedErrMsg string
2081 }{
2082 {
2083 name: "Empty string is empty",
2084 value: "",
2085 expectedResult: false,
2086 expectedErrMsg: `Should NOT be empty, but was ` + "\n", // TODO FIX THIS strange error message
2087 },
2088 {
2089 name: "Nil is empty",
2090 value: nil,
2091 expectedResult: false,
2092 expectedErrMsg: "Should NOT be empty, but was <nil>\n",
2093 },
2094 {
2095 name: "Empty string array is empty",
2096 value: []string{},
2097 expectedResult: false,
2098 expectedErrMsg: "Should NOT be empty, but was []\n",
2099 },
2100 {
2101 name: "Zero int value is empty",
2102 value: 0,
2103 expectedResult: false,
2104 expectedErrMsg: "Should NOT be empty, but was 0\n",
2105 },
2106 {
2107 name: "False value is empty",
2108 value: false,
2109 expectedResult: false,

Callers

nothing calls this directly

Calls 5

checkResultAndErrMsgMethod · 0.80
FalseFunction · 0.70
NotEmptyFunction · 0.70
TrueFunction · 0.70
RunMethod · 0.45

Tested by

no test coverage detected