99 v1pb "github.com/usememos/memos/proto/gen/api/v1"
1010)
1111
12- func TestInstanceOwnerCache (t * testing.T ) {
12+ func TestInstanceAdminRetrieval (t * testing.T ) {
1313 ctx := context .Background ()
1414
1515 t .Run ("Instance becomes initialized after first admin user is created" , func (t * testing.T ) {
@@ -20,7 +20,7 @@ func TestInstanceOwnerCache(t *testing.T) {
2020 // Verify instance is not initialized initially
2121 profile1 , err := ts .Service .GetInstanceProfile (ctx , & v1pb.GetInstanceProfileRequest {})
2222 require .NoError (t , err )
23- require .False (t , profile1 .Initialized , "Instance should not be initialized before first admin user" )
23+ require .Nil (t , profile1 .Admin , "Instance should not be initialized before first admin user" )
2424
2525 // Create the first admin user
2626 user , err := ts .CreateHostUser (ctx , "admin" )
@@ -30,29 +30,25 @@ func TestInstanceOwnerCache(t *testing.T) {
3030 // Verify instance is now initialized
3131 profile2 , err := ts .Service .GetInstanceProfile (ctx , & v1pb.GetInstanceProfileRequest {})
3232 require .NoError (t , err )
33- require .True (t , profile2 .Initialized , "Instance should be initialized after first admin user is created" )
33+ require .NotNil (t , profile2 .Admin , "Instance should be initialized after first admin user is created" )
34+ require .Equal (t , user .Username , profile2 .Admin .Username )
3435 })
3536
36- t .Run ("ClearInstanceOwnerCache works correctly " , func (t * testing.T ) {
37+ t .Run ("Admin retrieval is cached by Store layer " , func (t * testing.T ) {
3738 // Create test service
3839 ts := NewTestService (t )
3940 defer ts .Cleanup ()
4041
4142 // Create admin user
42- _ , err := ts .CreateHostUser (ctx , "admin" )
43- require .NoError (t , err )
44-
45- // Verify initialized
46- profile1 , err := ts .Service .GetInstanceProfile (ctx , & v1pb.GetInstanceProfileRequest {})
43+ user , err := ts .CreateHostUser (ctx , "admin" )
4744 require .NoError (t , err )
48- require .True (t , profile1 .Initialized )
4945
50- // Clear cache
51- ts . Service . ClearInstanceOwnerCache ()
52-
53- // Should still be initialized (cache is refilled from DB )
54- profile2 , err := ts . Service . GetInstanceProfile ( ctx , & v1pb. GetInstanceProfileRequest {} )
55- require .NoError (t , err )
56- require . True ( t , profile2 . Initialized )
46+ // Multiple calls should return consistent admin user (from cache)
47+ for i := 0 ; i < 5 ; i ++ {
48+ profile , err := ts . Service . GetInstanceProfile ( ctx , & v1pb. GetInstanceProfileRequest {})
49+ require . NoError ( t , err )
50+ require . NotNil ( t , profile . Admin )
51+ require .Equal (t , user . Username , profile . Admin . Username )
52+ }
5753 })
5854}
0 commit comments