-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupgrade_test.go
More file actions
53 lines (50 loc) · 1.77 KB
/
Copy pathupgrade_test.go
File metadata and controls
53 lines (50 loc) · 1.77 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
package commands_test
import (
"context"
"testing"
"github.com/loilo-inc/canarycage/v6/cli/cage/cageapp"
"github.com/loilo-inc/canarycage/v6/cli/cage/commands"
"github.com/loilo-inc/canarycage/v6/mocks/mock_types"
"github.com/loilo-inc/canarycage/v6/types"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli/v3"
"go.uber.org/mock/gomock"
)
func TestUpgrade(t *testing.T) {
t.Run("Upgrade", func(t *testing.T) {
app := &cli.Command{}
ctrl := gomock.NewController(t)
u := mock_types.NewMockUpgrade(ctrl)
u.EXPECT().Upgrade(gomock.Any()).Return(nil)
app.Commands = []*cli.Command{
commands.Upgrade(&cageapp.UpgradeCmdInput{}, func(_Ctx context.Context, _Input *cageapp.UpgradeCmdInput) (types.Upgrade, error) {
return u, nil
}),
}
err := app.Run(context.Background(), []string{"cage", "upgrade"})
assert.NoError(t, err)
})
t.Run("Upgrade with pre-release", func(t *testing.T) {
app := &cli.Command{}
ctrl := gomock.NewController(t)
u := mock_types.NewMockUpgrade(ctrl)
u.EXPECT().Upgrade(gomock.Any()).Return(nil)
app.Commands = []*cli.Command{
commands.Upgrade(&cageapp.UpgradeCmdInput{PreRelease: true}, func(_Ctx context.Context, _Input *cageapp.UpgradeCmdInput) (types.Upgrade, error) {
return u, nil
}),
}
err := app.Run(context.Background(), []string{"cage", "upgrade", "--pre-release"})
assert.NoError(t, err)
})
t.Run("should return error when provider fails", func(t *testing.T) {
app := &cli.Command{}
app.Commands = []*cli.Command{
commands.Upgrade(&cageapp.UpgradeCmdInput{}, func(_Ctx context.Context, _Input *cageapp.UpgradeCmdInput) (types.Upgrade, error) {
return nil, assert.AnError
}),
}
err := app.Run(context.Background(), []string{"cage", "upgrade"})
assert.Equal(t, assert.AnError, err)
})
}