Skip to content

Commit 81e6ddf

Browse files
committed
fixing test case to be compatible with 8+
1 parent 1fc5d85 commit 81e6ddf

File tree

4 files changed

+62
-9
lines changed

4 files changed

+62
-9
lines changed

gradle_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,12 @@ func TestGradleBuildWithFlexPackFallback(t *testing.T) {
453453
configFilePath := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "buildspecs", tests.GradleConfig)
454454
destPath := filepath.Join(filepath.Dir(buildGradlePath), ".jfrog", "projects")
455455
createConfigFile(destPath, configFilePath, t)
456+
457+
// Create the search spec before changing the working directory.
458+
// tests.GetTestResourcesPath() is relative ("testdata"), so creating the spec after chdir may fail on CI.
459+
searchSpec, err := tests.CreateSpec(tests.SearchAllGradle)
460+
require.NoError(t, err)
461+
456462
oldHomeDir := changeWD(t, filepath.Dir(buildGradlePath))
457463
defer clientTestUtils.ChangeDirAndAssert(t, oldHomeDir)
458464

@@ -466,8 +472,6 @@ func TestGradleBuildWithFlexPackFallback(t *testing.T) {
466472
runJfrogCli(t, "gradle", "clean", "artifactoryPublish", "-b"+buildGradlePath, "--build-name="+buildName, "--build-number="+buildNumber)
467473

468474
// Validate artifacts were deployed (traditional approach deploys to Artifactory)
469-
searchSpec, err := tests.CreateSpec(tests.SearchAllGradle)
470-
assert.NoError(t, err)
471475
inttestutils.VerifyExistInArtifactory(tests.GetGradleDeployedArtifacts(), searchSpec, serverDetails, t)
472476

473477
cleanGradleTest(t)

inttestutils/artifactory.go

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
1010
"github.com/jfrog/jfrog-cli/utils/tests"
1111
"github.com/stretchr/testify/assert"
12+
"github.com/stretchr/testify/require"
1213
)
1314

1415
// Verify the input slice exist in Artifactory
@@ -17,23 +18,39 @@ import (
1718
// serverDetails - Target Artifactory server details
1819
// t - Tests object
1920
func VerifyExistInArtifactory(expected []string, specFile string, serverDetails *config.ServerDetails, t *testing.T) {
20-
results, _ := SearchInArtifactory(specFile, serverDetails, t)
21+
results, err := SearchInArtifactory(specFile, serverDetails, t)
22+
require.NoError(t, err)
2123
tests.CompareExpectedVsActual(expected, results, t)
2224
}
2325

2426
func SearchInArtifactory(specFile string, serverDetails *config.ServerDetails, t *testing.T) ([]utils.SearchResult, error) {
25-
searchSpec, _ := spec.CreateSpecFromFile(specFile, nil)
27+
searchSpec, err := spec.CreateSpecFromFile(specFile, nil)
28+
if err != nil {
29+
return nil, err
30+
}
31+
if searchSpec == nil {
32+
return nil, assert.AnError
33+
}
2634
searchCmd := generic.NewSearchCommand()
2735
searchCmd.SetServerDetails(serverDetails).SetSpec(searchSpec)
2836
reader, err := searchCmd.Search()
29-
assert.NoError(t, err)
37+
if err != nil {
38+
return nil, err
39+
}
3040
var resultItems []utils.SearchResult
3141
readerNoDate, err := utils.SearchResultNoDate(reader)
32-
assert.NoError(t, err)
42+
if err != nil {
43+
_ = reader.Close()
44+
return nil, err
45+
}
3346
for searchResult := new(utils.SearchResult); readerNoDate.NextRecord(searchResult) == nil; searchResult = new(utils.SearchResult) {
3447
resultItems = append(resultItems, *searchResult)
3548
}
36-
assert.NoError(t, reader.Close(), "Couldn't close reader")
37-
assert.NoError(t, reader.GetError(), "Couldn't get reader error")
38-
return resultItems, err
49+
if cerr := reader.Close(); cerr != nil {
50+
return resultItems, cerr
51+
}
52+
if rerr := reader.GetError(); rerr != nil {
53+
return resultItems, rerr
54+
}
55+
return resultItems, nil
3956
}

testdata/gradle/gradleproject/build.gradle

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ repositories {
55
mavenCentral()
66
}
77

8+
// Gradle 8+ blocks http:// repositories unless allowInsecureProtocol=true is set.
9+
// The JFrog Gradle integration (traditional extractor flow) may add an Artifactory resolver repo using http://localhost in tests.
10+
// This block is safe across Gradle versions because it checks for the property before setting it.
11+
allprojects {
12+
repositories.all { repo ->
13+
try {
14+
def urlStr = repo.respondsTo('getUrl') && repo.url != null ? repo.url.toString() : ""
15+
if (urlStr.startsWith("http://") && repo.hasProperty("allowInsecureProtocol")) {
16+
repo.allowInsecureProtocol = true
17+
}
18+
} catch (Throwable ignored) {
19+
// Best-effort; ignore repositories that don't support URL/allowInsecureProtocol.
20+
}
21+
}
22+
}
23+
824
dependencies {
925
implementation "junit:junit:4.7"
1026
}

testdata/gradle/projectwithplugin/build.gradle

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@ apply plugin: 'idea'
1111
apply plugin: 'com.jfrog.artifactory'
1212
apply plugin: 'maven-publish'
1313

14+
// Gradle 8+ blocks http:// repositories unless allowInsecureProtocol=true is set.
15+
// The JFrog Gradle integration / Artifactory plugin may add an Artifactory resolver repo using http://localhost in tests.
16+
// This block is safe across Gradle versions because it checks for the property before setting it.
17+
allprojects {
18+
repositories.all { repo ->
19+
try {
20+
def urlStr = repo.respondsTo('getUrl') && repo.url != null ? repo.url.toString() : ""
21+
if (urlStr.startsWith("http://") && repo.hasProperty("allowInsecureProtocol")) {
22+
repo.allowInsecureProtocol = true
23+
}
24+
} catch (Throwable ignored) {
25+
// Best-effort; ignore repositories that don't support URL/allowInsecureProtocol.
26+
}
27+
}
28+
}
29+
1430
version = 1.0
1531
task initProject(description: 'Initialize project directory structure.') {
1632
doLast {

0 commit comments

Comments
 (0)