forked from SAP/jenkins-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransportRequestUploadRFC_test.go
141 lines (120 loc) · 3.93 KB
/
transportRequestUploadRFC_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
package cmd
import (
"fmt"
"github.com/SAP/jenkins-library/pkg/mock"
"github.com/SAP/jenkins-library/pkg/transportrequest/rfc"
"github.com/stretchr/testify/assert"
"testing"
)
type transportRequestUploadRFCMockUtils struct {
*mock.ExecMockRunner
}
func newTransportRequestUploadRFCTestsUtils() transportRequestUploadRFCMockUtils {
utils := transportRequestUploadRFCMockUtils{
ExecMockRunner: &mock.ExecMockRunner{},
}
return utils
}
type uploadMock struct {
received rfc.UploadAction
uploadCalled bool
failWith error
}
// WithApplicationURL The location of the deployable
func (m *uploadMock) WithApplicationURL(z string) {
m.received.ApplicationURL = z
}
// WithTransportRequestID The transport request ID for the upload
func (m *uploadMock) WithTransportRequestID(t string) {
m.received.TransportRequestID = t
}
// WithApplication Everything we need to know about the application
func (m *uploadMock) WithApplication(a rfc.Application) {
m.received.Application = a
}
// WithConfiguration Everything we need to know in order to perform the upload
func (m *uploadMock) WithConfiguration(c rfc.UploadConfig) {
m.received.Configuration = c
}
// WithConnection Everything we need to know about the connection
func (m *uploadMock) WithConnection(c rfc.Connection) {
m.received.Connection = c
}
func (m *uploadMock) Perform(exec rfc.Exec) error {
m.uploadCalled = true
return m.failWith
}
type configMock struct {
config *transportRequestUploadRFCOptions
}
func TestTrRfcRunTransportRequestUpload(t *testing.T) {
t.Parallel()
t.Run("good", func(t *testing.T) {
t.Parallel()
utils := newTransportRequestUploadRFCTestsUtils()
configMock := newRfcConfigMock()
actionMock := uploadMock{}
cpe := &transportRequestUploadRFCCommonPipelineEnvironment{}
err := runTransportRequestUploadRFC(configMock.config, &actionMock, nil, utils, cpe)
if assert.NoError(t, err) {
t.Run("upload triggered", func(t *testing.T) {
assert.True(t, actionMock.uploadCalled)
})
t.Run("parameters has been marshalled", func(t *testing.T) {
assert.Equal(t, rfc.UploadAction{
Connection: rfc.Connection{
Endpoint: "https://my.abap.server",
Client: "001",
Instance: "00",
User: "me",
Password: "******",
},
Application: rfc.Application{
Name: "MyApp",
Description: "Lorem impsum",
AbapPackage: "ABC",
},
Configuration: rfc.UploadConfig{
AcceptUnixStyleEndOfLine: true,
CodePage: "UTF-8",
FailUploadOnWarning: true,
Verbose: false, // comes from general config
},
TransportRequestID: "K12345678",
ApplicationURL: "http://example.org/myDeployable.zip",
}, actionMock.received)
assert.Equal(t, cpe.custom.transportRequestID, "K12345678")
})
}
})
t.Run("bad", func(t *testing.T) {
t.Parallel()
t.Run("Error during deployment", func(t *testing.T) {
utilsMock := newTransportRequestUploadSOLMANTestsUtils(0)
configMock := newRfcConfigMock()
actionMock := uploadMock{failWith: fmt.Errorf("upload failed")}
cpe := &transportRequestUploadRFCCommonPipelineEnvironment{}
err := runTransportRequestUploadRFC(configMock.config, &actionMock, nil, utilsMock, cpe)
assert.Error(t, err, "upload failed")
})
})
}
func newRfcConfigMock() *configMock {
return &configMock{
config: &transportRequestUploadRFCOptions{
Endpoint: "https://my.abap.server",
Client: "001",
Instance: "00",
Username: "me",
Password: "******",
ApplicationName: "MyApp",
ApplicationDescription: "Lorem impsum",
AbapPackage: "ABC",
ApplicationURL: "http://example.org/myDeployable.zip",
CodePage: "UTF-8",
AcceptUnixStyleLineEndings: true,
FailUploadOnWarning: true,
TransportRequestID: "K12345678",
},
}
}