smartystreets / goconvey

Go testing in the browser. Integrates with `go test`. Write behavioral tests in Go.
http://smartystreets.github.io/goconvey/
Other
8.24k stars 555 forks source link

ShouldResemble failing for identical values in GitHub action #665

Open sb10 opened 2 years ago

sb10 commented 2 years ago

Using go 1.19 (also happened with go 1.18) and goconvey v1.7.2 both locally and in a GitHub action, my tests pass locally but fail in GitHub:

https://github.com/wtsi-ssg/wrstat/runs/7804713143?check_suite_focus=true

Failures:
[144](https://github.com/wtsi-ssg/wrstat/runs/7804713143?check_suite_focus=true#step:4:145)

[145](https://github.com/wtsi-ssg/wrstat/runs/7804713143?check_suite_focus=true#step:4:146)
  * /home/runner/work/wrstat/wrstat/server/server_test.go 
[146](https://github.com/wtsi-ssg/wrstat/runs/7804713143?check_suite_focus=true#step:4:147)
  Line 450:
[147](https://github.com/wtsi-ssg/wrstat/runs/7804713143?check_suite_focus=true#step:4:148)
  Expected: '[]*server.DirSummary{(*server.DirSummary){Dir:"/a", Count:15, Size:86, Atime:time.Time{1970-01-01 00:00:50 +0000 UTC}, Users:[]string{"root", "runner"}, Groups:[]string{"adm", "docker", "root"}, FileTypes:[]string{"bam", "cram", "temporary"}}, (*server.DirSummary){Dir:"/a/b", Count:9, Size:80, Atime:time.Time{1970-01-01 00:00:50 +0000 UTC}, Users:[]string{"root", "runner"}, Groups:[]string{"docker"}, FileTypes:[]string{"bam", "cram", "temporary"}}, (*server.DirSummary){Dir:"/a/b/d", Count:7, Size:70, Atime:time.Time{1970-01-01 00:00:50 +0000 UTC}, Users:[]string{"root", "runner"}, Groups:[]string{"docker"}, FileTypes:[]string{"cram"}}, (*server.DirSummary){Dir:"/a/b/e/h", Count:2, Size:10, Atime:time.Time{1970-01-01 00:00:50 +0000 UTC}, Users:[]string{"runner"}, Groups:[]string{"docker"}, FileTypes:[]string{"bam", "temporary"}}, (*server.DirSummary){Dir:"/a/c/d", Count:5, Size:5, Atime:time.Time{1970-01-01 00:00:50 +0000 UTC}, Users:[]string{"root"}, Groups:[]string{"adm"}, FileTypes:[]string{"cram"}}}'
[148](https://github.com/wtsi-ssg/wrstat/runs/7804713143?check_suite_focus=true#step:4:149)
  Actual:   '[]*server.DirSummary{(*server.DirSummary){Dir:"/a", Count:15, Size:86, Atime:time.Time{1970-01-01 00:00:50 +0000 UTC}, Users:[]string{"root", "runner"}, Groups:[]string{"adm", "docker", "root"}, FileTypes:[]string{"bam", "cram", "temporary"}}, (*server.DirSummary){Dir:"/a/b", Count:9, Size:80, Atime:time.Time{1970-01-01 00:00:50 +0000 UTC}, Users:[]string{"root", "runner"}, Groups:[]string{"docker"}, FileTypes:[]string{"bam", "cram", "temporary"}}, (*server.DirSummary){Dir:"/a/b/d", Count:7, Size:70, Atime:time.Time{1970-01-01 00:00:50 +0000 UTC}, Users:[]string{"root", "runner"}, Groups:[]string{"docker"}, FileTypes:[]string{"cram"}}, (*server.DirSummary){Dir:"/a/b/e/h", Count:2, Size:10, Atime:time.Time{1970-01-01 00:00:50 +0000 UTC}, Users:[]string{"runner"}, Groups:[]string{"docker"}, FileTypes:[]string{"bam", "temporary"}}, (*server.DirSummary){Dir:"/a/c/d", Count:5, Size:5, Atime:time.Time{1970-01-01 00:00:50 +0000 UTC}, Users:[]string{"root"}, Groups:[]string{"adm"}, FileTypes:[]string{"cram"}}}'
[149](https://github.com/wtsi-ssg/wrstat/runs/7804713143?check_suite_focus=true#step:4:150)
  (Should resemble)!
[150](https://github.com/wtsi-ssg/wrstat/runs/7804713143?check_suite_focus=true#step:4:151)
  Diff:     '[]*server.DirSummary{(*server.DirSummary){Dir:"/a", Count:15, Size:86, Atime:time.Time{1970-01-01 00:00:50 +0000 UTC}, Users:[]string{"root", "runner"}, Groups:[]string{"adm", "docker", "root"}, FileTypes:[]string{"bam", "cram", "temporary"}}, (*server.DirSummary){Dir:"/a/b", Count:9, Size:80, Atime:time.Time{1970-01-01 00:00:50 +0000 UTC}, Users:[]string{"root", "runner"}, Groups:[]string{"docker"}, FileTypes:[]string{"bam", "cram", "temporary"}}, (*server.DirSummary){Dir:"/a/b/d", Count:7, Size:70, Atime:time.Time{1970-01-01 00:00:50 +0000 UTC}, Users:[]string{"root", "runner"}, Groups:[]string{"docker"}, FileTypes:[]string{"cram"}}, (*server.DirSummary){Dir:"/a/b/e/h", Count:2, Size:10, Atime:time.Time{1970-01-01 00:00:50 +0000 UTC}, Users:[]string{"runner"}, Groups:[]string{"docker"}, FileTypes:[]string{"bam", "temporary"}}, (*server.DirSummary){Dir:"/a/c/d", Count:5, Size:5, Atime:time.Time{1970-01-01 00:00:50 +0000 UTC}, Users:[]string{"root"}, Groups:[]string{"adm"}, FileTypes:[]string{"cram"}}}'

You will note that the "Expected" and "Actual" strings that it prints out are actually identical.

Why would this be happening, and what can I do about it?

sb10 commented 2 years ago

After a bit of debugging, it looks like when you defer to reflect.DeepEqual, it's returning false. So not your "fault", but the message returned is confusing.

Why isn't ShouldResemble implemented by doing something like:

renderedExpected, renderedActual := render.Render(expected[0]), render.Render(actual)
if renderedExpected != renderedActual {
   ...
}
srabraham commented 1 year ago

I just encountered what I think is the same issue. It happens when two different int types are compared.

func TestSillyDiff(t *testing.T) {
    type value struct {
        v any
    }
    v1 := value{int(123)}
    v2 := value{int64(123)}
    Convey("These things ain't the same", t, func() {
        // this passes
        So(reflect.DeepEqual(v1, v2), ShouldBeFalse)
        // this fails, see message below this block
        So(v1, ShouldResemble, v2)
    })
}

the above prints something like this, which is technically true, but the diff is useless

  Line 28:
  Expected: 'pkg.value{v:123}'
  Actual:   'pkg.value{v:123}'
  (Should resemble)!
  Diff:     'pkg.value{v:123}'