kcl-lang.io/kpm@v0.8.7-0.20240520061008-9fc4c5efc8c7/pkg/downloader/downloader_test.go (about) 1 package downloader 2 3 import ( 4 "os" 5 "path/filepath" 6 "testing" 7 8 "gotest.tools/v3/assert" 9 pkg "kcl-lang.io/kpm/pkg/package" 10 "kcl-lang.io/kpm/pkg/utils" 11 ) 12 13 const testDataDir = "test_data" 14 15 func getTestDir(subDir string) string { 16 pwd, _ := os.Getwd() 17 testDir := filepath.Join(pwd, testDataDir) 18 testDir = filepath.Join(testDir, subDir) 19 20 return testDir 21 } 22 23 func TestOciDownloader(t *testing.T) { 24 path := getTestDir("test_oci") 25 26 defer func() { 27 _ = os.RemoveAll(path) 28 }() 29 30 ociDownloader := OciDownloader{ 31 Platform: "linux/amd64", 32 } 33 34 err := ociDownloader.Download(*NewDownloadOptions( 35 WithSource(pkg.Source{ 36 Oci: &pkg.Oci{ 37 Reg: "ghcr.io", 38 Repo: "zong-zhe/helloworld", 39 Tag: "0.0.3", 40 }, 41 }), 42 WithLocalPath(path), 43 )) 44 45 assert.Equal(t, err, nil) 46 assert.Equal(t, true, utils.DirExists(filepath.Join(path, "artifact.tgz"))) 47 }