Skip to content

Commit c55d722

Browse files
committed
Bind package to application command
1 parent a726609 commit c55d722

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package packagecmds
2+
3+
import (
4+
"errors"
5+
"testing"
6+
7+
"github.com/jfrog/jfrog-cli-application/apptrust/model"
8+
mockpackages "github.com/jfrog/jfrog-cli-application/apptrust/service/packages/mocks"
9+
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
10+
"github.com/stretchr/testify/assert"
11+
"go.uber.org/mock/gomock"
12+
)
13+
14+
func TestBindPackageCommand_Run(t *testing.T) {
15+
ctrl := gomock.NewController(t)
16+
defer ctrl.Finish()
17+
18+
serverDetails := &config.ServerDetails{Url: "https://example.com"}
19+
requestPayload := &model.BindPackageRequest{
20+
ApplicationKey: "app-key",
21+
Type: "npm",
22+
Name: "test-package",
23+
Version: "1.0.0",
24+
}
25+
26+
mockPackageService := mockpackages.NewMockPackageService(ctrl)
27+
mockPackageService.EXPECT().BindPackage(gomock.Any(), requestPayload).
28+
Return(nil).Times(1)
29+
30+
cmd := &bindPackageCommand{
31+
packageService: mockPackageService,
32+
serverDetails: serverDetails,
33+
requestPayload: requestPayload,
34+
}
35+
36+
err := cmd.Run()
37+
assert.NoError(t, err)
38+
}
39+
40+
func TestBindPackageCommand_Run_Error(t *testing.T) {
41+
ctrl := gomock.NewController(t)
42+
defer ctrl.Finish()
43+
44+
serverDetails := &config.ServerDetails{Url: "https://example.com"}
45+
requestPayload := &model.BindPackageRequest{
46+
ApplicationKey: "app-key",
47+
Type: "npm",
48+
Name: "test-package",
49+
Version: "1.0.0",
50+
}
51+
52+
mockPackageService := mockpackages.NewMockPackageService(ctrl)
53+
mockPackageService.EXPECT().BindPackage(gomock.Any(), requestPayload).
54+
Return(errors.New("bind error")).Times(1)
55+
56+
cmd := &bindPackageCommand{
57+
packageService: mockPackageService,
58+
serverDetails: serverDetails,
59+
requestPayload: requestPayload,
60+
}
61+
62+
err := cmd.Run()
63+
assert.Error(t, err)
64+
assert.Equal(t, "bind error", err.Error())
65+
}

0 commit comments

Comments
 (0)