Skip to content

chore: increase parallelism of TestWorkspaceQuota #6710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 21, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Generator was not handling "nil" slices correctly
  • Loading branch information
Emyrk committed Mar 21, 2023
commit 012e2cb38ebc846882f64aca478c67ad39eaaac4
15 changes: 9 additions & 6 deletions coderd/database/dbgen/take.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package dbgen

import "net"
import (
"net"
)

func takeFirstIP(values ...net.IPNet) net.IPNet {
takeFirstSlice([]string{})

return takeFirstF(values, func(v net.IPNet) bool {
return len(v.IP) != 0 && len(v.Mask) != 0
})
Expand All @@ -14,19 +14,22 @@ func takeFirstIP(values ...net.IPNet) net.IPNet {
// []any is not a comparable type.
func takeFirstSlice[T any](values ...[]T) []T {
return takeFirstF(values, func(v []T) bool {
return len(v) != 0
return v != nil && len(v) != 0
})
}

// takeFirstF takes the first value that returns true
func takeFirstF[Value any](values []Value, take func(v Value) bool) Value {
var empty Value
for _, v := range values {
if take(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
}

Expand Down