sebdah / goldie

Golden file testing for Go
MIT License
228 stars 19 forks source link

test failed with Json data #33

Closed maliyan closed 4 years ago

maliyan commented 4 years ago

testdata/foo.golden

{
    "foo": 1,
    "bar": 3
}

foo_test.go

package main

import (
    "testing"

    "github.com/sebdah/goldie/v2"
)

func TestFoo(t *testing.T) {
    g := goldie.New(t)

    g.AssertJson(t, "something", `{"foo": 1, "bar": 2}`)
}

test failed


=== RUN   TestFoo
foo_test.go:12: Result did not match the golden fixture. Diff is below:
    --- Expected
    +++ Actual
    @@ -1,5 +1 @@
    -{
    -    "foo": 1,
    -    "bar": 3
    -}
    -
    +"{\"foo\": 1, \"bar\": 2}"

--- FAIL: TestFoo (0.00s)

sebdah commented 4 years ago

This is because you have new lines in your test data, which is not there in the input data. To make sure they align you can run go test -update ./..., or update the test data file.