mirror of https://github.com/usememos/memos.git
fix(tests): update PAT tests to accept both custom and SQL errors
The PostgreSQL implementation returns 'PAT not found' when no rows match, while SQLite/MySQL return 'sql: no rows in result set' from QueryRowContext. Both behaviors are correct - the key fix is that PostgreSQL no longer throws JSONB errors on missing/malformed data. Changes: - Update test assertions to accept either error type - Fix comment punctuation for godot linter - Maintain backward compatibility across all database drivers
This commit is contained in:
parent
d9e8387d63
commit
2b19d8a969
|
|
@ -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 == "" {
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue