Skip to content

Commit

Permalink
Improve upload archive progress bar
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Sverdlov <michaelsv@jfrog.com>
  • Loading branch information
sverdlov93 committed Jan 29, 2025
1 parent 992b353 commit 0407afa
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pip_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package main

import (
"fmt"
biutils "github.com/jfrog/build-info-go/utils"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
coretests "github.com/jfrog/jfrog-cli-core/v2/utils/tests"
"github.com/jfrog/jfrog-cli-security/commands/audit/sca/python"
"github.com/jfrog/jfrog-client-go/http/httpclient"
clientTestUtils "github.com/jfrog/jfrog-client-go/utils/tests"
"net/http"
"os"
"os/exec"
"path/filepath"
"strconv"
"testing"
Expand Down Expand Up @@ -269,3 +273,33 @@ func testTwineCmd(t *testing.T, projectPath, buildNumber, expectedModuleId strin
assert.Len(t, twineModule.Artifacts, expectedArtifacts)
assert.Equal(t, expectedModuleId, twineModule.Id)
}

func TestSetupPipCommand(t *testing.T) {
if !*tests.TestPip {
t.Skip("Skipping Pip test. To run Pip test add the '-test.pip=true' option.")
}

// Set custom pip.conf file.
t.Setenv("PIP_CONFIG_FILE", filepath.Join(t.TempDir(), "pip.conf"))

// Validate that the package does not exist in the cache before running the test.
client, err := httpclient.ClientBuilder().Build()
assert.NoError(t, err)
packageCacheUrl := serverDetails.ArtifactoryUrl + tests.PypiRemoteRepo + "-cache/54/16/12b82f791c7f50ddec566873d5bdd245baa1491bac11d15ffb98aecc8f8b/pefile-2024.8.26-py3-none-any.whl"

_, _, err = client.GetRemoteFileDetails(packageCacheUrl, artHttpDetails)
assert.ErrorContains(t, err, "404")

jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
require.NoError(t, execGo(jfrogCli, "setup", "pip", "--repo="+tests.PypiRemoteRepo))

// Run 'pip install' to resolve the package from Artifactory and force it to be cached.
output, err := exec.Command("pip", "install", "--target", t.TempDir(), "--no-cache-dir", "pefile==2024.8.26").CombinedOutput()
assert.NoError(t, err, fmt.Sprintf("%s\n%q", string(output), err))

// Validate that the package exists in the cache after running the test.
_, res, err := client.GetRemoteFileDetails(packageCacheUrl, artHttpDetails)
if assert.NoError(t, err, "Failed to find the package in the cache: "+packageCacheUrl) {
assert.Equal(t, http.StatusOK, res.StatusCode)
}
}
43 changes: 43 additions & 0 deletions pipenv_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package main

import (
"fmt"
biutils "github.com/jfrog/build-info-go/utils"
"github.com/jfrog/jfrog-client-go/http/httpclient"
"net/http"
"os"
"os/exec"
"path/filepath"
"strconv"
"testing"
Expand Down Expand Up @@ -133,3 +137,42 @@ func initPipenvTest(t *testing.T) {
require.True(t, isRepoExist(tests.PipenvRemoteRepo), "Pypi test remote repository doesn't exist.")
require.True(t, isRepoExist(tests.PipenvVirtualRepo), "Pypi test virtual repository doesn't exist.")
}

func TestSetupPipenvCommand(t *testing.T) {
if !*tests.TestPipenv {
t.Skip("Skipping Pipenv test. To run Pipenv test add the '-test.pipenv=true' option.")
}

// Change dir to temp dir to run the pipenv install in a clean environment.
wd, err := os.Getwd()
assert.NoError(t, err, "Failed to get current dir")
chdir := clientTestUtils.ChangeDirWithCallback(t, wd, t.TempDir())
defer chdir()

// Set custom pip.conf file.
t.Setenv("PIP_CONFIG_FILE", filepath.Join(t.TempDir(), "pip.conf"))

// Validate that the package does not exist in the cache before running the test.
client, err := httpclient.ClientBuilder().Build()
assert.NoError(t, err)
packageCacheUrl := serverDetails.ArtifactoryUrl + tests.PipenvRemoteRepo + "-cache/54/16/12b82f791c7f50ddec566873d5bdd245baa1491bac11d15ffb98aecc8f8b/pefile-2024.8.26-py3-none-any.whl"

_, _, err = client.GetRemoteFileDetails(packageCacheUrl, artHttpDetails)
assert.ErrorContains(t, err, "404")

// Set PIP_NO_CACHE_DIR to 'off' to force resolving the package from Artifactory.
unset := clientTestUtils.SetEnvWithCallbackAndAssert(t, "PIP_NO_CACHE_DIR", "1")
defer unset()
jfrogCli := coreTests.NewJfrogCli(execMain, "jfrog", "")
require.NoError(t, execGo(jfrogCli, "setup", "pipenv", "--repo="+tests.PipenvRemoteRepo))

// Run 'pip install' to resolve the package from Artifactory and force it to be cached.
output, err := exec.Command("pipenv", "install", "pefile==2024.8.26").CombinedOutput()
assert.NoError(t, err, fmt.Sprintf("%s\n%q", string(output), err))

// Validate that the package exists in the cache after running the test.
_, res, err := client.GetRemoteFileDetails(packageCacheUrl, artHttpDetails)
if assert.NoError(t, err, "Failed to find the package in the cache: "+packageCacheUrl) {
assert.Equal(t, http.StatusOK, res.StatusCode)
}
}

0 comments on commit 0407afa

Please sign in to comment.