Skip to content

Commit 8c09ca7

Browse files
authored
Detailed summary tests - maven, gradle, goPublish (#1109)
1 parent d9f10d2 commit 8c09ca7

File tree

8 files changed

+150
-12
lines changed

8 files changed

+150
-12
lines changed

Diff for: buildinfo_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func TestBuildPublishDetailedSummary(t *testing.T) {
202202
defer log.SetLogger(previousLog)
203203
// Execute the bp command with --detailed-summary.
204204
assert.NoError(t, artifactoryCli.Exec("bp", tests.RtBuildName1, buildNumber, "--detailed-summary=true"))
205-
tests.VerifySha256DetailedSummary(t, buffer, previousLog)
205+
tests.VerifySha256DetailedSummaryFromBuffer(t, buffer, previousLog)
206206

207207
inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails)
208208
cleanArtifactoryTest()

Diff for: distribution_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ func TestReleaseBundleCreateDetailedSummary(t *testing.T) {
480480
runRb(t, "rbc", tests.BundleName, bundleVersion, tests.DistRepo1+"/data/b2.in", "--sign", "--detailed-summary")
481481
inttestutils.VerifyLocalBundleExistence(t, tests.BundleName, bundleVersion, true, distHttpDetails)
482482

483-
tests.VerifySha256DetailedSummary(t, buffer, previousLog)
483+
tests.VerifySha256DetailedSummaryFromBuffer(t, buffer, previousLog)
484484

485485
// Cleanup
486486
cleanDistributionTest(t)
@@ -505,7 +505,7 @@ func TestReleaseBundleUpdateDetailedSummary(t *testing.T) {
505505
// Update release bundle to have b1.in
506506
runRb(t, "rbu", tests.BundleName, bundleVersion, tests.DistRepo1+"/data/b1.in", "--sign", "--detailed-summary")
507507

508-
tests.VerifySha256DetailedSummary(t, buffer, previousLog)
508+
tests.VerifySha256DetailedSummaryFromBuffer(t, buffer, previousLog)
509509

510510
// Cleanup
511511
cleanDistributionTest(t)
@@ -530,7 +530,7 @@ func TestReleaseBundleSignDetailedSummary(t *testing.T) {
530530
// Update release bundle to have b1.in
531531
runRb(t, "rbs", tests.BundleName, bundleVersion, "--detailed-summary")
532532

533-
tests.VerifySha256DetailedSummary(t, buffer, previousLog)
533+
tests.VerifySha256DetailedSummaryFromBuffer(t, buffer, previousLog)
534534

535535
// Cleanup
536536
cleanDistributionTest(t)

Diff for: go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ require (
2323
gopkg.in/yaml.v2 v2.4.0
2424
)
2525

26-
replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v0.23.2-0.20210616180824-7e7eb3eace21
26+
replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v0.23.2-0.20210617164909-62762d2bc8b2
2727

28-
replace github.com/jfrog/jfrog-cli-core => github.com/jfrog/jfrog-cli-core v1.7.2-0.20210616184017-06f7d34a5734
28+
replace github.com/jfrog/jfrog-cli-core => github.com/jfrog/jfrog-cli-core v1.7.2-0.20210617173353-f527001c4aad
2929

3030
replace github.com/jfrog/gocmd => github.com/jfrog/gocmd v0.2.1-0.20210616181221-7159cf844cc3
3131

Diff for: go.sum

+4-4
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ github.com/jfrog/gocmd v0.2.1-0.20210616181221-7159cf844cc3 h1:aBSJVLX1UcUKdCgA+
151151
github.com/jfrog/gocmd v0.2.1-0.20210616181221-7159cf844cc3/go.mod h1:TeZBKJw38D3aKpkIH6tCCztECdhNLIkwHbnCZG8umKE=
152152
github.com/jfrog/gofrog v1.0.6 h1:yUDxSCw8gTK6vC4PvtG0HTnEOQJSZ+O4lWGCgkev1nU=
153153
github.com/jfrog/gofrog v1.0.6/go.mod h1:HkDzg+tMNw23UryoOv0+LB94BzYcl6MCIoz8Tmlb+s8=
154-
github.com/jfrog/jfrog-cli-core v1.7.2-0.20210616184017-06f7d34a5734 h1:vkLfpFdwT5bqkBN4lHSS8oDNLrgsudyP06k6Q5bTD2k=
155-
github.com/jfrog/jfrog-cli-core v1.7.2-0.20210616184017-06f7d34a5734/go.mod h1:HstXPwf6MmrwsXujF6z5l1bv+9EU1hS4A/WiZvxXLEo=
156-
github.com/jfrog/jfrog-client-go v0.23.2-0.20210616180824-7e7eb3eace21 h1:xIQYhaugt8Ka6LHZmYibx2Ee9l5jN0UuwcXcldYs3JQ=
157-
github.com/jfrog/jfrog-client-go v0.23.2-0.20210616180824-7e7eb3eace21/go.mod h1:1XMLr/yzslzV9uABPrX4gpA0Bvc51ZX6LRvu/L0WQPc=
154+
github.com/jfrog/jfrog-cli-core v1.7.2-0.20210617173353-f527001c4aad h1:vTqolA8nEAN4jBTT78Erzkc40vbOLhzYDI5czw0/bLw=
155+
github.com/jfrog/jfrog-cli-core v1.7.2-0.20210617173353-f527001c4aad/go.mod h1:I6Sk609q0PzLvMmOUEAgVAGK1Cjp9lJyBZg2ZV7AtFM=
156+
github.com/jfrog/jfrog-client-go v0.23.2-0.20210617164909-62762d2bc8b2 h1:OfZ5coJSiENCD/7JOFRYRVcRXtOnRh6c4JgDjlWYncg=
157+
github.com/jfrog/jfrog-client-go v0.23.2-0.20210617164909-62762d2bc8b2/go.mod h1:1XMLr/yzslzV9uABPrX4gpA0Bvc51ZX6LRvu/L0WQPc=
158158
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
159159
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
160160
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=

Diff for: go_test.go

+51-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package main
22

33
import (
4+
"github.com/jfrog/jfrog-cli-core/artifactory/commands/golang"
5+
"github.com/jfrog/jfrog-cli-core/artifactory/utils"
6+
"github.com/jfrog/jfrog-cli-core/common/commands"
47
"io/ioutil"
58
"os"
69
"os/exec"
@@ -311,7 +314,7 @@ func runGo(module, buildName, buildNumber string, t *testing.T, args ...string)
311314
inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails)
312315
}
313316

314-
func prepareGoProject(configDestDir string, t *testing.T, copyDirs bool) {
317+
func prepareGoProject(configDestDir string, t *testing.T, copyDirs bool) string {
315318
project1Path := createGoProject(t, "project1", copyDirs)
316319
testdataTarget := filepath.Join(tests.Out, "testdata")
317320
testdataSrc := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "go", "testdata")
@@ -325,6 +328,7 @@ func prepareGoProject(configDestDir string, t *testing.T, copyDirs bool) {
325328
assert.NoError(t, err)
326329
assert.NoError(t, os.Chdir(project1Path))
327330
log.Info("Using Go project located at ", project1Path)
331+
return project1Path
328332
}
329333

330334
// Testing publishing and resolution capabilities for go projects.
@@ -370,6 +374,51 @@ func TestGoPublishResolve(t *testing.T) {
370374
cleanGoTest(t)
371375
}
372376

377+
func TestGoPublishWithDetailedSummary(t *testing.T) {
378+
initGoTest(t)
379+
380+
// Init environment
381+
wd, err := os.Getwd()
382+
assert.NoError(t, err)
383+
projectPath := prepareGoProject("", t, true)
384+
385+
// Publish with detailed summary and buildinfo.
386+
// Build project
387+
buildNumber := "1"
388+
artifactoryGoCli := tests.NewJfrogCli(execMain, "jfrog rt", "")
389+
assert.NoError(t, execGo(t, artifactoryGoCli, "go", "build", "--build-name="+tests.GoBuildName, "--build-number="+buildNumber, "--module="+ModuleNameJFrogTest))
390+
391+
// GoPublish with detailed summary without buildinfo.
392+
goPublishCmd := golang.NewGoPublishCommand()
393+
goPublishCmd.SetConfigFilePath(filepath.Join(projectPath, ".jfrog", "projects", "go.yaml")).SetBuildConfiguration(new(utils.BuildConfiguration)).SetVersion("v1.0.0").SetDetailedSummary(true)
394+
assert.NoError(t, commands.Exec(goPublishCmd))
395+
tests.VerifySha256DetailedSummaryFromResult(t, goPublishCmd.Result())
396+
397+
// GoPublish with buildinfo configuration
398+
buildConf := utils.BuildConfiguration{BuildName: tests.GoBuildName, BuildNumber: buildNumber, Module: ModuleNameJFrogTest}
399+
goPublishCmd.SetBuildConfiguration(&buildConf)
400+
assert.NoError(t, commands.Exec(goPublishCmd))
401+
tests.VerifySha256DetailedSummaryFromResult(t, goPublishCmd.Result())
402+
403+
// Build publish
404+
assert.NoError(t, artifactoryCli.Exec("bp", tests.GoBuildName, buildNumber))
405+
publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.GoBuildName, buildNumber)
406+
if err != nil {
407+
assert.NoError(t, err)
408+
return
409+
}
410+
if !found {
411+
assert.True(t, found, "build info was expected to be found")
412+
return
413+
}
414+
buildInfo := publishedBuildInfo.BuildInfo
415+
validateBuildInfo(buildInfo, t, 4, 3, ModuleNameJFrogTest, buildinfo.Go)
416+
417+
// Restore workspace
418+
assert.NoError(t, os.Chdir(wd))
419+
cleanGoTest(t)
420+
}
421+
373422
// Testing the fallback mechanism
374423
// 1. Building a project with a dependency that doesn't exists not in Artifactory and not in VCS.
375424
// 2. The fallback mechanism will try to download from both VCS and Artifactory and then fail with an error
@@ -433,6 +482,7 @@ func initGoTest(t *testing.T) {
433482
t.Skip("Skipping go test. To run go test add the '-test.go=true' option.")
434483
}
435484
assert.NoError(t, os.Setenv("GONOSUMDB", "github.com/jfrog"))
485+
createJfrogHomeConfig(t, true)
436486
}
437487

438488
func cleanGoTest(t *testing.T) {

Diff for: gradle_test.go

+50
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package main
22

33
import (
4+
"github.com/jfrog/jfrog-cli-core/artifactory/commands/gradle"
5+
"github.com/jfrog/jfrog-cli-core/artifactory/utils"
6+
"github.com/jfrog/jfrog-cli-core/common/commands"
47
"os"
58
"path/filepath"
69
"strings"
@@ -87,6 +90,53 @@ func TestNativeGradleBuildWithServerID(t *testing.T) {
8790
cleanGradleTest()
8891
}
8992

93+
func TestNativeGradleBuildWithServerIDAndDetailedSummary(t *testing.T) {
94+
initGradleTest(t)
95+
buildGradlePath := createGradleProject(t, "gradleproject")
96+
configFilePath := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "buildspecs", tests.GradleConfig)
97+
destPath := filepath.Join(filepath.Dir(buildGradlePath), ".jfrog", "projects")
98+
createConfigFile(destPath, configFilePath, t)
99+
oldHomeDir := changeWD(t, filepath.Dir(buildGradlePath))
100+
buildNumber := "1"
101+
buildGradlePath = strings.Replace(buildGradlePath, `\`, "/", -1) // Windows compatibility.
102+
103+
// Test gradle with detailed summary without buildinfo props.
104+
filteredGradleArgs := []string{"clean artifactoryPublish", "-b" + buildGradlePath}
105+
gradleCmd := gradle.NewGradleCommand().SetConfiguration(new(utils.BuildConfiguration)).SetTasks(strings.Join(filteredGradleArgs, " ")).SetConfigPath(filepath.Join(destPath, "gradle.yaml")).SetDetailedSummary(true)
106+
assert.NoError(t, commands.Exec(gradleCmd))
107+
// Validate sha256
108+
tests.VerifySha256DetailedSummaryFromResult(t, gradleCmd.Result())
109+
110+
// Test gradle with detailed summary + buildinfo.
111+
buildConfiguration := &utils.BuildConfiguration{BuildName: tests.GradleBuildName, BuildNumber: buildNumber}
112+
gradleCmd = gradle.NewGradleCommand().SetConfiguration(buildConfiguration).SetTasks(strings.Join(filteredGradleArgs, " ")).SetConfigPath(filepath.Join(destPath, "gradle.yaml")).SetDetailedSummary(true)
113+
assert.NoError(t, commands.Exec(gradleCmd))
114+
// Validate sha256
115+
tests.VerifySha256DetailedSummaryFromResult(t, gradleCmd.Result())
116+
117+
err := os.Chdir(oldHomeDir)
118+
assert.NoError(t, err)
119+
// Validate build info
120+
searchSpec, err := tests.CreateSpec(tests.SearchAllGradle)
121+
assert.NoError(t, err)
122+
verifyExistInArtifactory(tests.GetGradleDeployedArtifacts(), searchSpec, t)
123+
verifyExistInArtifactoryByProps(tests.GetGradleDeployedArtifacts(), tests.GradleRepo+"/*", "build.name="+tests.GradleBuildName+";build.number="+buildNumber, t)
124+
assert.NoError(t, artifactoryCli.Exec("bp", tests.GradleBuildName, buildNumber))
125+
126+
publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.GradleBuildName, buildNumber)
127+
if err != nil {
128+
assert.NoError(t, err)
129+
return
130+
}
131+
if !found {
132+
assert.True(t, found, "build info was expected to be found")
133+
return
134+
}
135+
buildInfo := publishedBuildInfo.BuildInfo
136+
validateBuildInfo(buildInfo, t, 0, 1, gradleModuleId, buildinfo.Gradle)
137+
cleanGradleTest()
138+
}
139+
90140
func TestGradleBuildWithServerIDWithUsesPlugin(t *testing.T) {
91141
initGradleTest(t)
92142

Diff for: maven_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package main
22

33
import (
4+
"github.com/jfrog/jfrog-cli-core/artifactory/commands/mvn"
5+
"github.com/jfrog/jfrog-cli-core/artifactory/utils"
6+
"github.com/jfrog/jfrog-cli-core/common/commands"
47
"io/ioutil"
58
"net/url"
69
"os"
@@ -61,6 +64,29 @@ func TestNativeMavenBuildWithServerID(t *testing.T) {
6164
cleanMavenTest()
6265
}
6366

67+
func TestNativeMavenBuildWithServerIDAndDetailedSummary(t *testing.T) {
68+
initMavenTest(t, false)
69+
pomPath := createMavenProject(t)
70+
configFilePath := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "buildspecs", tests.MavenConfig)
71+
destPath := filepath.Join(filepath.Dir(pomPath), ".jfrog", "projects")
72+
createConfigFile(destPath, configFilePath, t)
73+
oldHomeDir := changeWD(t, filepath.Dir(pomPath))
74+
repoLocalSystemProp := localRepoSystemProperty + localRepoDir
75+
pomPath = strings.Replace(pomPath, `\`, "/", -1) // Windows compatibility.
76+
filteredMavenArgs := []string{"clean", "install", "-f", pomPath, repoLocalSystemProp}
77+
mvnCmd := mvn.NewMvnCommand().SetConfiguration(new(utils.BuildConfiguration)).SetConfigPath(filepath.Join(destPath, tests.MavenConfig)).SetGoals(filteredMavenArgs).SetDetailedSummary(true)
78+
assert.NoError(t, commands.Exec(mvnCmd))
79+
err := os.Chdir(oldHomeDir)
80+
assert.NoError(t, err)
81+
// Validate
82+
tests.VerifySha256DetailedSummaryFromResult(t, mvnCmd.Result())
83+
84+
searchSpec, err := tests.CreateSpec(tests.SearchAllMaven)
85+
assert.NoError(t, err)
86+
verifyExistInArtifactory(tests.GetMavenDeployedArtifacts(), searchSpec, t)
87+
cleanMavenTest()
88+
}
89+
6490
func TestMavenBuildWithoutDeployer(t *testing.T) {
6591
initMavenTest(t, false)
6692
pomPath := createMavenProject(t)

Diff for: utils/tests/utils.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"flag"
99
"fmt"
1010
"github.com/jfrog/jfrog-cli/utils/summary"
11+
clientutils "github.com/jfrog/jfrog-client-go/utils"
1112
"io/ioutil"
1213
"math/rand"
1314
"os"
@@ -31,6 +32,7 @@ import (
3132
"github.com/jfrog/jfrog-cli-core/utils/coreutils"
3233
"github.com/stretchr/testify/assert"
3334

35+
commandutils "github.com/jfrog/jfrog-cli-core/artifactory/commands/utils"
3436
"github.com/jfrog/jfrog-client-go/artifactory/services/utils"
3537
"github.com/jfrog/jfrog-client-go/auth"
3638
"github.com/jfrog/jfrog-client-go/utils/errorutils"
@@ -645,7 +647,7 @@ func RedirectLogOutputToNil() (previousLog log.Log) {
645647
return previousLog
646648
}
647649

648-
func VerifySha256DetailedSummary(t *testing.T, buffer *bytes.Buffer, logger log.Log) {
650+
func VerifySha256DetailedSummaryFromBuffer(t *testing.T, buffer *bytes.Buffer, logger log.Log) {
649651
content := buffer.Bytes()
650652
buffer.Reset()
651653
logger.Output(string(content))
@@ -664,3 +666,13 @@ func VerifySha256DetailedSummary(t *testing.T, buffer *bytes.Buffer, logger log.
664666
assert.Equal(t, 64, len(sha256.Sha256Str), "Summary validation failed - invalid sha256 has returned from artifactory")
665667
}
666668
}
669+
670+
func VerifySha256DetailedSummaryFromResult(t *testing.T, result *commandutils.Result) {
671+
result.Reader()
672+
reader := result.Reader()
673+
defer reader.Close()
674+
assert.NoError(t, reader.GetError())
675+
for transferDetails := new(clientutils.FileTransferDetails); reader.NextRecord(transferDetails) == nil; transferDetails = new(clientutils.FileTransferDetails) {
676+
assert.Equal(t, 64, len(transferDetails.Sha256), "Summary validation failed - invalid sha256 has returned from artifactory")
677+
}
678+
}

0 commit comments

Comments
 (0)