stretchr / testify

A toolkit with common assertions and mocks that plays nicely with the standard library
MIT License
22.52k stars 1.56k forks source link

assert.EqualExportedValues - panic: reflect.MakeSlice of non-slice type [recovered] #1515

Closed tommynanny closed 4 months ago

tommynanny commented 7 months ago
import (
    "github.com/lib/pq"
)

type User struct {
        ...
    Roles                    pq.StringArray `json:"roles" gorm:"type:text[]"`
}

----
"github.com/lib/pq"
type StringArray []string  //https://github.com/lib/pq/blob/3d613208bca2e74f2a20e04126ed30bcb5c4cc27/array.go#L626
panic: reflect.MakeSlice of non-slice type [recovered]
        panic: reflect.MakeSlice of non-slice type

goroutine 86 [running]:
testing.tRunner.func1.2({0x1027680, 0x1246ea0})
        C:/Program Files/Go/src/testing/testing.go:1545 +0x238
testing.tRunner.func1()
        C:/Program Files/Go/src/testing/testing.go:1548 +0x397
panic({0x1027680?, 0x1246ea0?})
        C:/Program Files/Go/src/runtime/panic.go:914 +0x21f
reflect.MakeSlice({0x125aa28, 0x1100c60}, 0x10, 0x10)
        C:/Program Files/Go/src/reflect/value.go:3135 +0x171
github.com/stretchr/testify/assert.copyExportedFields({0x1100c60, 0xc0002c8e00})
        C:/Users/tommy/go/pkg/mod/github.com/stretchr/testify@v1.8.4/assert/assertions.go:113 +0x22f
github.com/stretchr/testify/assert.copyExportedFields({0x111b960, 0xc0002c8e00})
        C:/Users/tommy/go/pkg/mod/github.com/stretchr/testify@v1.8.4/assert/assertions.go:100 +0x5af
github.com/stretchr/testify/assert.ObjectsExportedFieldsAreEqual({0x111b960?, 0xc0002c8e00?}, {0x111b960, 0xc0002c9000})
        C:/Users/tommy/go/pkg/mod/github.com/stretchr/testify@v1.8.4/assert/assertions.go:144 +0x27
bitbucket.org/anra-mission-manager/mmx-registration-service/app/tests/repository_test_test.TestGetUserById.func3(0x0?)
        C:/Users/tommy/Desktop/anra/repo/mmx-registration-service/app/tests/repository_test/user_test.go:108 +0x12c
testing.tRunner(0xc0005841a0, 0xc00033d900)
        C:/Program Files/Go/src/testing/testing.go:1595 +0xff
created by testing.(*T).Run in goroutine 14
        C:/Program Files/Go/src/testing/testing.go:1648 +0x3ad
FAIL    bitbucket.org/anra-mission-manager/mmx-registration-service/app/tests/repository_test   0.873
hendrywiranto commented 6 months ago

Hi! can you give more explanation about what does this error about? a go.dev example like this would help maintainers understand the issue https://go.dev/play/p/AsRNcxCRdWx

johnfrankmorgan commented 6 months ago

Hi there, I've been running into this same issue when using arrays. I've put together an example here: https://go.dev/play/p/XeoP7BQJeQV I'm using Go 1.21.3

hendrywiranto commented 6 months ago

thank you for the testcase addition @johnfrankmorgan after some digging, I think it's fixed here https://github.com/stretchr/testify/pull/1473 this should be fixed on the next version

also this issue is duplicate of https://github.com/stretchr/testify/issues/1404

johnfrankmorgan commented 6 months ago

That's brilliant, thanks! 😃

hendrywiranto commented 6 months ago

do you have any plan to release some of the fixes? @dolmen

brackendawson commented 4 months ago

Can confirm this is fixed but not yet released. I intend to tag a release very soon.