Skip to content

Commit

Permalink
fixup! Export test-specific functions without go:linkname
Browse files Browse the repository at this point in the history
  • Loading branch information
adombeck committed Dec 5, 2024
1 parent 7d8f2e3 commit 978d4d8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
14 changes: 7 additions & 7 deletions internal/services/pam/pam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func TestGetAuthenticationModes(t *testing.T) {
}

// Now, set tests permissions for this use case
pm.Z_ForTests_SetCurrentUserAsRoot(!tc.currentUserNotRoot)
permissions.Z_ForTests_SetCurrentUserAsRoot(&pm, !tc.currentUserNotRoot)

if tc.supportedUILayouts == nil {
tc.supportedUILayouts = []*authd.UILayout{requiredEntry}
Expand Down Expand Up @@ -393,7 +393,7 @@ func TestSelectAuthenticationMode(t *testing.T) {
}

// Now, set tests permissions for this use case
pm.Z_ForTests_SetCurrentUserAsRoot(!tc.currentUserNotRoot)
permissions.Z_ForTests_SetCurrentUserAsRoot(&pm, !tc.currentUserNotRoot)

samReq := &authd.SAMRequest{
SessionId: tc.sessionID,
Expand Down Expand Up @@ -484,7 +484,7 @@ func TestIsAuthenticated(t *testing.T) {
}

// Now, set tests permissions for this use case
pm.Z_ForTests_SetCurrentUserAsRoot(!tc.currentUserNotRoot)
permissions.Z_ForTests_SetCurrentUserAsRoot(&pm, !tc.currentUserNotRoot)

var firstCall, secondCall string
ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -532,7 +532,7 @@ func TestIsAuthenticated(t *testing.T) {
require.Equal(t, want, got, "IsAuthenticated should return the expected combined data, but did not")

// Check that cache has been updated too.
gotDB, err := userstestutils.GetManagerCache(m).Z_ForTests_DumpNormalizedYAML()
gotDB, err := cache.Z_ForTests_DumpNormalizedYAML(userstestutils.GetManagerCache(m))
require.NoError(t, err, "Setup: failed to dump database for comparing")
wantDB := golden.LoadWithUpdate(t, gotDB, golden.WithPath("cache.db"))
require.Equal(t, wantDB, gotDB, "IsAuthenticated should update the cache database as expected")
Expand Down Expand Up @@ -573,7 +573,7 @@ func TestIDGeneration(t *testing.T) {
require.NoError(t, err, "Setup: could not authenticate user")
require.Equal(t, "granted", resp.GetAccess(), "Setup: authentication should be granted")

gotDB, err := userstestutils.GetManagerCache(m).Z_ForTests_DumpNormalizedYAML()
gotDB, err := cache.Z_ForTests_DumpNormalizedYAML(userstestutils.GetManagerCache(m))
require.NoError(t, err, "Setup: failed to dump database for comparing")
wantDB := golden.LoadWithUpdate(t, gotDB, golden.WithPath("cache.db"))
require.Equal(t, wantDB, gotDB, "IsAuthenticated should update the cache database as expected")
Expand Down Expand Up @@ -633,7 +633,7 @@ func TestSetDefaultBrokerForUser(t *testing.T) {
require.Equal(t, tc.brokerID, gpbResp.GetPreviousBroker(), "SetDefaultBrokerForUser should set the default broker as expected")

// Check that cache has been updated too.
gotDB, err := userstestutils.GetManagerCache(m).Z_ForTests_DumpNormalizedYAML()
gotDB, err := cache.Z_ForTests_DumpNormalizedYAML(userstestutils.GetManagerCache(m))
require.NoError(t, err, "Setup: failed to dump database for comparing")
wantDB := golden.LoadWithUpdate(t, gotDB, golden.WithPath("cache.db"))
require.Equal(t, wantDB, gotDB, "SetDefaultBrokerForUser should update the cache database as expected")
Expand Down Expand Up @@ -678,7 +678,7 @@ func TestEndSession(t *testing.T) {
}

// Now, set tests permissions for this use case
pm.Z_ForTests_SetCurrentUserAsRoot(!tc.currentUserNotRoot)
permissions.Z_ForTests_SetCurrentUserAsRoot(&pm, !tc.currentUserNotRoot)

esReq := &authd.ESRequest{
SessionId: tc.sessionID,
Expand Down
2 changes: 1 addition & 1 deletion internal/services/permissions/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func currentUserUID() uint32 {
// Z_ForTests_SetCurrentUserAsRoot mutates a default permission to the current user's UID if currentUserAsRoot is true.
//
// nolint:revive,nolintlint // We want to use underscores in the function name here.
func (m *Manager) Z_ForTests_SetCurrentUserAsRoot(currentUserAsRoot bool) {
func Z_ForTests_SetCurrentUserAsRoot(m *Manager, currentUserAsRoot bool) {
testsdetection.MustBeTesting()

if !currentUserAsRoot {
Expand Down
6 changes: 3 additions & 3 deletions internal/users/cache/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestNew(t *testing.T) {
require.NoError(t, err)
defer c.Close()

got, err := c.Z_ForTests_DumpNormalizedYAML()
got, err := cache.Z_ForTests_DumpNormalizedYAML(c)
require.NoError(t, err, "Created database should be valid yaml content")

want := golden.LoadWithUpdate(t, got)
Expand Down Expand Up @@ -225,7 +225,7 @@ func TestUpdateUserEntry(t *testing.T) {
}
require.NoError(t, err)

got, err := c.Z_ForTests_DumpNormalizedYAML()
got, err := cache.Z_ForTests_DumpNormalizedYAML(c)
require.NoError(t, err, "Created database should be valid yaml content")

want := golden.LoadWithUpdate(t, got)
Expand Down Expand Up @@ -479,7 +479,7 @@ func TestDeleteUser(t *testing.T) {
}
require.NoError(t, err)

got, err := c.Z_ForTests_DumpNormalizedYAML()
got, err := cache.Z_ForTests_DumpNormalizedYAML(c)
require.NoError(t, err, "Created database should be valid yaml content")
want := golden.LoadWithUpdate(t, got)
require.Equal(t, want, got, "Did not get expected database content")
Expand Down
2 changes: 1 addition & 1 deletion internal/users/cache/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func redactTime(line string) string {
// (so that it can be compared with a golden file) and returns it as a YAML string.
//
// nolint:revive,nolintlint // We want to use underscores in the function name here.
func (c *Cache) Z_ForTests_DumpNormalizedYAML() (string, error) {
func Z_ForTests_DumpNormalizedYAML(c *Cache) (string, error) {
testsdetection.MustBeTesting()

d := make(map[string]map[string]string)
Expand Down
6 changes: 3 additions & 3 deletions internal/users/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestNewManager(t *testing.T) {
}
require.NoError(t, err, "NewManager should not return an error, but did")

got, err := userstestutils.GetManagerCache(m).Z_ForTests_DumpNormalizedYAML()
got, err := cache.Z_ForTests_DumpNormalizedYAML(userstestutils.GetManagerCache(m))
require.NoError(t, err, "Created database should be valid yaml content")

want := golden.LoadWithUpdate(t, got)
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestUpdateUser(t *testing.T) {
require.Equal(t, oldUID, newUser.UID, "UID should not have changed")
}

got, err := userstestutils.GetManagerCache(m).Z_ForTests_DumpNormalizedYAML()
got, err := cache.Z_ForTests_DumpNormalizedYAML(userstestutils.GetManagerCache(m))
require.NoError(t, err, "Created database should be valid yaml content")

want := golden.LoadWithUpdateYAML(t, got)
Expand Down Expand Up @@ -314,7 +314,7 @@ func TestUpdateBrokerForUser(t *testing.T) {
return
}

got, err := userstestutils.GetManagerCache(m).Z_ForTests_DumpNormalizedYAML()
got, err := cache.Z_ForTests_DumpNormalizedYAML(userstestutils.GetManagerCache(m))
require.NoError(t, err, "Created database should be valid yaml content")

want := golden.LoadWithUpdateYAML(t, got)
Expand Down

0 comments on commit 978d4d8

Please sign in to comment.