Skip to content
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

refactor: Rename DumpToYaml -> DumpNormalizedYAML #656

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions internal/services/pam/pam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,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 := cachetestutils.DumpToYaml(userstestutils.GetManagerCache(m))
gotDB, err := cachetestutils.DumpNormalizedYAML(userstestutils.GetManagerCache(m))
require.NoError(t, err, "Setup: failed to dump database for comparing")
wantDB := testutils.LoadWithUpdateFromGolden(t, gotDB, testutils.WithGoldenPath(filepath.Join(testutils.GoldenPath(t), "cache.db")))
require.Equal(t, wantDB, gotDB, "IsAuthenticated should update the cache database as expected")
Expand Down Expand Up @@ -571,7 +571,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 := cachetestutils.DumpToYaml(userstestutils.GetManagerCache(m))
gotDB, err := cachetestutils.DumpNormalizedYAML(userstestutils.GetManagerCache(m))
require.NoError(t, err, "Setup: failed to dump database for comparing")
wantDB := testutils.LoadWithUpdateFromGolden(t, gotDB, testutils.WithGoldenPath(filepath.Join(testutils.GoldenPath(t), "cache.db")))
require.Equal(t, wantDB, gotDB, "IsAuthenticated should update the cache database as expected")
Expand Down Expand Up @@ -631,7 +631,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 := cachetestutils.DumpToYaml(userstestutils.GetManagerCache(m))
gotDB, err := cachetestutils.DumpNormalizedYAML(userstestutils.GetManagerCache(m))
require.NoError(t, err, "Setup: failed to dump database for comparing")
wantDB := testutils.LoadWithUpdateFromGolden(t, gotDB, testutils.WithGoldenPath(filepath.Join(testutils.GoldenPath(t), "cache.db")))
require.Equal(t, wantDB, gotDB, "SetDefaultBrokerForUser should update the cache database as expected")
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 @@ -75,7 +75,7 @@ func TestNew(t *testing.T) {
require.NoError(t, err)
defer c.Close()

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

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

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

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

got, err := cachetestutils.DumpToYaml(c)
got, err := cachetestutils.DumpNormalizedYAML(c)
require.NoError(t, err, "Created database should be valid yaml content")
want := testutils.LoadWithUpdateFromGolden(t, got)
require.Equal(t, want, got, "Did not get expected database content")
Expand Down
5 changes: 3 additions & 2 deletions internal/users/cache/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ func redactTime(line string) string {
return line
}

// dumpToYaml deserializes the cache database as a string in yaml format.
// dumpNormalizedYAML gets the content of the database, normalizes it (so that
// it can be compared with a golden file) and returns it as a YAML string.
//
//nolint:unused // This is used for tests, with go linking. Not part of exported API.
adombeck marked this conversation as resolved.
Show resolved Hide resolved
func (c *Cache) dumpToYaml() (string, error) {
func (c *Cache) dumpNormalizedYAML() (string, error) {
testsdetection.MustBeTesting()

d := make(map[string]map[string]string)
Expand Down
7 changes: 4 additions & 3 deletions internal/users/cache/testutils/serialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ var (
DbName string
)

// DumpToYaml deserializes the cache database as a string in yaml format.
// DumpNormalizedYAML gets the content of the database, normalizes it (so that
// it can be compared with a golden file) and returns it as a YAML string.
//
//go:linkname DumpToYaml github.com/ubuntu/authd/internal/users/cache.(*Cache).dumpToYaml
func DumpToYaml(c *cache.Cache) (string, error)
//go:linkname DumpNormalizedYAML github.com/ubuntu/authd/internal/users/cache.(*Cache).dumpNormalizedYAML
func DumpNormalizedYAML(c *cache.Cache) (string, error)

// DbfromYAML loads a yaml formatted of the buckets from a reader and dump it into destDir, with its dbname.
//
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 @@ -76,7 +76,7 @@ func TestNewManager(t *testing.T) {
}
require.NoError(t, err, "NewManager should not return an error, but did")

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

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

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

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

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

want := testutils.LoadWithUpdateFromGoldenYAML(t, got)
Expand Down
Loading