コード例 #1
0
ファイル: bintray_test.go プロジェクト: JFrogDev/jfrog-cli-go
func TestBintrayVersionDownloads(t *testing.T) {
	initBintrayTest(t)

	repositoryPath := bintrayConfig.User + "/" + tests.BintrayRepo1
	packagePath := repositoryPath + "/" + tests.BintrayUploadTestPackageName
	versionPath := packagePath + "/" + tests.BintrayUploadTestVersion
	createPackageAndVersion(packagePath, versionPath)

	bintrayCli.Exec("upload", tests.GetTestResourcesPath()+"a/*", versionPath, "--flat=true --recursive=true")
	bintrayCli.Exec("download-ver", versionPath, tests.Out+"/bintray/", "--unpublished=true")

	paths, _ := ioutils.ListFilesRecursive(tests.Out + "/bintray/")
	expected := []string{
		tests.Out + ioutils.GetFileSeperator() + "bintray" + ioutils.GetFileSeperator() + "a1.in",
		tests.Out + ioutils.GetFileSeperator() + "bintray" + ioutils.GetFileSeperator() + "a2.in",
		tests.Out + ioutils.GetFileSeperator() + "bintray" + ioutils.GetFileSeperator() + "a3.in",
		tests.Out + ioutils.GetFileSeperator() + "bintray" + ioutils.GetFileSeperator() + "b1.in",
		tests.Out + ioutils.GetFileSeperator() + "bintray" + ioutils.GetFileSeperator() + "b2.in",
		tests.Out + ioutils.GetFileSeperator() + "bintray" + ioutils.GetFileSeperator() + "b3.in",
		tests.Out + ioutils.GetFileSeperator() + "bintray" + ioutils.GetFileSeperator() + "c1.in",
		tests.Out + ioutils.GetFileSeperator() + "bintray" + ioutils.GetFileSeperator() + "c2.in",
		tests.Out + ioutils.GetFileSeperator() + "bintray" + ioutils.GetFileSeperator() + "c3.in",
	}
	tests.IsExistLocally(expected, paths, t)
	bintrayCli.Exec("package-delete", packagePath, "--quiet=true")
	cleanBintrayTest()
}
コード例 #2
0
func TestArtifactoryMassiveDownloadSpec(t *testing.T) {
	initArtifactoryTest(t)
	prepUploadFiles()
	specFile := tests.GetFilePath(tests.DownloadSpec)
	artifactoryCli.Exec("download", "--spec="+specFile)

	paths, _ := ioutils.ListFilesRecursive(tests.Out + "/")
	tests.IsExistLocally(tests.MassiveDownload, paths, t)
	cleanArtifactoryTest()
}
コード例 #3
0
ファイル: upload.go プロジェクト: JFrogDev/jfrog-cli-go
func getFilesToUpload(localPath, targetPath, packageName string, flags *UploadFlags) ([]cliutils.Artifact, error) {
	var debianDefaultPath string
	if targetPath == "" && flags.Deb != "" {
		debianDefaultPath = getDebianDefaultPath(flags.Deb, packageName)
	}

	rootPath := cliutils.GetRootPathForUpload(localPath, flags.UseRegExp)
	if !ioutils.IsPathExists(rootPath) {
		err := cliutils.CheckError(errors.New("Path does not exist: " + rootPath))
		if err != nil {
			return nil, err
		}
	}
	localPath = cliutils.PrepareLocalPathForUpload(localPath, flags.UseRegExp)

	artifacts := []cliutils.Artifact{}
	// If the path is a single file then return it
	dir, err := ioutils.IsDir(rootPath)
	if err != nil {
		return nil, err
	}

	if !dir {
		artifact := getSingleFileToUpload(rootPath, targetPath, debianDefaultPath, flags.Flat)
		return append(artifacts, artifact), nil
	}

	r, err := regexp.Compile(localPath)
	err = cliutils.CheckError(err)
	if err != nil {
		return nil, err
	}

	spinner := cliutils.NewSpinner("[Info] Collecting files for upload:", time.Second)
	spinner.Start()
	var paths []string
	if flags.Recursive {
		paths, err = ioutils.ListFilesRecursive(rootPath)
	} else {
		paths, err = ioutils.ListFiles(rootPath)
	}
	if err != nil {
		return nil, err
	}

	for _, path := range paths {
		dir, err := ioutils.IsDir(path)
		if err != nil {
			return nil, err
		}
		if dir {
			continue
		}

		groups := r.FindStringSubmatch(path)
		size := len(groups)
		target := targetPath

		if size > 0 {
			for i := 1; i < size; i++ {
				group := strings.Replace(groups[i], "\\", "/", -1)
				target = strings.Replace(target, "{"+strconv.Itoa(i)+"}", group, -1)
			}

			if target == "" || strings.HasSuffix(target, "/") {
				if target == "" {
					target = debianDefaultPath
				}
				if flags.Flat {
					fileName, _ := ioutils.GetFileAndDirFromPath(path)
					target += fileName
				} else {
					uploadPath := cliutils.TrimPath(path)
					target += uploadPath
				}
			}

			artifacts = append(artifacts, cliutils.Artifact{path, target})
		}
	}
	spinner.Stop()
	return artifacts, nil
}