Skip to content

Commit

Permalink
Win tests fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Gurevitch committed Feb 14, 2018
1 parent 65a0e4a commit 3516e84
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 37 deletions.
12 changes: 10 additions & 2 deletions jfrog-cli/artifactory/commands/gradle.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"path/filepath"
"runtime"
"strings"
"path"
)

const gradleExtractorDependencyVersion = "4.6.2"
Expand Down Expand Up @@ -49,7 +50,7 @@ func downloadGradleDependencies() (string, error) {
}

filename := "build-info-extractor-gradle-${version}-uber.jar"
downloadPath := filepath.Join("jfrog/jfrog-jars/org/jfrog/buildinfo/build-info-extractor-gradle/${version}/", filename)
downloadPath := path.Join("jfrog/jfrog-jars/org/jfrog/buildinfo/build-info-extractor-gradle/${version}/", filename)
err = utils.DownloadFromBintray(downloadPath, filename, gradleExtractorDependencyVersion, dependenciesPath)
if err != nil {
return "", err
Expand Down Expand Up @@ -98,7 +99,14 @@ func getInitScript(dependenciesPath string) (string, error) {
return initScript, nil
}

initScriptContent := strings.Replace(utils.GradleInitScript, "${pluginLibDir}", dependenciesPath, -1)
dependenciesPathFixed := strings.Replace(dependenciesPath, "\\", "\\\\", -1)
initScriptContent := strings.Replace(utils.GradleInitScript, "${pluginLibDir}", dependenciesPathFixed, -1)
if !fileutils.IsPathExists(dependenciesPath) {
err = os.MkdirAll(dependenciesPath, 0777)
if errorutils.CheckError(err) != nil {
return "", err
}
}
return initScript, errorutils.CheckError(ioutil.WriteFile(initScript, []byte(initScriptContent), 0644))
}

Expand Down
3 changes: 2 additions & 1 deletion jfrog-cli/artifactory/commands/mvn.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"os/exec"
"path/filepath"
"strings"
"path"
)

const MavenExtractorDependencyVersion = "2.9.2"
Expand Down Expand Up @@ -62,7 +63,7 @@ func downloadDependencies() (string, error) {
}

