Closed sutra closed 4 years ago
不支持Association,先skip下。等我处理下Association跳过
杨树 Shu Yang Tel: +8613513517944 Twitter: _CharlieYang Website: http://www.8tree.net
------------------ Original ------------------ From: Sutra Zhou <notifications@github.com> Date: Tue,Sep 22,2020 9:47 PM To: 8treenet/gcache <gcache@noreply.github.com> Cc: Subscribed <subscribed@noreply.github.com> Subject: Re: [8treenet/gcache] Association got panic: runtime error: invalid memory address or nil pointer dereference (#17)
func TestAssociation(t *testing.T) { var tc TestUser db.First(&tc, "user_name = ?", "name_1") assert.Equal(t, "name_1", tc.UserName) assert.Equal(t, 0, len(tc.Roles)) cachePlugin.SkipCache().Preload("Roles").Find(&tc) assert.Equal(t, 2, len(tc.Roles)) db.Preload("Roles").Find(&tc) assert.Equal(t, 2, len(tc.Roles)) var adminRole TestRole db.Model(&adminRole).Where("name = ?", "ADMIN").First(&adminRole) assert.Equal(t, "ADMIN", adminRole.Name) db.Association("Roles") // panic: runtime error: invalid memory address or nil pointer dereference }
Other code see #16, full code see https://github.com/8treenet/gcache/compare/master...sutra:testAssociation?expand=1
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.
那能否有一种机制,默认不开启 gcache,只在需要时开启它呢?我在现有工作良好的代码上增加 gcache,如果 100% 覆盖地去测试太困难了,希望能默认不开启,只在需要的地方开启,这样我可以针对性地对开启了的地方进行测试。
你说的这个需求可以加。不难。明天我一起处理下。 常用的没有问题。外键的这几个用的很少。所以我也没覆盖到
修复了v1.1.10
测试代码如下:
这个删除操作会导致
panic: reflect.Value.Addr of unaddressable value
,测试了去掉 gcache 是能通过测试的。Other code see #16, full code see https://github.com/8treenet/gcache/compare/master...sutra:testAssociation?expand=1