chore: dbgen passing nil slices to postgres is not valid (#6714)

This commit is contained in:
Steven Masley
2023-03-22 09:10:49 -05:00
committed by GitHub
parent 5460ab4ba6
commit ab764db8c8
2 changed files with 9 additions and 7 deletions

View File

@ -1153,6 +1153,7 @@ func (s *MethodTestSuite) TestWorkspace() {
ID: build.ID, ID: build.ID,
UpdatedAt: build.UpdatedAt, UpdatedAt: build.UpdatedAt,
Deadline: build.Deadline, Deadline: build.Deadline,
ProvisionerState: []byte{},
}).Asserts(ws, rbac.ActionUpdate).Returns(build) }).Asserts(ws, rbac.ActionUpdate).Returns(build)
})) }))
s.Run("SoftDeleteWorkspaceByID", s.Subtest(func(db database.Store, check *expects) { s.Run("SoftDeleteWorkspaceByID", s.Subtest(func(db database.Store, check *expects) {

View File

@ -3,8 +3,6 @@ package dbgen
import "net" import "net"
func takeFirstIP(values ...net.IPNet) net.IPNet { func takeFirstIP(values ...net.IPNet) net.IPNet {
takeFirstSlice([]string{})
return takeFirstF(values, func(v net.IPNet) bool { return takeFirstF(values, func(v net.IPNet) bool {
return len(v.IP) != 0 && len(v.Mask) != 0 return len(v.IP) != 0 && len(v.Mask) != 0
}) })
@ -20,13 +18,16 @@ func takeFirstSlice[T any](values ...[]T) []T {
// takeFirstF takes the first value that returns true // takeFirstF takes the first value that returns true
func takeFirstF[Value any](values []Value, take func(v Value) bool) Value { func takeFirstF[Value any](values []Value, take func(v Value) bool) Value {
var empty Value
for _, v := range values { for _, v := range values {
if take(v) { if take(v) {
return v return v
} }
} }
// If all empty, return empty // If all empty, return the last element
if len(values) > 0 {
return values[len(values)-1]
}
var empty Value
return empty return empty
} }