zrhoffman commented on code in PR #7288:
URL: https://github.com/apache/trafficcontrol/pull/7288#discussion_r1126918455
##########
lib/go-util/assert/assertions.go:
##########
@@ -162,3 +162,63 @@ func RequireNotEqual(t *testing.T, a, b interface{},
msgAndArgs ...interface{})
t.FailNow()
}
}
+
+// Empty takes a value and checks whether it is empty for the given type
+// supports slices, arrays, channels, strings, and maps
+func Empty(t *testing.T, a interface{}) {
+ val := reflect.ValueOf(a)
+ switch val.Kind() {
+ case reflect.Slice:
+ if val.Len() != 0 {
+ t.Errorf("expected %v to be empty, but it is not", a)
+ }
+ case reflect.Array:
+ if val.Len() != 0 {
+ t.Errorf("expected %v to be empty, but it is not", a)
+ }
+ case reflect.Chan:
+ if val.Len() != 0 {
+ t.Errorf("expected %v to be empty, but it is not", a)
+ }
+ case reflect.String:
+ if val.Len() != 0 {
+ t.Errorf("expected %v to be empty, but it is not", a)
+ }
+ case reflect.Map:
+ if val.Len() != 0 {
+ t.Errorf("expected %v to be empty, but it is not", a)
+ }
+ default:
+ t.Errorf("can't check that %v of type %T is empty", a, a)
+ }
+}
+
+// NotEmpty takes a value and checks whether it isvnot empty for the given type
+// supports slices, arrays, channels, strings, and maps
+func NotEmpty(t *testing.T, a interface{}) {
+ val := reflect.ValueOf(a)
+ switch val.Kind() {
+ case reflect.Slice:
+ if val.Len() == 0 {
+ t.Errorf("expected %v to not be empty, but it is", a)
+ }
+ case reflect.Array:
+ if val.Len() == 0 {
+ t.Errorf("expected %v to not be empty, but it is", a)
+ }
+ case reflect.Chan:
+ if val.Len() == 0 {
+ t.Errorf("expected %v to not be empty, but it is", a)
+ }
+ case reflect.String:
+ if val.Len() == 0 {
+ t.Errorf("expected %v to not be empty, but it is", a)
+ }
+ case reflect.Map:
+ if val.Len() == 0 {
+ t.Errorf("expected %v to not be empty, but it is", a)
+ }
+ default:
+ t.Errorf("can't check that %v of type %T is not empty", a, a)
Review Comment:
> Check warning on line 222 in lib/go-util/assert/assertions.go
> Codecov / codecov/patch
>
> lib/go-util/assert/assertions.go#L198-L222
>
> ```
> Added lines #L198 - L222 were not covered by tests
> ```
I can see that `assert.NotEmpty()` is used in
`traffic_stats/influxdb_tools/sync/sync_test.go`, so that is probably coming
from moving from being covered by one Codecov check to being covered by another.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]