filename := "/build-info-extractor-maven3-${version}-uber.jar"
downloadPath := filepath.Join("jfrog/jfrog-jars/org/jfrog/buildinfo/build-info-extractor-maven3/${version}/", filename)
downloadPath := path.Join("jfrog/jfrog-jars/org/jfrog/buildinfo/build-info-extractor-maven3/${version}/", filename)
err = utils.DownloadFromBintray(downloadPath, filename, MavenExtractorDependencyVersion, dependenciesPath)
if err != nil {
return "", err
Expand Down
22 changes: 11 additions & 11 deletions jfrog-cli/jfrog/artifactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/jfrogdev/jfrog-cli-go/jfrog-cli/artifactory/commands"
"github.com/jfrogdev/jfrog-cli-go/jfrog-cli/artifactory/utils"
"github.com/jfrogdev/jfrog-cli-go/jfrog-cli/artifactory/utils/spec"
"github.com/jfrogdev/jfrog-cli-go/jfrog-cli/jfrog/inttestutils"
"github.com/jfrogdev/jfrog-cli-go/jfrog-cli/utils/cliutils"
"github.com/jfrogdev/jfrog-cli-go/jfrog-cli/utils/config"
"github.com/jfrogdev/jfrog-cli-go/jfrog-cli/utils/tests"
Expand Down Expand Up @@ -38,7 +39,6 @@ import (
"strings"
"testing"
"time"
"github.com/jfrogdev/jfrog-cli-go/jfrog-cli/jfrog/inttestutils"
)

var artifactoryCli *tests.JfrogCli
Expand Down Expand Up @@ -71,7 +71,7 @@ func authenticate() string {
cred += getArtifactoryTestCredentials()
var err error
if artAuth, err = artifactoryDetails.CreateArtAuthConfig(); err != nil {
cliutils.ExitOnErr(errors.New("Failed while attempting to authenticate with Artifactory: "+err.Error()))
cliutils.ExitOnErr(errors.New("Failed while attempting to authenticate with Artifactory: " + err.Error()))
}
artifactoryDetails.SshAuthHeaders = artAuth.GetSshAuthHeaders()
artifactoryDetails.Url = artAuth.GetUrl()
Expand Down Expand Up @@ -572,8 +572,8 @@ func checkIfServerIsUp(port, proxyScheme string) error {
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tr}
attempt := 0
for attempt < 10 {

for attempt := 0; attempt < 10; attempt++ {
log.Info("Checking if proxy server is up and running.", strconv.Itoa(attempt+1), "attempt.", "URL:", proxyScheme+"://localhost:"+port)
resp, err := client.Get(proxyScheme + "://localhost:" + port)
if err != nil {
Expand Down Expand Up @@ -686,8 +686,8 @@ func TestArtifactoryUploadFromHomeDir(t *testing.T) {
}

func createFileInHomeDir(t *testing.T, fileName string) (testFileRelPath string, testFileAbsPath string) {
testFileRelPath = "~" + fileutils.GetFileSeparator() + fileName
testFileAbsPath = fileutils.GetHomeDir() + fileutils.GetFileSeparator() + fileName
testFileRelPath = filepath.Join("~", fileName)
testFileAbsPath = filepath.Join(fileutils.GetHomeDir(), fileName)
d1 := []byte("test file")
err := ioutil.WriteFile(testFileAbsPath, d1, 0644)
if err != nil {
Expand All @@ -706,8 +706,8 @@ func TestArtifactoryUploadExcludeByCli1Wildcard(t *testing.T) {

func prepareFilePathForWindows(path string) string {
if runtime.GOOS == "windows" {
path = strings.Replace(path, "\\", "\\\\", -1)
path = strings.Replace(path, "/", "\\\\", -1)

}
return path
}
Expand All @@ -729,21 +729,21 @@ func TestArtifactoryUploadExcludeByCli2Wildcard(t *testing.T) {
t.Error("Couldn't create dir:", err)
}
defer os.Remove(absDirPath)
absDirPath = prepareFilePathForWindows(absDirPath + "/")
absDirPath = prepareFilePathForWindows(absDirPath)

// Create temp files
d1 := []byte("test file")
err = ioutil.WriteFile(absDirPath+"cliTestFile1.in", d1, 0644)
err = ioutil.WriteFile(filepath.Join(absDirPath, "cliTestFile1.in"), d1, 0644)
if err != nil {
t.Error("Couldn't create file:", err)
}
err = ioutil.WriteFile(absDirPath+"cliTestFile2.in", d1, 0644)
err = ioutil.WriteFile(filepath.Join(absDirPath, "cliTestFile2.in"), d1, 0644)
if err != nil {
t.Error("Couldn't create file:", err)
}

// Upload files
artifactoryCli.Exec("upload", absDirPath+"*", tests.Repo1, "--exclude-patterns=*cliTestFile1*")
artifactoryCli.Exec("upload", tests.FixWinPath(filepath.Join(absDirPath, "*")), tests.Repo1, "--exclude-patterns=*cliTestFile1*")

// Check files exists in artifactory
isExistInArtifactory([]string{tests.Repo1 + "/cliTestFile2.in"}, tests.GetFilePath(tests.Search), t)
Expand Down
10 changes: 5 additions & 5 deletions jfrog-cli/jfrog/buildinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestBuildAddDependenciesFromHomeDir(t *testing.T) {

fileName := "cliTestFile.txt"
testFileRelPath, testFileAbs := createFileInHomeDir(t, fileName)
testFileRelPath = testFileRelPath[:len(testFileRelPath)-5] + "*"

test := buildAddDepsBuildInfoTestParams{description: "'rt bad' from home dir", commandArgs: []string{testFileRelPath, "--recursive=false"}, expectedDependencies: []string{fileName}, buildNumber: "1"}
collectDepsAndPublishBuild(test, t)
validateBuildAddDepsBuildInfo(t, test)
Expand Down Expand Up @@ -54,7 +54,7 @@ func TestBuildAddDependenciesDryRun(t *testing.T) {

noCredsCli := tests.NewJfrogCli(main, "jfrog rt", "")
// Execute tha bad command
noCredsCli.Exec("bad", tests.BuildAddDepsBuildName, "1", "a/*", "--dry-run=true")
noCredsCli.Exec("bad", tests.BuildAddDepsBuildName, "1", prepareFilePathForWindows("a/*"), "--dry-run=true")
buildDir, err := buildutils.GetBuildDir(tests.BuildAddDepsBuildName, "1")
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -88,9 +88,9 @@ func TestBuildAddDependencies(t *testing.T) {
allFiles := []string{"a1.in", "a2.in", "a3.in", "b1.in", "b2.in", "b3.in", "c1.in", "c2.in", "c3.in"}

var badTests = []buildAddDepsBuildInfoTestParams{
{description: "'rt bad' simple cli", commandArgs: []string{"a/*"}, expectedDependencies: allFiles},
{description: "'rt bad' single file", commandArgs: []string{"a/a1.in"}, expectedDependencies: []string{"a1.in"}},
{description: "'rt bad' none recursive", commandArgs: []string{"a/*", "--recursive=false"}, expectedDependencies: []string{"a1.in", "a2.in", "a3.in"}},
{description: "'rt bad' simple cli", commandArgs: []string{prepareFilePathForWindows("a/*")}, expectedDependencies: allFiles},
{description: "'rt bad' single file", commandArgs: []string{prepareFilePathForWindows("a/a1.in")}, expectedDependencies: []string{"a1.in"}},
{description: "'rt bad' none recursive", commandArgs: []string{prepareFilePathForWindows("a/*"), "--recursive=false"}, expectedDependencies: []string{"a1.in", "a2.in", "a3.in"}},
{description: "'rt bad' special chars recursive", commandArgs: []string{getSpecialCharFilePath()}, expectedDependencies: []string{"a1.in"}},
{description: "'rt bad' exclude command line wildcards", commandArgs: []string{prepareFilePathForWindows("../testsdata/a/*"), "--exclude-patterns=*a2*;*a3.in"}, expectedDependencies: []string{"a1.in", "b1.in", "b2.in", "b3.in", "c1.in", "c2.in", "c3.in"}},
{description: "'rt bad' spec", commandArgs: []string{"--spec=" + tests.GetFilePath(tests.BuildAddDepsSpec)}, expectedDependencies: allFiles},
Expand Down
4 changes: 2 additions & 2 deletions jfrog-client/bintray/services/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"strconv"
"strings"
"sync"
"path/filepath"
)

func NewDownloadService(client *httpclient.HttpClient) *DownloadService {
Expand Down Expand Up @@ -179,7 +180,7 @@ func (ds *DownloadService) downloadBintrayFile(downloadParams *DownloadFileParam

localPath, localFileName := fileutils.GetLocalPathAndFile(fileName, filePath, placeHolderTarget, downloadParams.Flat)
var shouldDownload bool
shouldDownload, err = shouldDownloadFile(path.Join(localPath, localFileName), details)
shouldDownload, err = shouldDownloadFile(filepath.Join(localPath, localFileName), details)
if err != nil {
return err
}
Expand Down Expand Up @@ -218,7 +219,6 @@ func (ds *DownloadService) downloadBintrayFile(downloadParams *DownloadFileParam
FileSize: details.Size,
SplitCount: ds.SplitCount,
Flat: downloadParams.Flat}

httputils.DownloadFileConcurrently(concurrentDownloadFlags, "", httpClientsDetails)
} else {
if errorutils.CheckError(err) != nil {
Expand Down
25 changes: 10 additions & 15 deletions jfrog-client/utils/io/httputils/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package httputils

import (
"bytes"
"encoding/base64"
"errors"
"github.com/jfrogdev/jfrog-cli-go/jfrog-client/errors/httperrors"
"github.com/jfrogdev/jfrog-cli-go/jfrog-client/utils/errorutils"
Expand Down Expand Up @@ -268,32 +267,28 @@ func downloadFileRange(flags ConcurrentDownloadFlags, start, end int64, currentS
if err != nil {
return "", err
}
tempLocalPath = filepath.Join(tempLocalPath, flags.LocalPath)

tempFile, err := ioutil.TempFile(tempLocalPath, strconv.Itoa(currentSplit)+"_")
if errorutils.CheckError(err) != nil {
return "", err
}
defer tempFile.Close()

if httpClientsDetails.Headers == nil {
httpClientsDetails.Headers = make(map[string]string)
}
httpClientsDetails.Headers["Range"] = "bytes=" + strconv.FormatInt(start, 10) + "-" + strconv.FormatInt(end-1, 10)

resp, _, err := sendGetForFileDownload(flags.DownloadPath, false, httpClientsDetails)
err = errorutils.CheckError(err)
if err != nil {
if errorutils.CheckError(err) != nil {
return "", err
}
defer resp.Body.Close()

log.Debug(logMsgPrefix+"["+strconv.Itoa(currentSplit)+"]:", resp.Status+"...")
log.Info(logMsgPrefix+"["+strconv.Itoa(currentSplit)+"]:", resp.Status+"...")
os.MkdirAll(tempLocalPath, 0777)
filePath := filepath.Join(tempLocalPath, base64.StdEncoding.EncodeToString([]byte(flags.FileName))+"_"+strconv.Itoa(currentSplit))

out, err := os.Create(filePath)
err = errorutils.CheckError(err)
defer out.Close()
if err != nil {
return "", err
}
_, err = io.Copy(out, resp.Body)
return filePath, errorutils.CheckError(err)
_, err = io.Copy(tempFile, resp.Body)
return tempFile.Name(), errorutils.CheckError(err)
}

func GetRemoteFileDetails(downloadUrl string, httpClientsDetails HttpClientDetails) (*fileutils.FileDetails, error) {
Expand Down
2 changes: 1 addition & 1 deletion jfrog-client/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func GetUserHomeDir() string {
if home == "" {
home = os.Getenv("USERPROFILE")
}
return home
return strings.Replace(home, "\\", "\\\\", -1)
}
return os.Getenv("HOME")
}
Expand Down

0 comments on commit 3516e84

Please sign in to comment.