From c4dc849b3c7c55f89ce877509ad6a524742a505f Mon Sep 17 00:00:00 2001 From: Djalal Harouni Date: Fri, 17 May 2024 18:39:07 +0100 Subject: [PATCH] test: test userdb lookup Signed-off-by: Djalal Harouni --- pkg/reader/userdb/userdb_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 pkg/reader/userdb/userdb_test.go diff --git a/pkg/reader/userdb/userdb_test.go b/pkg/reader/userdb/userdb_test.go new file mode 100644 index 00000000000..5ec9d7220fe --- /dev/null +++ b/pkg/reader/userdb/userdb_test.go @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Authors of Tetragon +// +// Lookup users from /etc/passwd + +package userdb + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestUsersRecords(t *testing.T) { + name, err := UsersCache.lookupUser(0) + assert.Error(t, err) + assert.Empty(t, name) + + UsersCache.addUser(0, "root") + name, err = UsersCache.lookupUser(0) + assert.NoError(t, err) + assert.Equal(t, "root", name) + + name, err = UsersCache.LookupUser(2) + assert.NoError(t, err) + name2, err := UsersCache.lookupUser(2) + assert.NoError(t, err) + assert.Equal(t, name, name2) +}