@@ -84,3 +84,101 @@ func TestLfsMetaStore_CRUD(t *testing.T) {
8484 require .NotNil (t , err )
8585
8686}
87+
88+ func TestLfsMetaStore_UpdateXnetUsed (t * testing.T ) {
89+ db := tests .InitTestDB ()
90+ defer db .Close ()
91+ ctx := context .TODO ()
92+
93+ store := database .NewLfsMetaObjectStoreWithDB (db )
94+
95+ // Create a test LFS object
96+ _ , err := store .Create (ctx , database.LfsMetaObject {
97+ RepositoryID : 123 ,
98+ Oid : "test-oid-123" ,
99+ Size : 1024 ,
100+ XnetUsed : false ,
101+ })
102+ require .Nil (t , err )
103+
104+ // Verify initial state
105+ obj , err := store .FindByOID (ctx , 123 , "test-oid-123" )
106+ require .Nil (t , err )
107+ require .Equal (t , "test-oid-123" , obj .Oid )
108+ require .Equal (t , false , obj .XnetUsed )
109+
110+ // Update XnetUsed to true
111+ err = store .UpdateXnetUsed (ctx , 123 , "test-oid-123" , true )
112+ require .Nil (t , err )
113+
114+ // Verify update
115+ obj , err = store .FindByOID (ctx , 123 , "test-oid-123" )
116+ require .Nil (t , err )
117+ require .Equal (t , true , obj .XnetUsed )
118+
119+ // Update XnetUsed back to false
120+ err = store .UpdateXnetUsed (ctx , 123 , "test-oid-123" , false )
121+ require .Nil (t , err )
122+
123+ // Verify update
124+ obj , err = store .FindByOID (ctx , 123 , "test-oid-123" )
125+ require .Nil (t , err )
126+ require .Equal (t , false , obj .XnetUsed )
127+
128+ // Test updating non-existent object (should not error but affect 0 rows)
129+ err = store .UpdateXnetUsed (ctx , 999 , "non-existent-oid" , true )
130+ require .Nil (t , err )
131+ }
132+
133+ func TestLfsMetaStore_CheckIfAllMigratedToXnet (t * testing.T ) {
134+ db := tests .InitTestDB ()
135+ defer db .Close ()
136+ ctx := context .TODO ()
137+
138+ store := database .NewLfsMetaObjectStoreWithDB (db )
139+
140+ // Test with no objects
141+ allMigrated , err := store .CheckIfAllMigratedToXnet (ctx , 123 )
142+ require .Nil (t , err )
143+ require .True (t , allMigrated , "No objects should return true" )
144+
145+ // Create test objects
146+ testCases := []database.LfsMetaObject {
147+ {RepositoryID : 123 , Oid : "oid-1" , Size : 1024 , XnetUsed : false },
148+ {RepositoryID : 123 , Oid : "oid-2" , Size : 2048 , XnetUsed : false },
149+ {RepositoryID : 456 , Oid : "oid-3" , Size : 3072 , XnetUsed : true }, // Different repo
150+ }
151+
152+ for _ , tc := range testCases {
153+ _ , err := store .Create (ctx , tc )
154+ require .Nil (t , err )
155+ }
156+
157+ // Test with some objects not migrated
158+ allMigrated , err = store .CheckIfAllMigratedToXnet (ctx , 123 )
159+ require .Nil (t , err )
160+ require .False (t , allMigrated , "Should return false when some objects are not migrated" )
161+
162+ // Test with all objects migrated in another repo
163+ allMigrated , err = store .CheckIfAllMigratedToXnet (ctx , 456 )
164+ require .Nil (t , err )
165+ require .True (t , allMigrated , "Should return true when all objects are migrated" )
166+
167+ // Update one object to migrated
168+ err = store .UpdateXnetUsed (ctx , 123 , "oid-1" , true )
169+ require .Nil (t , err )
170+
171+ // Test with one migrated, one not migrated
172+ allMigrated , err = store .CheckIfAllMigratedToXnet (ctx , 123 )
173+ require .Nil (t , err )
174+ require .False (t , allMigrated , "Should return false when not all objects are migrated" )
175+
176+ // Update all objects to migrated
177+ err = store .UpdateXnetUsed (ctx , 123 , "oid-2" , true )
178+ require .Nil (t , err )
179+
180+ // Test with all objects migrated
181+ allMigrated , err = store .CheckIfAllMigratedToXnet (ctx , 123 )
182+ require .Nil (t , err )
183+ require .True (t , allMigrated , "Should return true when all objects are migrated" )
184+ }
0 commit comments