Skip to content

Commit dcf5425

Browse files
committed
Fix CreateJfrogHomeConfig to work without testing.T context
The previous commit called CreateJfrogHomeConfig(nil, '', true) from setupIntegrationTests(), which runs in TestMain without a testing.T context. This caused all assert.NoError() calls to silently fail, so config creation errors were ignored and the config was never actually created! Solution: - Created createDefaultServerConfig() helper that handles errors manually - Uses os.Exit(1) on errors instead of assert.NoError() - Properly creates the default server config before any tests run - Added required imports: path/filepath, commonCommands, clientUtils This ensures binary scan tests have a valid config to use.
1 parent 4840220 commit dcf5425

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

jfrogclisecurity_test.go

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ package main
22

33
import (
44
"fmt"
5+
"os"
6+
"path/filepath"
7+
"testing"
58

9+
commonCommands "github.com/jfrog/jfrog-cli-core/v2/common/commands"
610
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
711
"github.com/jfrog/jfrog-cli-core/v2/utils/log"
812
"github.com/jfrog/jfrog-cli-security/cli"
9-
integrationUtils "github.com/jfrog/jfrog-cli-security/tests/utils/integration"
10-
1113
configTests "github.com/jfrog/jfrog-cli-security/tests"
12-
14+
integrationUtils "github.com/jfrog/jfrog-cli-security/tests/utils/integration"
1315
clientLog "github.com/jfrog/jfrog-client-go/utils/log"
14-
15-
"os"
16-
"testing"
16+
clientUtils "github.com/jfrog/jfrog-client-go/utils"
1717
)
1818

1919
func TestMain(m *testing.M) {
@@ -44,7 +44,34 @@ func setupIntegrationTests() {
4444
integrationUtils.CreateRequiredRepositories()
4545
// Create CLI config for binary scan tests (Docker tests create their own isolated configs)
4646
if *configTests.TestScan {
47-
integrationUtils.CreateJfrogHomeConfig(nil, "", true)
47+
createDefaultServerConfig()
48+
}
49+
}
50+
51+
// createDefaultServerConfig creates the default CLI config for tests without requiring a testing.T context
52+
func createDefaultServerConfig() {
53+
wd, err := os.Getwd()
54+
if err != nil {
55+
clientLog.Error(fmt.Sprintf("Failed to get current dir: %s", err.Error()))
56+
os.Exit(1)
57+
}
58+
if err := os.Setenv(coreutils.HomeDir, filepath.Join(wd, configTests.Out, "jfroghome")); err != nil {
59+
clientLog.Error(fmt.Sprintf("Failed to set HomeDir: %s", err.Error()))
60+
os.Exit(1)
61+
}
62+
63+
// Delete the default server if exist
64+
config, err := commonCommands.GetConfig("default", false)
65+
if err == nil && config.ServerId != "" {
66+
if err = commonCommands.NewConfigCommand(commonCommands.Delete, "default").Run(); err != nil {
67+
clientLog.Error(fmt.Sprintf("Failed to delete existing default config: %s", err.Error()))
68+
os.Exit(1)
69+
}
70+
}
71+
*configTests.JfrogUrl = clientUtils.AddTrailingSlashIfNeeded(*configTests.JfrogUrl)
72+
if err = commonCommands.NewConfigCommand(commonCommands.AddOrEdit, "default").SetDetails(configTests.XrDetails).SetInteractive(false).SetEncPassword(true).Run(); err != nil {
73+
clientLog.Error(fmt.Sprintf("Failed to create default config: %s", err.Error()))
74+
os.Exit(1)
4875
}
4976
}
5077

0 commit comments

Comments
 (0)