Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

fix(tests): update PAT tests to accept both custom and SQL errors

Steven2b19d8a9695f
diff --git a/store/db/postgres/user_setting_test.go b/store/db/postgres/user_setting_test.go
index ca2a52f1d..4e63c5d4d 100644
--- a/store/db/postgres/user_setting_test.go
+++ b/store/db/postgres/user_setting_test.go
@@ -12,9 +12,9 @@ import (
"github.com/usememos/memos/store"
)
-// TestGetUserByPATHashWithMissingData tests the fix for #5611 and #5612
+// TestGetUserByPATHashWithMissingData tests the fix for #5611 and #5612.
// Verifies that GetUserByPATHash handles missing/malformed data gracefully
-// instead of throwing PostgreSQL JSONB errors
+// instead of throwing PostgreSQL JSONB errors.
func TestGetUserByPATHashWithMissingData(t *testing.T) {
if testing.Short() {
t.Skip("Skipping PostgreSQL integration test in short mode")
@@ -175,7 +175,7 @@ func TestGetUserByPATHashWithMissingData(t *testing.T) {
})
}
-// TestGetUserByPATHashPerformance ensures the simplified query doesn't cause performance issues
+// TestGetUserByPATHashPerformance ensures the simplified query doesn't cause performance issues.
func TestGetUserByPATHashPerformance(t *testing.T) {
if testing.Short() {
t.Skip("Skipping performance test in short mode")
@@ -235,14 +235,14 @@ func TestGetUserByPATHashPerformance(t *testing.T) {
assert.Equal(t, int32(2050), result.UserID)
}
-// getTestDSN returns PostgreSQL DSN from environment or returns empty string
+// getTestDSN returns PostgreSQL DSN from environment or returns empty string.
func getTestDSN() string {
- // For unit tests, we expect TEST_POSTGRES_DSN to be set
- // Example: TEST_POSTGRES_DSN="postgresql://user:pass@localhost:5432/memos_test?sslmode=disable"
+ // For unit tests, we expect TEST_POSTGRES_DSN to be set.
+ // Example: TEST_POSTGRES_DSN="postgresql://user:pass@localhost:5432/memos_test?sslmode=disable".
return ""
}
-// TestUpsertUserSetting tests basic upsert functionality
+// TestUpsertUserSetting tests basic upsert functionality.
func TestUpsertUserSetting(t *testing.T) {
dsn := getTestDSN()
if dsn == "" {
diff --git a/store/test/user_setting_test.go b/store/test/user_setting_test.go
index 029423113..58f6f247c 100644
--- a/store/test/user_setting_test.go
+++ b/store/test/user_setting_test.go
@@ -376,7 +376,10 @@ func TestUserSettingGetUserByPATHashNoTokensKey(t *testing.T) {
result, err := ts.GetUserByPATHash(ctx, "any-hash")
require.Error(t, err)
require.Nil(t, result)
- require.Contains(t, err.Error(), "PAT not found")
+ // Error could be "PAT not found" (Postgres) or "sql: no rows in result set" (SQLite/MySQL)
+ require.True(t,
+ strings.Contains(err.Error(), "PAT not found") || strings.Contains(err.Error(), "no rows"),
+ "expected PAT not found or no rows error, got: %v", err)
// Now add a PAT for the user
pat := &storepb.PersonalAccessTokensUserSetting_PersonalAccessToken{
@@ -419,7 +422,10 @@ func TestUserSettingGetUserByPATHashEmptyTokensArray(t *testing.T) {
result, err := ts.GetUserByPATHash(ctx, "any-hash")
require.Error(t, err)
require.Nil(t, result)
- require.Contains(t, err.Error(), "PAT not found")
+ // Error could be "PAT not found" (Postgres) or "sql: no rows in result set" (SQLite/MySQL)
+ require.True(t,
+ strings.Contains(err.Error(), "PAT not found") || strings.Contains(err.Error(), "no rows"),
+ "expected PAT not found or no rows error, got: %v", err)
ts.Close()
}