-
Notifications
You must be signed in to change notification settings - Fork 89
/
jenkins_test.go
114 lines (97 loc) · 2.91 KB
/
jenkins_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
package gojenkins
import (
"fmt"
"testing"
"time"
)
func NewJenkinsWithTestData() *Jenkins {
var auth Auth
return NewJenkins(&auth, "http://example.com")
}
func Test(t *testing.T) {
jenkins := NewJenkinsWithTestData()
jobs, err := jenkins.GetJobs()
if err != nil {
t.Errorf("error %v\n", err)
}
if len(jobs) == 0 {
t.Errorf("return no jobs\n")
}
}
func TestAddJobToView(t *testing.T) {
jenkins := NewJenkinsWithTestData()
scm := Scm{
Class: "hudson.scm.SubversionSCM",
}
jobItem := MavenJobItem{
Plugin: "[email protected]",
Description: "test description",
Scm: scm,
Triggers: Triggers{},
RunPostStepsIfResult: RunPostStepsIfResult{},
Settings: JobSettings{Class: "jenkins.mvn.DefaultSettingsProvider"},
GlobalSettings: JobSettings{Class: "jenkins.mvn.DefaultSettingsProvider"},
}
newJobName := fmt.Sprintf("test-with-view-%d", time.Now().UnixNano())
newViewName := fmt.Sprintf("test-view-%d", time.Now().UnixNano())
jenkins.CreateJob(jobItem, newJobName)
jenkins.CreateView(NewListView(newViewName))
job := Job{Name: newJobName}
err := jenkins.AddJobToView(newViewName, job)
if err != nil {
t.Errorf("error %v\n", err)
}
}
func TestCreateView(t *testing.T) {
jenkins := NewJenkinsWithTestData()
newViewName := fmt.Sprintf("test-view-%d", time.Now().UnixNano())
err := jenkins.CreateView(NewListView(newViewName))
if err != nil {
t.Errorf("error %v\n", err)
}
}
func TestCreateJobItem(t *testing.T) {
jenkins := NewJenkinsWithTestData()
scm := Scm{
ScmContent: ScmSvn{
Locations: Locations{
[]ScmSvnLocation{
ScmSvnLocation{IgnoreExternalsOption: "false", DepthOption: "infinity", Local: ".", Remote: "http://some-svn-url"},
},
},
IgnoreDirPropChanges: "false",
FilterChangelog: "false",
WorkspaceUpdater: WorkspaceUpdater{Class: "hudson.scm.subversion.UpdateUpdater"},
},
Class: "hudson.scm.SubversionSCM",
Plugin: "[email protected]",
}
triggers := Triggers{[]Trigger{ScmTrigger{}}}
postStep := RunPostStepsIfResult{Name: "FAILURE", Ordinal: "2", Color: "RED", CompleteBuild: "true"}
settings := JobSettings{Class: "jenkins.mvn.DefaultSettingsProvider"}
globalSettings := JobSettings{Class: "jenkins.mvn.DefaultSettingsProvider"}
jobItem := MavenJobItem{
Plugin: "[email protected]",
Description: "test description",
Scm: scm,
Triggers: triggers,
RunPostStepsIfResult: postStep,
Settings: settings,
GlobalSettings: globalSettings,
}
newJobName := fmt.Sprintf("test-%d", time.Now().UnixNano())
err := jenkins.CreateJob(jobItem, newJobName)
if err != nil {
t.Errorf("error %v\n", err)
}
jobs, _ := jenkins.GetJobs()
foundNewJob := false
for _, v := range jobs {
if v.Name == newJobName {
foundNewJob = true
}
}
if !foundNewJob {
t.Errorf("error %s not found\n", newJobName)
}
}