forked from jfrog/jfrog-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgradle_test.go
132 lines (111 loc) · 5.59 KB
/
gradle_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package main
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/jfrog/jfrog-cli/artifactory/spec"
"github.com/jfrog/jfrog-cli/inttestutils"
"github.com/jfrog/jfrog-cli/utils/cliutils"
"github.com/jfrog/jfrog-cli/utils/tests"
)
const gradleFlagName = "gradle"
func cleanGradleTest() {
os.Unsetenv(cliutils.HomeDir)
deleteSpec := spec.NewBuilder().Pattern(tests.GradleRepo).BuildSpec()
tests.DeleteFiles(deleteSpec, artifactoryDetails)
tests.CleanFileSystem()
}
func TestGradleBuildWithServerID(t *testing.T) {
initGradleTest(t)
buildGradlePath := createGradleProject(t, "gradleproject")
configFilePath := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "buildspecs", tests.GradleServerIDConfig)
configFilePath, err := tests.ReplaceTemplateVariables(configFilePath, "")
assert.NoError(t, err)
buildName := "gradle-cli"
buildNumber := "1"
runAndValidateGradle(buildGradlePath, configFilePath, buildName, buildNumber, t)
artifactoryCli.Exec("bp", buildName, buildNumber)
buildInfo, _ := inttestutils.GetBuildInfo(artifactoryDetails.Url, buildName, buildNumber, t, artHttpDetails)
validateBuildInfo(buildInfo, t, 0, 1, ":minimal-example:1.0")
cleanGradleTest()
}
func TestNativeGradleBuildWithServerID(t *testing.T) {
initGradleTest(t)
buildGradlePath := createGradleProject(t, "gradleproject")
configFilePath := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "buildspecs", tests.GradleConfig)
destPath := filepath.Join(filepath.Dir(buildGradlePath), ".jfrog", "projects")
createConfigFile(destPath, configFilePath, t)
oldHomeDir := changeWD(t, filepath.Dir(buildGradlePath))
buildNumber := "1"
buildGradlePath = strings.Replace(buildGradlePath, `\`, "/", -1) // Windows compatibility.
runCli(t, "gradle", "clean artifactoryPublish", "-b"+buildGradlePath, "--build-name="+tests.GradleBuildName, "--build-number="+buildNumber)
err := os.Chdir(oldHomeDir)
assert.NoError(t, err)
// Validate
searchSpec, err := tests.CreateSpec(tests.SearchAllGradle)
assert.NoError(t, err)
verifyExistInArtifactory(tests.GetGradleDeployedArtifacts(), searchSpec, t)
verifyExistInArtifactoryByProps(tests.GetGradleDeployedArtifacts(), tests.GradleRepo+"/*", "build.name="+tests.GradleBuildName+";build.number="+buildNumber, t)
artifactoryCli.Exec("bp", tests.GradleBuildName, buildNumber)
buildInfo, _ := inttestutils.GetBuildInfo(artifactoryDetails.Url, tests.GradleBuildName, buildNumber, t, artHttpDetails)
validateBuildInfo(buildInfo, t, 0, 1, ":minimal-example:1.0")
cleanGradleTest()
}
func TestGradleBuildWithServerIDWithUsesPlugin(t *testing.T) {
initGradleTest(t)
buildGradlePath := createGradleProject(t, "projectwithplugin")
configFilePath := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "buildspecs", tests.GradleServerIDUsesPluginConfig)
configFilePath, err := tests.ReplaceTemplateVariables(configFilePath, "")
assert.NoError(t, err)
buildNumber := "1"
runAndValidateGradle(buildGradlePath, configFilePath, tests.GradleBuildName, buildNumber, t)
artifactoryCli.Exec("bp", tests.GradleBuildName, buildNumber)
buildInfo, _ := inttestutils.GetBuildInfo(artifactoryDetails.Url, tests.GradleBuildName, buildNumber, t, artHttpDetails)
validateBuildInfo(buildInfo, t, 0, 1, ":minimal-example:1.0")
cleanGradleTest()
}
// This test check legacy behavior whereby the Gradle config yml contains the username, url and password.
func TestGradleBuildWithCredentials(t *testing.T) {
initGradleTest(t)
if *tests.RtAccessToken != "" {
origUsername, origPassword := tests.SetBasicAuthFromAccessToken(t)
defer func() {
*tests.RtUser = origUsername
*tests.RtPassword = origPassword
}()
}
buildNumber := "1"
buildGradlePath := createGradleProject(t, "gradleproject")
srcConfigTemplate := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "buildspecs", tests.GradleUsernamePasswordTemplate)
configFilePath, err := tests.ReplaceTemplateVariables(srcConfigTemplate, "")
assert.NoError(t, err)
runAndValidateGradle(buildGradlePath, configFilePath, tests.GradleBuildName, buildNumber, t)
artifactoryCli.Exec("bp", tests.GradleBuildName, buildNumber)
buildInfo, _ := inttestutils.GetBuildInfo(artifactoryDetails.Url, tests.GradleBuildName, buildNumber, t, artHttpDetails)
validateBuildInfo(buildInfo, t, 0, 1, ":minimal-example:1.0")
cleanGradleTest()
}
func runAndValidateGradle(buildGradlePath, configFilePath, buildName, buildNumber string, t *testing.T) {
runCliWithLegacyBuildtoolsCmd(t, "gradle", "clean artifactoryPublish -b "+buildGradlePath, configFilePath, "--build-name="+buildName, "--build-number="+buildNumber)
searchSpec, err := tests.CreateSpec(tests.SearchAllGradle)
assert.NoError(t, err)
verifyExistInArtifactory(tests.GetGradleDeployedArtifacts(), searchSpec, t)
verifyExistInArtifactoryByProps(tests.GetGradleDeployedArtifacts(), tests.GradleRepo+"/*", "build.name="+buildName+";build.number="+buildNumber, t)
}
func createGradleProject(t *testing.T, projectName string) string {
srcBuildFile := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "gradle", projectName, "build.gradle")
buildGradlePath, err := tests.ReplaceTemplateVariables(srcBuildFile, "")
assert.NoError(t, err)
srcSettingsFile := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "gradle", projectName, "settings.gradle")
_, err = tests.ReplaceTemplateVariables(srcSettingsFile, "")
assert.NoError(t, err)
return buildGradlePath
}
func initGradleTest(t *testing.T) {
if !*tests.TestGradle {
t.Skip("Skipping Gradle test. To run Gradle test add the '-test.gradle=true' option.")
}
createJfrogHomeConfig(t, true)
}