@@ -23,11 +23,15 @@ func getTestDir(subDir string) string {
2323 return testDir
2424}
2525
26- func testOciDownloader (t * testing.T ) {
27- path_oci := getTestDir ("test_oci" )
28- if err := os .MkdirAll (path_oci , os .ModePerm ); err != nil {
26+ func makeDir (t * testing.T , path string ) {
27+ if err := os .MkdirAll (path , os .ModePerm ); err != nil {
2928 t .Fatal (err )
3029 }
30+ }
31+
32+ func testOciDownloader (t * testing.T ) {
33+ path_oci := getTestDir ("test_oci" )
34+ makeDir (t , path_oci )
3135
3236 defer func () {
3337 _ = os .RemoveAll (path_oci )
@@ -54,9 +58,7 @@ func testOciDownloader(t *testing.T) {
5458func testGitDownloader (t * testing.T ) {
5559 features .Enable (features .SupportNewStorage )
5660 path_git := getTestDir ("test_git_bare_repo" )
57- if err := os .MkdirAll (path_git , os .ModePerm ); err != nil {
58- t .Fatal (err )
59- }
61+ makeDir (t , path_git )
6062
6163 defer func () {
6264 _ = os .RemoveAll (path_git )
@@ -86,7 +88,46 @@ func testGitDownloader(t *testing.T) {
8688 assert .Equal (t , utils .DirExists (filepath .Join (path_git , "git" , "src" , gitHash , "kcl.mod" )), true )
8789}
8890
91+ func testDepDownloaderWhenPackageCacheFolderExistsButEmpty (t * testing.T ) {
92+ path_tmp := getTestDir ("test_dep_downloader" )
93+ makeDir (t , path_tmp )
94+ defer func () {
95+ _ = os .RemoveAll (path_tmp )
96+ }()
97+
98+ path_local := filepath .Join (path_tmp , "package_local" )
99+ makeDir (t , path_local )
100+ path_cache := filepath .Join (path_tmp , "package_cache" )
101+ makeDir (t , path_cache )
102+
103+ depDownloader := DepDownloader {
104+ OciDownloader : & OciDownloader {
105+ Platform : "linux/amd64" ,
106+ },
107+ }
108+
109+ err := depDownloader .Download (NewDownloadOptions (
110+ WithSource (Source {
111+ Oci : & Oci {
112+ Reg : "ghcr.io" ,
113+ Repo : "zong-zhe/helloworld" ,
114+ Tag : "0.0.3" ,
115+ },
116+ }),
117+ WithLocalPath (path_local ),
118+ WithCachePath (path_cache ),
119+ WithEnableCache (true ),
120+ ))
121+
122+ assert .Equal (t , err , nil )
123+ existFile , err := utils .Exists (path_local + "/kcl.mod" )
124+ assert .NilError (t , err )
125+ assert .Check (t , existFile )
126+ }
127+
89128func TestWithGlobalLock (t * testing.T ) {
90129 test .RunTestWithGlobalLock (t , "TestOciDownloader" , testOciDownloader )
91130 test .RunTestWithGlobalLock (t , "TestGitDownloader" , testGitDownloader )
131+ test .RunTestWithGlobalLock (t , "TestDepDownloaderWhenPackageCacheFolderExistsButEmpty" ,
132+ testDepDownloaderWhenPackageCacheFolderExistsButEmpty )
92133}
0 commit comments