Dataset test coverage to 80%
Closed this issue · 0 comments
osterbit commented
(moving qri-io/qri#227 to this repo)
- After looking at codecov, it looks like dataset.vals has the most uncovered lines, and inside that, values.go is the biggest culprit.
- values.go has several functions that are expected to trigger a panic on failure (crash the program instead of just returning an error), which requires a slightly different testing template than usual
- this example from jsonschema's schema_test provides a good template to follow for these types of functions (checks the value held by recover inside a deferred function following a panic):
func TestMust(t *testing.T) {
defer func() {
if r := recover(); r != nil {
if err, ok := r.(error); ok {
if err.Error() != "unexpected end of JSON input" {
t.Errorf("expected panic error to equal: %s", "unexpected end of JSON input")
}
} else {
t.Errorf("must paniced with a non-error")
}
} else {
t.Errorf("expected invalid call to Must to panic")
}
}()
// Valid call to Must shouldn't panic
rs := Must(`{}`)
if rs == nil {
t.Errorf("expected parse of empty schema to return *RootSchema, got nil")
return
}
// This should panic, checked in defer above
Must(``)
}