🧑💻 Show diff between test output and golden file
This commit is contained in:
parent
2704399e3f
commit
8ce87b8603
2
go.mod
2
go.mod
|
@ -1,3 +1,5 @@
|
||||||
module source.toby3d.me/toby3d/hacks
|
module source.toby3d.me/toby3d/hacks
|
||||||
|
|
||||||
go 1.22.0
|
go 1.22.0
|
||||||
|
|
||||||
|
require github.com/google/go-cmp v0.6.0
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||||
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
|
@ -2,13 +2,14 @@
|
||||||
package testing
|
package testing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
)
|
)
|
||||||
|
|
||||||
//nolint:gochecknoglobals // сompiler global flags cannot be read from within tests
|
//nolint:gochecknoglobals // сompiler global flags cannot be read from within tests
|
||||||
|
@ -67,7 +68,7 @@ func GoldenEqual(tb testing.TB, output io.Reader) {
|
||||||
tb.Fatal("cannot read golden file data:", err)
|
tb.Fatal("cannot read golden file data:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.Equal(actual, expect) {
|
if diff := cmp.Diff(actual, expect); diff != "" {
|
||||||
tb.Errorf("the test output does not match the contents of %s.golden file", tb.Name())
|
tb.Error(diff)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue