Skip to content

Commit a789a1f

Browse files
committed
Improve upload archive progress bar
Signed-off-by: Michael Sverdlov <[email protected]>
1 parent a412162 commit a789a1f

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

artifactory/commands/setup/setup_test.go

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
1010
"github.com/jfrog/jfrog-cli-core/v2/utils/ioutils"
1111
"github.com/jfrog/jfrog-client-go/auth"
12-
clientTestUtils "github.com/jfrog/jfrog-client-go/utils/tests"
1312
"github.com/stretchr/testify/assert"
1413
"github.com/stretchr/testify/require"
1514
"golang.org/x/exp/slices"
@@ -170,24 +169,14 @@ func TestSetupCommand_Pip(t *testing.T) {
170169
func testSetupCommandPip(t *testing.T, packageManager project.ProjectType, customConfig bool) {
171170
var pipConfFilePath string
172171
if customConfig {
172+
// For custom configuration file, set the PIP_CONFIG_FILE environment variable to point to the temporary pip.conf file.
173173
pipConfFilePath = filepath.Join(t.TempDir(), "pip.conf")
174-
restoreEnv := clientTestUtils.SetEnvWithCallbackAndAssert(t, "PIP_CONFIG_FILE", pipConfFilePath)
175-
defer restoreEnv()
174+
t.Setenv("PIP_CONFIG_FILE", pipConfFilePath)
176175
} else {
177-
if coreutils.IsWindows() {
178-
pipConfFilePath = filepath.Join(os.Getenv("APPDATA"), "pip", "pip.ini")
179-
} else {
180-
// Retrieve the home directory and construct the pip.conf file path.
181-
homeDir, err := os.UserHomeDir()
182-
assert.NoError(t, err)
183-
pipConfFilePath = filepath.Join(homeDir, ".config", "pip", "pip.conf")
184-
}
185-
// Back up the existing .pip.conf file and ensure restoration after the test.
186-
restorePipConfFunc, err := ioutils.BackupFile(pipConfFilePath, ".pipconf.backup")
187-
assert.NoError(t, err)
188-
defer func() {
189-
assert.NoError(t, restorePipConfFunc())
190-
}()
176+
// For global configuration file, back up the existing pip.conf file and ensure restoration after the test.
177+
var restoreFunc func()
178+
pipConfFilePath, restoreFunc = globalGlobalPipConfigPath(t)
179+
defer restoreFunc()
191180
}
192181

193182
pipLoginCmd := createTestSetupCommand(packageManager)
@@ -225,12 +214,30 @@ func testSetupCommandPip(t *testing.T, packageManager project.ProjectType, custo
225214
}
226215
}
227216

217+
// globalGlobalPipConfigPath returns the path to the global pip.conf file and a backup function to restore the original file.
218+
func globalGlobalPipConfigPath(t *testing.T) (string, func()) {
219+
var pipConfFilePath string
220+
if coreutils.IsWindows() {
221+
pipConfFilePath = filepath.Join(os.Getenv("APPDATA"), "pip", "pip.ini")
222+
} else {
223+
// Retrieve the home directory and construct the pip.conf file path.
224+
homeDir, err := os.UserHomeDir()
225+
assert.NoError(t, err)
226+
pipConfFilePath = filepath.Join(homeDir, ".config", "pip", "pip.conf")
227+
}
228+
// Back up the existing .pip.conf file and ensure restoration after the test.
229+
restorePipConfFunc, err := ioutils.BackupFile(pipConfFilePath, ".pipconf.backup")
230+
assert.NoError(t, err)
231+
return pipConfFilePath, func() {
232+
assert.NoError(t, restorePipConfFunc())
233+
}
234+
}
235+
228236
func TestSetupCommand_configurePoetry(t *testing.T) {
229237
configDir := t.TempDir()
230238
poetryConfigFilePath := filepath.Join(configDir, "config.toml")
231239
poetryAuthFilePath := filepath.Join(configDir, "auth.toml")
232-
restoreEnv := clientTestUtils.SetEnvWithCallbackAndAssert(t, "POETRY_CONFIG_DIR", configDir)
233-
defer restoreEnv()
240+
t.Setenv("POETRY_CONFIG_DIR", configDir)
234241
poetryLoginCmd := createTestSetupCommand(project.Poetry)
235242

236243
for _, testCase := range testCases {
@@ -279,8 +286,7 @@ func TestSetupCommand_configurePoetry(t *testing.T) {
279286
func TestSetupCommand_Go(t *testing.T) {
280287
goProxyEnv := "GOPROXY"
281288
// Restore the original value of the GOPROXY environment variable after the test.
282-
restoreGoProxy := clientTestUtils.SetEnvWithCallbackAndAssert(t, goProxyEnv, "")
283-
defer restoreGoProxy()
289+
t.Setenv(goProxyEnv, "")
284290

285291
// Assuming createTestSetupCommand initializes your Go login command
286292
goLoginCmd := createTestSetupCommand(project.Go)
@@ -329,12 +335,10 @@ func testBuildToolLoginCommandConfigureDotnetNuget(t *testing.T, packageManager
329335
// Set the NuGet.config file path to a custom location.
330336
if packageManager == project.Dotnet {
331337
nugetConfigFilePath = filepath.Join(t.TempDir(), "NuGet.Config")
332-
restoreEnv := clientTestUtils.SetEnvWithCallbackAndAssert(t, "DOTNET_CLI_HOME", filepath.Dir(nugetConfigFilePath))
333-
defer restoreEnv()
338+
t.Setenv("DOTNET_CLI_HOME", filepath.Dir(nugetConfigFilePath))
334339
} else {
335340
nugetConfigFilePath = filepath.Join(t.TempDir(), "nuget.config")
336-
restoreEnv := clientTestUtils.SetEnvWithCallbackAndAssert(t, "NUGET_CONFIG_FILE", nugetConfigFilePath)
337-
defer restoreEnv()
341+
t.Setenv("NUGET_CONFIG_FILE", nugetConfigFilePath)
338342
}
339343

340344
nugetLoginCmd := createTestSetupCommand(packageManager)

0 commit comments

Comments
 (0)