Skip to content

Commit

Permalink
Make content of golden file deterministic
Browse files Browse the repository at this point in the history
To avoid random changes to the golden file when running tests with
TESTS_UPDATE_GOLDEN=1.
  • Loading branch information
adombeck authored and didrocks committed Oct 2, 2024
1 parent 0f277ab commit 01af328
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
8 changes: 8 additions & 0 deletions internal/services/manager_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package services_test

import (
"cmp"
"context"
"fmt"
"net"
"os"
"path/filepath"
"slices"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -59,6 +61,12 @@ func TestRegisterGRPCServices(t *testing.T) {
defer require.NoError(t, m.Stop(), "Teardown: Stop should not have returned an error, but did")

got := m.RegisterGRPCServices(context.Background()).GetServiceInfo()
// Make the content of the golden file deterministic by sorting the methods by name.
for _, info := range got {
slices.SortFunc(info.Methods, func(a, b grpc.MethodInfo) int {
return cmp.Compare(a.Name, b.Name)
})
}
want := testutils.LoadWithUpdateFromGoldenYAML(t, got)
requireEqualServices(t, want, got)
}
Expand Down
30 changes: 15 additions & 15 deletions internal/services/testdata/TestRegisterGRPCServices/golden
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
authd.NSS:
methods:
- name: GetPasswdByUID
- name: GetGroupByGID
isclientstream: false
isserverstream: false
- name: GetPasswdEntries
- name: GetGroupByName
isclientstream: false
isserverstream: false
- name: GetGroupByName
- name: GetGroupEntries
isclientstream: false
isserverstream: false
- name: GetGroupByGID
- name: GetPasswdByName
isclientstream: false
isserverstream: false
- name: GetGroupEntries
- name: GetPasswdByUID
isclientstream: false
isserverstream: false
- name: GetShadowByName
- name: GetPasswdEntries
isclientstream: false
isserverstream: false
- name: GetShadowEntries
- name: GetShadowByName
isclientstream: false
isserverstream: false
- name: GetPasswdByName
- name: GetShadowEntries
isclientstream: false
isserverstream: false
metadata: authd.proto
authd.PAM:
methods:
- name: SelectAuthenticationMode
- name: AvailableBrokers
isclientstream: false
isserverstream: false
- name: IsAuthenticated
- name: EndSession
isclientstream: false
isserverstream: false
- name: EndSession
- name: GetAuthenticationModes
isclientstream: false
isserverstream: false
- name: SetDefaultBrokerForUser
- name: GetPreviousBroker
isclientstream: false
isserverstream: false
- name: AvailableBrokers
- name: IsAuthenticated
isclientstream: false
isserverstream: false
- name: GetPreviousBroker
- name: SelectAuthenticationMode
isclientstream: false
isserverstream: false
- name: SelectBroker
isclientstream: false
isserverstream: false
- name: GetAuthenticationModes
- name: SetDefaultBrokerForUser
isclientstream: false
isserverstream: false
metadata: authd.proto

0 comments on commit 01af328

Please sign in to comment.