-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrelease_app_version_cmd_test.go
More file actions
95 lines (81 loc) · 2.38 KB
/
release_app_version_cmd_test.go
File metadata and controls
95 lines (81 loc) · 2.38 KB
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
package version
import (
"errors"
"testing"
mockversions "github.com/jfrog/jfrog-cli-application/apptrust/service/versions/mocks"
"go.uber.org/mock/gomock"
"github.com/jfrog/jfrog-cli-application/apptrust/model"
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/stretchr/testify/assert"
)
func TestReleaseAppVersionCommand_Run(t *testing.T) {
tests := []struct {
name string
sync bool
}{
{
name: "sync flag true",
sync: true,
},
{
name: "sync flag false",
sync: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
serverDetails := &config.ServerDetails{Url: "https://example.com"}
applicationKey := "app-key"
version := "1.0.0"
requestPayload := model.NewReleaseAppVersionRequest(
model.PromotionTypeCopy,
nil, // includedRepos
nil, // excludedRepos
nil, // artifactProps
)
mockVersionService := mockversions.NewMockVersionService(ctrl)
mockVersionService.EXPECT().ReleaseAppVersion(gomock.Any(), applicationKey, version, requestPayload, tt.sync).
Return(nil).Times(1)
cmd := &releaseAppVersionCommand{
versionService: mockVersionService,
serverDetails: serverDetails,
applicationKey: applicationKey,
version: version,
requestPayload: requestPayload,
sync: tt.sync,
}
err := cmd.Run()
assert.NoError(t, err)
})
}
}
func TestReleaseAppVersionCommand_Run_Error(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
serverDetails := &config.ServerDetails{Url: "https://example.com"}
applicationKey := "app-key"
version := "1.0.0"
requestPayload := model.NewReleaseAppVersionRequest(
model.PromotionTypeCopy,
nil, // includedRepos
nil, // excludedRepos
nil, // artifactProps
)
expectedError := errors.New("service error occurred")
mockVersionService := mockversions.NewMockVersionService(ctrl)
mockVersionService.EXPECT().ReleaseAppVersion(gomock.Any(), applicationKey, version, requestPayload, false).
Return(expectedError).Times(1)
cmd := &releaseAppVersionCommand{
versionService: mockVersionService,
serverDetails: serverDetails,
applicationKey: applicationKey,
version: version,
requestPayload: requestPayload,
sync: false,
}
err := cmd.Run()
assert.Error(t, err)
assert.Contains(t, err.Error(), "service error occurred")
}