Skip to content

Commit

Permalink
impl(internal/language): make TestRust_ParseOptions deterministic
Browse files Browse the repository at this point in the history
Sort RustCodec.ExtraPackages in TestRust_ParseOptions before comparing
the output to ensure the packages show up in the right order.
  • Loading branch information
julieqiu committed Jan 11, 2025
1 parent 9427edb commit 6f83ef1
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions generator/internal/language/rust_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package language

import (
"fmt"
"sort"
"strings"
"testing"

Expand Down Expand Up @@ -50,7 +51,7 @@ func TestRust_ParseOptions(t *testing.T) {
"package:gax": "package=gax,path=src/gax,feature=unstable-sdk-client",
"package:serde_with": "package=serde_with,version=2.3.4,default-features=false",
}
codec, err := NewRustCodec("", options)
got, err := NewRustCodec("", options)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -89,13 +90,19 @@ func TestRust_ParseOptions(t *testing.T) {
"test-only": gp,
},
}
if diff := cmp.Diff(want, codec, cmpopts.IgnoreFields(RustCodec{}, "ExtraPackages", "PackageMapping")); diff != "" {
sort.Slice(want.ExtraPackages, func(i, j int) bool {
return want.ExtraPackages[i].Name < want.ExtraPackages[j].Name
})
sort.Slice(got.ExtraPackages, func(i, j int) bool {
return got.ExtraPackages[i].Name < got.ExtraPackages[j].Name
})
if diff := cmp.Diff(want, got, cmpopts.IgnoreFields(RustCodec{}, "ExtraPackages", "PackageMapping")); diff != "" {
t.Errorf("codec mismatch (-want, +got):\n%s", diff)
}
if want.PackageNameOverride != codec.PackageNameOverride {
t.Errorf("mismatched in packageNameOverride, want=%s, got=%s", want.PackageNameOverride, codec.PackageNameOverride)
if want.PackageNameOverride != got.PackageNameOverride {
t.Errorf("mismatched in packageNameOverride, want=%s, got=%s", want.PackageNameOverride, got.PackageNameOverride)
}
checkRustPackages(t, codec, want)
checkRustPackages(t, got, want)
}

func TestRust_RequiredPackages(t *testing.T) {
Expand Down

0 comments on commit 6f83ef1

Please sign in to comment.