MCPcopy Index your code
hub / github.com/GetStream/stream-go2 / Test_parseIntValue

Function Test_parseIntValue

utils_internal_test.go:99–142  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

97}
98
99func Test_parseIntValue(t *testing.T) {
100 testCases := []struct {
101 values url.Values
102 shouldError bool
103 expected int
104 expectedFlag bool
105 }{
106 {
107 values: url.Values{},
108 shouldError: false,
109 expected: 0,
110 expectedFlag: false,
111 },
112 {
113 values: url.Values{"test": []string{"a"}},
114 shouldError: true,
115 expected: 0,
116 expectedFlag: false,
117 },
118 {
119 values: url.Values{"test": []string{"123"}},
120 shouldError: false,
121 expected: 123,
122 expectedFlag: true,
123 },
124 {
125 values: url.Values{"test": []string{"123.5"}},
126 shouldError: true,
127 expected: 0,
128 expectedFlag: false,
129 },
130 }
131 for _, tc := range testCases {
132 v, ok, err := parseIntValue(tc.values, "test")
133 if tc.shouldError {
134 require.Error(t, err)
135 assert.False(t, ok)
136 } else {
137 require.NoError(t, err)
138 assert.Equal(t, tc.expectedFlag, ok)
139 assert.Equal(t, tc.expected, v)
140 }
141 }
142}

Callers

nothing calls this directly

Calls 2

parseIntValueFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected