I'm testing a scenario where json.Unmarshall
fails and returns
&json.SyntaxError{msg:"unexpected end of JSON input", Offset:0}
the code is like this:
err = json.Unmarshal(input, &data)
if err != nil {
return nil, err
}
test case is expecting this type of error:
{
...
errorType: &json.SyntaxError{},
...
}
the assertion is like this:
assert.Equal(t, tt.errorType, err)
which is failing because the error message is different:
expected: &json.SyntaxError{msg:"", Offset:0}
actual : &json.SyntaxError{msg:"unexpected end of JSON input", Offset:0}
How can I handle this? Perhaps making use of Error()
?