@@ -2205,4 +2205,321 @@ func TestAddPack(t *testing.T) {
22052205 assert .Nil (err )
22062206 checkPackIsInstalled (t , packInfoToType (packInfo ))
22072207 })
2208+
2209+ // Tests with CreatePackRoot = false (no automatic directory creation)
2210+
2211+ t .Run ("test installing a pack with non-existent pack directory" , func (t * testing.T ) {
2212+ localTestingDir := "test-add-pack-non-existent-directory"
2213+ // Do NOT create the pack root directory
2214+ err := installer .SetPackRoot (localTestingDir , ! CreatePackRoot )
2215+
2216+ // Should fail because pack root doesn't exist
2217+ assert .NotNil (err )
2218+ assert .Equal (errs .ErrPackRootDoesNotExist , err )
2219+ })
2220+
2221+ t .Run ("test installing a pack with empty pack directory" , func (t * testing.T ) {
2222+ localTestingDir := "test-add-pack-empty-directory"
2223+ // Create pack root but don't create subdirectories
2224+ assert .Nil (os .Mkdir (localTestingDir , 0700 ))
2225+ defer removePackRoot (localTestingDir )
2226+
2227+ err := installer .SetPackRoot (localTestingDir , ! CreatePackRoot )
2228+
2229+ // Should fail because subdirectories (.Web, .Download, .Local) are missing
2230+ assert .NotNil (err )
2231+ assert .Equal (errs .ErrAlreadyLogged , err )
2232+ })
2233+
2234+ t .Run ("test installing a pack with partially initialized pack directory - missing .Web" , func (t * testing.T ) {
2235+ localTestingDir := "test-add-pack-partial-directory-no-web"
2236+ // Create pack root and some subdirectories, but not all
2237+ assert .Nil (os .Mkdir (localTestingDir , 0700 ))
2238+ assert .Nil (os .Mkdir (filepath .Join (localTestingDir , ".Download" ), 0700 ))
2239+ assert .Nil (os .Mkdir (filepath .Join (localTestingDir , ".Local" ), 0700 ))
2240+ // .Web is missing
2241+ defer removePackRoot (localTestingDir )
2242+
2243+ err := installer .SetPackRoot (localTestingDir , ! CreatePackRoot )
2244+
2245+ // Should fail because .Web subdirectory is missing
2246+ assert .NotNil (err )
2247+ assert .Equal (errs .ErrAlreadyLogged , err )
2248+ })
2249+
2250+ t .Run ("test installing a pack with partially initialized pack directory - missing .Download" , func (t * testing.T ) {
2251+ localTestingDir := "test-add-pack-partial-directory-no-download"
2252+ // Create pack root and some subdirectories, but not all
2253+ assert .Nil (os .Mkdir (localTestingDir , 0700 ))
2254+ assert .Nil (os .Mkdir (filepath .Join (localTestingDir , ".Web" ), 0700 ))
2255+ assert .Nil (os .Mkdir (filepath .Join (localTestingDir , ".Local" ), 0700 ))
2256+ // .Download is missing
2257+ defer removePackRoot (localTestingDir )
2258+
2259+ err := installer .SetPackRoot (localTestingDir , ! CreatePackRoot )
2260+
2261+ // Should fail because .Download subdirectory is missing
2262+ assert .NotNil (err )
2263+ assert .Equal (errs .ErrAlreadyLogged , err )
2264+ })
2265+
2266+ t .Run ("test installing a pack with partially initialized pack directory - missing .Local" , func (t * testing.T ) {
2267+ localTestingDir := "test-add-pack-partial-directory-no-local"
2268+ // Create pack root and some subdirectories, but not all
2269+ assert .Nil (os .Mkdir (localTestingDir , 0700 ))
2270+ assert .Nil (os .Mkdir (filepath .Join (localTestingDir , ".Web" ), 0700 ))
2271+ assert .Nil (os .Mkdir (filepath .Join (localTestingDir , ".Download" ), 0700 ))
2272+ // .Local is missing
2273+ defer removePackRoot (localTestingDir )
2274+
2275+ err := installer .SetPackRoot (localTestingDir , ! CreatePackRoot )
2276+
2277+ // Should fail because .Local subdirectory is missing
2278+ assert .NotNil (err )
2279+ assert .Equal (errs .ErrAlreadyLogged , err )
2280+ })
2281+
2282+ t .Run ("test installing a pack with partially initialized pack directory - only .Web exists" , func (t * testing.T ) {
2283+ localTestingDir := "test-add-pack-partial-directory-only-web"
2284+ // Create pack root and only .Web subdirectory
2285+ assert .Nil (os .Mkdir (localTestingDir , 0700 ))
2286+ assert .Nil (os .Mkdir (filepath .Join (localTestingDir , ".Web" ), 0700 ))
2287+ // .Download and .Local are missing
2288+ defer removePackRoot (localTestingDir )
2289+
2290+ err := installer .SetPackRoot (localTestingDir , ! CreatePackRoot )
2291+
2292+ // Should fail because .Download and .Local subdirectories are missing
2293+ assert .NotNil (err )
2294+ assert .Equal (errs .ErrAlreadyLogged , err )
2295+ })
2296+
2297+ t .Run ("test installing a pack with fully initialized pack directory" , func (t * testing.T ) {
2298+ localTestingDir := "test-add-pack-fully-initialized-directory"
2299+ // Create pack root and all required subdirectories
2300+ assert .Nil (os .Mkdir (localTestingDir , 0700 ))
2301+ assert .Nil (os .Mkdir (filepath .Join (localTestingDir , ".Web" ), 0700 ))
2302+ assert .Nil (os .Mkdir (filepath .Join (localTestingDir , ".Download" ), 0700 ))
2303+ assert .Nil (os .Mkdir (filepath .Join (localTestingDir , ".Local" ), 0700 ))
2304+ defer removePackRoot (localTestingDir )
2305+
2306+ err := installer .SetPackRoot (localTestingDir , ! CreatePackRoot )
2307+
2308+ // Should succeed because all required subdirectories exist
2309+ assert .Nil (err )
2310+ installer .UnlockPackRoot ()
2311+ assert .Nil (installer .ReadIndexFiles ())
2312+
2313+ // Now try installing a pack
2314+ packPath := publicLocalPack123
2315+ err = installer .AddPack (packPath , ! CheckEula , ! ExtractEula , ! ForceReinstall , ! NoRequirements , true , Timeout )
2316+ assert .Nil (err )
2317+
2318+ packInfo , err := utils .ExtractPackInfo (packPath )
2319+ assert .Nil (err )
2320+ checkPackIsInstalled (t , packInfoToType (packInfo ))
2321+ })
2322+
2323+ // Tests with CreatePackRoot = true (automatic directory creation)
2324+
2325+ t .Run ("test installing a pack with non-existent pack directory with CreatePackRoot" , func (t * testing.T ) {
2326+ localTestingDir := "test-add-pack-non-existent-directory-create"
2327+ defer removePackRoot (localTestingDir )
2328+
2329+ // Should succeed and create all necessary directories
2330+ err := installer .SetPackRoot (localTestingDir , CreatePackRoot )
2331+ assert .Nil (err )
2332+
2333+ // Verify that all subdirectories were created
2334+ assert .DirExists (localTestingDir )
2335+ assert .DirExists (filepath .Join (localTestingDir , ".Web" ))
2336+ assert .DirExists (filepath .Join (localTestingDir , ".Download" ))
2337+ assert .DirExists (filepath .Join (localTestingDir , ".Local" ))
2338+
2339+ installer .UnlockPackRoot ()
2340+ assert .Nil (installer .ReadIndexFiles ())
2341+
2342+ // Verify that index files were created
2343+ assert .FileExists (filepath .Join (localTestingDir , ".Local" , "local_repository.pidx" ))
2344+ assert .FileExists (filepath .Join (localTestingDir , ".Web" , "cache.pidx" ))
2345+ assert .FileExists (filepath .Join (localTestingDir , ".Web" , "index.pidx" ))
2346+
2347+ // Now try installing a pack
2348+ packPath := publicLocalPack123
2349+ err = installer .AddPack (packPath , ! CheckEula , ! ExtractEula , ! ForceReinstall , ! NoRequirements , true , Timeout )
2350+ assert .Nil (err )
2351+
2352+ packInfo , err := utils .ExtractPackInfo (packPath )
2353+ assert .Nil (err )
2354+ checkPackIsInstalled (t , packInfoToType (packInfo ))
2355+ })
2356+
2357+ t .Run ("test installing a pack with empty pack directory with CreatePackRoot" , func (t * testing.T ) {
2358+ localTestingDir := "test-add-pack-empty-directory-create"
2359+ // Create pack root but don't create subdirectories
2360+ assert .Nil (os .Mkdir (localTestingDir , 0700 ))
2361+ defer removePackRoot (localTestingDir )
2362+
2363+ // Should succeed and create missing subdirectories
2364+ err := installer .SetPackRoot (localTestingDir , CreatePackRoot )
2365+ assert .Nil (err )
2366+
2367+ // Verify that all subdirectories were created
2368+ assert .DirExists (filepath .Join (localTestingDir , ".Web" ))
2369+ assert .DirExists (filepath .Join (localTestingDir , ".Download" ))
2370+ assert .DirExists (filepath .Join (localTestingDir , ".Local" ))
2371+
2372+ installer .UnlockPackRoot ()
2373+ assert .Nil (installer .ReadIndexFiles ())
2374+
2375+ // Verify that index files were created
2376+ assert .FileExists (filepath .Join (localTestingDir , ".Local" , "local_repository.pidx" ))
2377+ assert .FileExists (filepath .Join (localTestingDir , ".Web" , "cache.pidx" ))
2378+ assert .FileExists (filepath .Join (localTestingDir , ".Web" , "index.pidx" ))
2379+
2380+ // Now try installing a pack
2381+ packPath := publicLocalPack123
2382+ err = installer .AddPack (packPath , ! CheckEula , ! ExtractEula , ! ForceReinstall , ! NoRequirements , true , Timeout )
2383+ assert .Nil (err )
2384+
2385+ packInfo , err := utils .ExtractPackInfo (packPath )
2386+ assert .Nil (err )
2387+ checkPackIsInstalled (t , packInfoToType (packInfo ))
2388+ })
2389+
2390+ t .Run ("test installing a pack with partially initialized pack directory - missing .Web with CreatePackRoot" , func (t * testing.T ) {
2391+ localTestingDir := "test-add-pack-partial-directory-no-web-create"
2392+ // Create pack root and some subdirectories, but not all
2393+ assert .Nil (os .Mkdir (localTestingDir , 0700 ))
2394+ assert .Nil (os .Mkdir (filepath .Join (localTestingDir , ".Download" ), 0700 ))
2395+ assert .Nil (os .Mkdir (filepath .Join (localTestingDir , ".Local" ), 0700 ))
2396+ // .Web is missing
2397+ defer removePackRoot (localTestingDir )
2398+
2399+ // Should succeed and create missing .Web subdirectory
2400+ err := installer .SetPackRoot (localTestingDir , CreatePackRoot )
2401+ assert .Nil (err )
2402+
2403+ // Verify that .Web was created
2404+ assert .DirExists (filepath .Join (localTestingDir , ".Web" ))
2405+
2406+ installer .UnlockPackRoot ()
2407+ assert .Nil (installer .ReadIndexFiles ())
2408+
2409+ // Verify that index files were created
2410+ assert .FileExists (filepath .Join (localTestingDir , ".Local" , "local_repository.pidx" ))
2411+ assert .FileExists (filepath .Join (localTestingDir , ".Web" , "cache.pidx" ))
2412+ assert .FileExists (filepath .Join (localTestingDir , ".Web" , "index.pidx" ))
2413+
2414+ // Now try installing a pack
2415+ packPath := publicLocalPack123
2416+ err = installer .AddPack (packPath , ! CheckEula , ! ExtractEula , ! ForceReinstall , ! NoRequirements , true , Timeout )
2417+ assert .Nil (err )
2418+
2419+ packInfo , err := utils .ExtractPackInfo (packPath )
2420+ assert .Nil (err )
2421+ checkPackIsInstalled (t , packInfoToType (packInfo ))
2422+ })
2423+
2424+ t .Run ("test installing a pack with partially initialized pack directory - missing .Download with CreatePackRoot" , func (t * testing.T ) {
2425+ localTestingDir := "test-add-pack-partial-directory-no-download-create"
2426+ // Create pack root and some subdirectories, but not all
2427+ assert .Nil (os .Mkdir (localTestingDir , 0700 ))
2428+ assert .Nil (os .Mkdir (filepath .Join (localTestingDir , ".Web" ), 0700 ))
2429+ assert .Nil (os .Mkdir (filepath .Join (localTestingDir , ".Local" ), 0700 ))
2430+ // .Download is missing
2431+ defer removePackRoot (localTestingDir )
2432+
2433+ // Should succeed and create missing .Download subdirectory
2434+ err := installer .SetPackRoot (localTestingDir , CreatePackRoot )
2435+ assert .Nil (err )
2436+
2437+ // Verify that .Download was created
2438+ assert .DirExists (filepath .Join (localTestingDir , ".Download" ))
2439+
2440+ installer .UnlockPackRoot ()
2441+ assert .Nil (installer .ReadIndexFiles ())
2442+
2443+ // Verify that index files were created
2444+ assert .FileExists (filepath .Join (localTestingDir , ".Local" , "local_repository.pidx" ))
2445+ assert .FileExists (filepath .Join (localTestingDir , ".Web" , "cache.pidx" ))
2446+ assert .FileExists (filepath .Join (localTestingDir , ".Web" , "index.pidx" ))
2447+
2448+ // Now try installing a pack
2449+ packPath := publicLocalPack123
2450+ err = installer .AddPack (packPath , ! CheckEula , ! ExtractEula , ! ForceReinstall , ! NoRequirements , true , Timeout )
2451+ assert .Nil (err )
2452+
2453+ packInfo , err := utils .ExtractPackInfo (packPath )
2454+ assert .Nil (err )
2455+ checkPackIsInstalled (t , packInfoToType (packInfo ))
2456+ })
2457+
2458+ t .Run ("test installing a pack with partially initialized pack directory - missing .Local with CreatePackRoot" , func (t * testing.T ) {
2459+ localTestingDir := "test-add-pack-partial-directory-no-local-create"
2460+ // Create pack root and some subdirectories, but not all
2461+ assert .Nil (os .Mkdir (localTestingDir , 0700 ))
2462+ assert .Nil (os .Mkdir (filepath .Join (localTestingDir , ".Web" ), 0700 ))
2463+ assert .Nil (os .Mkdir (filepath .Join (localTestingDir , ".Download" ), 0700 ))
2464+ // .Local is missing
2465+ defer removePackRoot (localTestingDir )
2466+
2467+ // Should succeed and create missing .Local subdirectory
2468+ err := installer .SetPackRoot (localTestingDir , CreatePackRoot )
2469+ assert .Nil (err )
2470+
2471+ // Verify that .Local was created
2472+ assert .DirExists (filepath .Join (localTestingDir , ".Local" ))
2473+
2474+ installer .UnlockPackRoot ()
2475+ assert .Nil (installer .ReadIndexFiles ())
2476+
2477+ // Verify that index files were created
2478+ assert .FileExists (filepath .Join (localTestingDir , ".Local" , "local_repository.pidx" ))
2479+ assert .FileExists (filepath .Join (localTestingDir , ".Web" , "cache.pidx" ))
2480+ assert .FileExists (filepath .Join (localTestingDir , ".Web" , "index.pidx" ))
2481+
2482+ // Now try installing a pack
2483+ packPath := publicLocalPack123
2484+ err = installer .AddPack (packPath , ! CheckEula , ! ExtractEula , ! ForceReinstall , ! NoRequirements , true , Timeout )
2485+ assert .Nil (err )
2486+
2487+ packInfo , err := utils .ExtractPackInfo (packPath )
2488+ assert .Nil (err )
2489+ checkPackIsInstalled (t , packInfoToType (packInfo ))
2490+ })
2491+
2492+ t .Run ("test installing a pack with partially initialized pack directory - only .Web exists with CreatePackRoot" , func (t * testing.T ) {
2493+ localTestingDir := "test-add-pack-partial-directory-only-web-create"
2494+ // Create pack root and only .Web subdirectory
2495+ assert .Nil (os .Mkdir (localTestingDir , 0700 ))
2496+ assert .Nil (os .Mkdir (filepath .Join (localTestingDir , ".Web" ), 0700 ))
2497+ // .Download and .Local are missing
2498+ defer removePackRoot (localTestingDir )
2499+
2500+ // Should succeed and create missing subdirectories
2501+ err := installer .SetPackRoot (localTestingDir , CreatePackRoot )
2502+ assert .Nil (err )
2503+
2504+ // Verify that missing subdirectories were created
2505+ assert .DirExists (filepath .Join (localTestingDir , ".Download" ))
2506+ assert .DirExists (filepath .Join (localTestingDir , ".Local" ))
2507+
2508+ installer .UnlockPackRoot ()
2509+ assert .Nil (installer .ReadIndexFiles ())
2510+
2511+ // Verify that index files were created
2512+ assert .FileExists (filepath .Join (localTestingDir , ".Local" , "local_repository.pidx" ))
2513+ assert .FileExists (filepath .Join (localTestingDir , ".Web" , "cache.pidx" ))
2514+ assert .FileExists (filepath .Join (localTestingDir , ".Web" , "index.pidx" ))
2515+
2516+ // Now try installing a pack
2517+ packPath := publicLocalPack123
2518+ err = installer .AddPack (packPath , ! CheckEula , ! ExtractEula , ! ForceReinstall , ! NoRequirements , true , Timeout )
2519+ assert .Nil (err )
2520+
2521+ packInfo , err := utils .ExtractPackInfo (packPath )
2522+ assert .Nil (err )
2523+ checkPackIsInstalled (t , packInfoToType (packInfo ))
2524+ })
22082525}
0 commit comments