forked from SAP/jenkins-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabapEnvironmentAssemblePackages_test.go
166 lines (152 loc) · 4.61 KB
/
abapEnvironmentAssemblePackages_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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package cmd
import (
"testing"
"time"
abapbuild "github.com/SAP/jenkins-library/pkg/abap/build"
"github.com/SAP/jenkins-library/pkg/abaputils"
piperhttp "github.com/SAP/jenkins-library/pkg/http"
"github.com/stretchr/testify/assert"
)
func testSetup(client piperhttp.Sender, buildID string) abapbuild.Build {
conn := new(abapbuild.Connector)
conn.Client = client
conn.DownloadClient = &abapbuild.DownloadClientMock{}
conn.Header = make(map[string][]string)
b := abapbuild.Build{
Connector: *conn,
BuildID: buildID,
}
return b
}
func TestCheckIfFailedAndPrintLogsWithError(t *testing.T) {
t.Run("checkIfFailedAndPrintLogs with failed build", func(t *testing.T) {
var repo abaputils.Repository
b := testSetup(&abapbuild.ClMock{}, "ABIFNLDCSQPOVMXK4DNPBDRW2M")
b.RunState = abapbuild.Failed
var buildsWithRepo []buildWithRepository
bWR := buildWithRepository{
build: b,
repo: repo,
}
buildsWithRepo = append(buildsWithRepo, bWR)
err := checkIfFailedAndPrintLogs(buildsWithRepo)
assert.Error(t, err)
})
t.Run("checkIfFailedAndPrintLogs", func(t *testing.T) {
var repo abaputils.Repository
b := testSetup(&abapbuild.ClMock{}, "ABIFNLDCSQPOVMXK4DNPBDRW2M")
b.RunState = abapbuild.Finished
var buildsWithRepo []buildWithRepository
bWR := buildWithRepository{
build: b,
repo: repo,
}
buildsWithRepo = append(buildsWithRepo, bWR)
err := checkIfFailedAndPrintLogs(buildsWithRepo)
assert.NoError(t, err)
})
}
func TestStartingInvalidInput(t *testing.T) {
t.Run("Run starting with Invalid Input", func(t *testing.T) {
client := &abapbuild.ClMock{
Token: "MyToken",
}
conn := new(abapbuild.Connector)
conn.Client = client
conn.Header = make(map[string][]string)
var repos []abaputils.Repository
repo := abaputils.Repository{
Name: "RepoA",
Status: "P",
}
repos = append(repos, repo)
builds, err := executeBuilds(repos, *conn, time.Duration(0*time.Second), time.Duration(1*time.Millisecond))
assert.NoError(t, err)
assert.Equal(t, 1, len(builds))
assert.Equal(t, abapbuild.Failed, builds[0].build.RunState)
})
}
func TestStep(t *testing.T) {
autils := &abaputils.AUtilsMock{
ReturnedConnectionDetailsHTTP: abaputils.ConnectionDetailsHTTP{
URL: `/sap/opu/odata/BUILD/CORE_SRV`,
},
}
client := abapbuild.GetBuildMockClient()
cpe := &abapEnvironmentAssemblePackagesCommonPipelineEnvironment{}
t.Run("abapEnvironmentAssemblePackages: nothing to do", func(t *testing.T) {
config := &abapEnvironmentAssemblePackagesOptions{
AddonDescriptor: cpeAbapAddonDescriptorPackageLocked,
MaxRuntimeInMinutes: 1,
PollIntervalsInMilliseconds: 1,
}
err := runAbapEnvironmentAssemblePackages(config, nil, autils, &client, cpe)
assert.NoError(t, err)
assert.Contains(t, cpe.abap.addonDescriptor, `"InBuildScope":false`)
})
t.Run("abapEnvironmentAssemblePackages: build", func(t *testing.T) {
config := &abapEnvironmentAssemblePackagesOptions{
AddonDescriptor: cpeAbapAddonDescriptorPackageReserved,
MaxRuntimeInMinutes: 1,
PollIntervalsInMilliseconds: 1,
}
err := runAbapEnvironmentAssemblePackages(config, nil, autils, &client, cpe)
assert.NoError(t, err)
assert.Contains(t, cpe.abap.addonDescriptor, `SAPK-001AAINITAPC1.SAR`)
assert.Contains(t, cpe.abap.addonDescriptor, `"InBuildScope":true`)
})
}
var cpeAbapAddonDescriptorPackageLocked = `{
"addonProduct":"/ITAPC1/I_CURRENCZPRODUCT",
"addonVersion":"1.0.0",
"addonVersionAAK":"0001",
"addonUniqueID":"myAddonId",
"customerID":"$ID",
"AddonSpsLevel":"0000",
"AddonPatchLevel":"0000",
"TargetVectorID":"",
"repositories":[
{ "name":"/ITAPC1/I_CURRENCZ",
"tag":"whatever",
"branch":"",
"commitID":"",
"version":"1.0.0",
"versionAAK":"0001",
"PackageName":"SAPK-002AAINITAPC1",
"PackageType":"AOI",
"SpLevel":"0000",
"PatchLevel":"0000",
"PredecessorCommitID":"",
"Status":"L",
"Namespace":"/ITAPC1/",
"SarXMLFilePath":".pipeline\\commonPipelineEnvironment\\abap\\SAPK-002AAINITAPC1.SAR"
}
]
}`
var cpeAbapAddonDescriptorPackageReserved = `{
"addonProduct":"/ITAPC1/I_CURRENCZPRODUCT",
"addonVersion":"1.0.0",
"addonVersionAAK":"0001",
"addonUniqueID":"myAddonId",
"customerID":"$ID",
"AddonSpsLevel":"0000",
"AddonPatchLevel":"0000",
"TargetVectorID":"",
"repositories":[
{ "name":"/ITAPC1/I_CURRENCZ",
"tag":"whatever",
"branch":"",
"commitID":"",
"version":"1.0.0",
"versionAAK":"0001",
"PackageName":"SAPK-002AAINITAPC1",
"PackageType":"AOI",
"SpLevel":"0000",
"PatchLevel":"0000",
"PredecessorCommitID":"",
"Status":"P",
"Namespace":"/ITAPC1/",
"SarXMLFilePath":""
}
]
}`