di2019-10-23 11:04:51
di, 2019-10-23 11:04:51

Advanced feature for testing aka reflect.DeepEqual?

I need a function to compare two complex nested structures.
`reflect.DeepEqual` basically copes with its mission, but it returns true or false, and I would like to have more detailed information - which field when compared gave the wrong result, what index the structure had if it was inside the slice. Is there something similar already implemented. That is, I need a function that does the same thing as reflect.DeepEqual, but which will return an error with a description of the problem, not true or false.
Maybe there is something already ready, do not want to write another bike.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Vladislav, 2019-10-23

I will advise https://github.com/stretchr/testify
Namely, the assert package, it shows diff structures.

--- Expected
+++ Actual
@@ -2,5 +2,5 @@
  (int) 1,
- (int) 2,
  (int) 3,
- (int) 4
+ (int) 5,
+ (int) 7

Easy to use:
where t is testing.T (the only argument of the test function)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question