Skip to content

Commit

Permalink
Use go-cmp/cmp in randomizer test to handle more values
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenafamo committed Jan 5, 2024
1 parent a3eca35 commit e6a3162
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions gen/templates/factory/singleton/bobfactory_random_test.go.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{$.Importer.Import "testing"}}
{{$.Importer.Import "github.com/google/go-cmp/cmp"}}


{{$doneTypes := dict }}
Expand All @@ -10,14 +11,14 @@
{{- $.Importer.ImportList $column.Imports -}}
{{- $_ := set $doneTypes $colTyp nil -}}

func TestRandom_{{replace "." "_" $colTyp}}(t *testing.T) {
func TestRandom_{{$colTyp | replace "." "_" | replace "[" "_" | replace "]" "_"}}(t *testing.T) {
t.Parallel()
seen := make([]{{$colTyp}}, 10)
for i := 0; i < 10; i++ {
seen[i] = random[{{$colTyp}}](nil)
for j := 0; j < i; j++ {
if seen[i] == seen[j] {
if cmp.Equal(seen[i], seen[j]) {
t.Fatalf("random[{{$colTyp}}]() returned the same value twice: %v", seen[i])
}
}
Expand Down

0 comments on commit e6a3162

Please sign in to comment.