-
Notifications
You must be signed in to change notification settings - Fork 674
/
upgrade_test.go
179 lines (155 loc) · 5.13 KB
/
upgrade_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
167
168
169
170
171
172
173
174
175
176
177
178
179
package upgrade
import (
"sort"
"testing"
cmdCore "github.com/flyteorg/flyte/flytectl/cmd/core"
"github.com/flyteorg/flyte/flytectl/cmd/testutils"
"github.com/flyteorg/flyte/flytectl/pkg/github"
"github.com/flyteorg/flyte/flytectl/pkg/platformutil"
"github.com/flyteorg/flyte/flytectl/pkg/util"
stdlibversion "github.com/flyteorg/flyte/flytestdlib/version"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
)
var (
version = "v0.2.20"
tempExt = "flyte.ext"
)
func TestUpgradeCommand(t *testing.T) {
rootCmd := &cobra.Command{
Long: "Flytectl is a CLI tool written in Go to interact with the FlyteAdmin service.",
Short: "Flytectl CLI tool",
Use: "flytectl",
DisableAutoGenTag: true,
}
upgradeCmd := SelfUpgrade(rootCmd)
cmdCore.AddCommands(rootCmd, upgradeCmd)
assert.Equal(t, len(rootCmd.Commands()), 1)
cmdNouns := rootCmd.Commands()
// Sort by Use value.
sort.Slice(cmdNouns, func(i, j int) bool {
return cmdNouns[i].Use < cmdNouns[j].Use
})
assert.Equal(t, cmdNouns[0].Use, "upgrade")
assert.Equal(t, cmdNouns[0].Short, upgradeCmdShort)
assert.Equal(t, cmdNouns[0].Long, upgradeCmdLong)
}
func TestUpgrade(t *testing.T) {
_ = util.WriteIntoFile([]byte("data"), tempExt)
stdlibversion.Version = version
github.FlytectlReleaseConfig.OverrideExecutable = tempExt
t.Run("Successful upgrade", func(t *testing.T) {
message, err := upgrade(github.FlytectlReleaseConfig)
assert.Nil(t, err)
assert.Contains(t, message, "Successfully updated to version")
})
}
func TestCheckGoosForRollback(t *testing.T) {
stdlibversion.Version = version
linux := platformutil.Linux
windows := platformutil.Windows
darwin := platformutil.Darwin
github.FlytectlReleaseConfig.OverrideExecutable = tempExt
t.Run("checkGOOSForRollback on linux", func(t *testing.T) {
assert.Equal(t, true, isRollBackSupported(linux))
assert.Equal(t, false, isRollBackSupported(windows))
assert.Equal(t, true, isRollBackSupported(darwin))
})
}
func TestIsUpgradeable(t *testing.T) {
stdlibversion.Version = version
github.FlytectlReleaseConfig.OverrideExecutable = tempExt
linux := platformutil.Linux
windows := platformutil.Windows
darwin := platformutil.Darwin
t.Run("IsUpgradeable on linux", func(t *testing.T) {
check, err := isUpgradeSupported(linux)
assert.Nil(t, err)
assert.Equal(t, true, check)
})
t.Run("IsUpgradeable on darwin", func(t *testing.T) {
check, err := isUpgradeSupported(darwin)
assert.Nil(t, err)
assert.Equal(t, true, check)
})
t.Run("IsUpgradeable on darwin using brew", func(t *testing.T) {
check, err := isUpgradeSupported(darwin)
assert.Nil(t, err)
assert.Equal(t, true, check)
})
t.Run("isUpgradeSupported failed", func(t *testing.T) {
stdlibversion.Version = "v"
check, err := isUpgradeSupported(linux)
assert.NotNil(t, err)
assert.Equal(t, false, check)
stdlibversion.Version = version
})
t.Run("isUpgradeSupported windows", func(t *testing.T) {
check, err := isUpgradeSupported(windows)
assert.Nil(t, err)
assert.Equal(t, false, check)
})
}
func TestSelfUpgrade(t *testing.T) {
stdlibversion.Version = version
github.FlytectlReleaseConfig.OverrideExecutable = tempExt
goos = platformutil.Linux
t.Run("Successful upgrade", func(t *testing.T) {
s := testutils.Setup(t)
stdlibversion.Build = ""
stdlibversion.BuildTime = ""
stdlibversion.Version = version
assert.Nil(t, selfUpgrade(s.Ctx, []string{}, s.CmdCtx))
})
}
func TestSelfUpgradeError(t *testing.T) {
stdlibversion.Version = version
github.FlytectlReleaseConfig.OverrideExecutable = tempExt
goos = platformutil.Linux
t.Run("Successful upgrade", func(t *testing.T) {
s := testutils.Setup(t)
stdlibversion.Build = ""
stdlibversion.BuildTime = ""
stdlibversion.Version = "v"
assert.NotNil(t, selfUpgrade(s.Ctx, []string{}, s.CmdCtx))
})
}
func TestSelfUpgradeRollback(t *testing.T) {
stdlibversion.Version = version
github.FlytectlReleaseConfig.OverrideExecutable = tempExt
goos = platformutil.Linux
t.Run("Successful rollback", func(t *testing.T) {
s := testutils.Setup(t)
var args = []string{rollBackSubCommand}
stdlibversion.Build = ""
stdlibversion.BuildTime = ""
stdlibversion.Version = version
assert.Nil(t, selfUpgrade(s.Ctx, args, s.CmdCtx))
})
t.Run("Successful rollback failed", func(t *testing.T) {
s := testutils.Setup(t)
var args = []string{rollBackSubCommand}
stdlibversion.Build = ""
stdlibversion.BuildTime = ""
stdlibversion.Version = "v100.0.0"
assert.NotNil(t, selfUpgrade(s.Ctx, args, s.CmdCtx))
})
t.Run("Successful rollback for windows", func(t *testing.T) {
s := testutils.Setup(t)
var args = []string{rollBackSubCommand}
stdlibversion.Build = ""
stdlibversion.BuildTime = ""
stdlibversion.Version = version
goos = platformutil.Windows
assert.Nil(t, selfUpgrade(s.Ctx, args, s.CmdCtx))
})
t.Run("Successful rollback for windows", func(t *testing.T) {
s := testutils.Setup(t)
var args = []string{rollBackSubCommand}
stdlibversion.Build = ""
stdlibversion.BuildTime = ""
stdlibversion.Version = version
github.FlytectlReleaseConfig.OverrideExecutable = "/"
assert.Nil(t, selfUpgrade(s.Ctx, args, s.CmdCtx))
})
}