forked from jfrog/jfrog-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaven_test.go
96 lines (84 loc) · 2.81 KB
/
maven_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
package main
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/jfrog/jfrog-cli-go/artifactory/commands/mvn"
"github.com/jfrog/jfrog-cli-go/artifactory/utils"
"github.com/jfrog/jfrog-cli-go/utils/tests"
)
const mavenFlagName = "maven"
func TestMavenBuildWithServerID(t *testing.T) {
initMavenTest(t)
pomPath := createMavenProject(t)
configFilePath := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "buildspecs", tests.MavenServerIDConfig)
configFilePath, err := tests.ReplaceTemplateVariables(configFilePath, "")
if err != nil {
t.Error(err)
}
runAndValidateMaven(pomPath, configFilePath, t)
cleanBuildToolsTest()
}
func TestNativeMavenBuildWithServerID(t *testing.T) {
initMavenTest(t)
pomPath := createMavenProject(t)
configFilePath := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "buildspecs", tests.MavenConfig)
destPath := filepath.Join(filepath.Dir(pomPath), ".jfrog", "projects")
createConfigFile(destPath, configFilePath, t)
oldHomeDir := changeWD(t, filepath.Dir(pomPath))
pomPath = strings.Replace(pomPath, `\`, "/", -1) // Windows compatibility.
runCli(t, "mvn", "clean", "install", "-f", pomPath)
err := os.Chdir(oldHomeDir)
if err != nil {
t.Error(err)
}
// Validate
searchSpec, err := tests.CreateSpec(tests.SearchAllRepo1)
if err != nil {
t.Error(err)
}
isExistInArtifactory(tests.GetMavenDeployedArtifacts(), searchSpec, t)
cleanBuildToolsTest()
}
func TestMavenBuildWithCredentials(t *testing.T) {
if *tests.RtUser == "" || *tests.RtPassword == "" {
t.SkipNow()
}
initMavenTest(t)
pomPath := createMavenProject(t)
srcConfigTemplate := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "buildspecs", tests.MavenUsernamePasswordTemplate)
configFilePath, err := tests.ReplaceTemplateVariables(srcConfigTemplate, "")
if err != nil {
t.Error(err)
}
runAndValidateMaven(pomPath, configFilePath, t)
cleanBuildToolsTest()
}
func runAndValidateMaven(pomPath, configFilePath string, t *testing.T) {
buildConfig := &utils.BuildConfiguration{}
mvnCmd := mvn.NewMvnCommand().SetConfiguration(buildConfig).SetGoals("clean install -f" + pomPath).SetConfigPath(configFilePath)
err := mvnCmd.Run()
if err != nil {
t.Error(err)
}
searchSpec, err := tests.CreateSpec(tests.SearchAllRepo1)
if err != nil {
t.Error(err)
}
isExistInArtifactory(tests.GetMavenDeployedArtifacts(), searchSpec, t)
}
func createMavenProject(t *testing.T) string {
srcPomFile := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "mavenproject", "pom.xml")
pomPath, err := tests.ReplaceTemplateVariables(srcPomFile, "")
if err != nil {
t.Error(err)
}
return pomPath
}
func initMavenTest(t *testing.T) {
if !*tests.TestMaven {
t.Skip("Skipping Maven test. To run Maven test add the '-test.maven=true' option.")
}
createJfrogHomeConfig(t)
}