Replace all []*Foo by []Foo in sql db return values

- Implement SlicePtrsToSlice and use it in all `meddler.QueryAll` sql db functions to always return []Foo instead of []*Foo
This commit is contained in:
Eduard S
2020-10-07 16:39:48 +02:00
parent 0277210c39
commit b14495cfcc
14 changed files with 124 additions and 54 deletions

35
db/utils_test.go Normal file
View File

@@ -0,0 +1,35 @@
package db
import (
"testing"
"github.com/stretchr/testify/assert"
)
type foo struct {
V int
}
func TestSliceToSlicePtrs(t *testing.T) {
n := 16
a := make([]foo, n)
for i := 0; i < n; i++ {
a[i] = foo{V: i}
}
b := SliceToSlicePtrs(a).([]*foo)
for i := 0; i < len(a); i++ {
assert.Equal(t, a[i], *b[i])
}
}
func TestSlicePtrsToSlice(t *testing.T) {
n := 16
a := make([]*foo, n)
for i := 0; i < n; i++ {
a[i] = &foo{V: i}
}
b := SlicePtrsToSlice(a).([]foo)
for i := 0; i < len(a); i++ {
assert.Equal(t, *a[i], b[i])
}
}