forked from kyma-project/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupgrade_test.go
126 lines (109 loc) · 3.75 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
package installation
import (
"errors"
"testing"
"time"
installSDK "github.com/kyma-incubator/hydroform/install/installation"
k8sMocks "github.com/kyma-project/cli/internal/kube/mocks"
"github.com/kyma-project/cli/pkg/installation/mocks"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
networkingv1alpha3 "istio.io/api/networking/v1alpha3"
"istio.io/client-go/pkg/apis/networking/v1alpha3"
fakeIstio "istio.io/client-go/pkg/clientset/versioned/fake"
v1 "k8s.io/api/core/v1"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/fake"
"k8s.io/client-go/rest"
)
func TestUpgradeKyma(t *testing.T) {
t.Parallel()
// prepare mocks
kymaMock := k8sMocks.KymaKube{}
iServiceMock := mocks.Service{}
// fake k8s with installer pod running and post installation resources
k8sMock := fake.NewSimpleClientset(
&v1.Pod{
ObjectMeta: metaV1.ObjectMeta{Name: "kyma-installer", Namespace: "kyma-installer", Labels: map[string]string{"name": "kyma-installer"}},
Status: v1.PodStatus{Phase: v1.PodRunning},
Spec: v1.PodSpec{
Containers: []v1.Container{
{
Name: "Installer",
Image: "fake-registry/installer:1.15.0",
},
},
},
},
&v1.Secret{
ObjectMeta: metaV1.ObjectMeta{
Name: "admin-user",
Namespace: "kyma-system",
},
Data: map[string][]byte{
"email": []byte("[email protected]"),
"password": []byte("1234-super-secure"),
},
},
)
// fake istio vService
istioMock := fakeIstio.NewSimpleClientset(
&v1alpha3.VirtualService{
ObjectMeta: metaV1.ObjectMeta{
Name: "console-web",
Namespace: "kyma-system",
},
Spec: networkingv1alpha3.VirtualService{
Hosts: []string{"fake-console-url"},
},
},
)
kymaMock.On("Static").Return(k8sMock)
kymaMock.On("Istio").Return(istioMock)
kymaMock.On("RestConfig", mock.Anything).Return(&rest.Config{Host: "fake-kubeconfig-host"})
kymaMock.On("WaitPodStatusByLabel", "kyma-installer", "name", "kyma-installer", v1.PodRunning).Return(nil)
i := &Installation{
K8s: &kymaMock,
Service: &iServiceMock,
Options: &Options{
NoWait: false,
NonInteractive: true,
Timeout: 10 * time.Minute,
Domain: "irrelevant",
TLSCert: "fake-cert",
TLSKey: "fake-key",
Password: "fake-password",
OverrideConfigs: nil,
ComponentsConfig: "",
IsLocal: false,
Source: "1.15.1",
},
}
// Happy path
iServiceMock.On("CheckInstallationState", mock.Anything).Return(installSDK.InstallationState{State: "Installed"}, nil).Times(3)
iServiceMock.On("TriggerUpgrade", mock.Anything, mock.Anything, mock.Anything).Return(nil)
r, err := i.UpgradeKyma()
require.NoError(t, err)
require.NotEmpty(t, r)
// Installation in progress
i.Options.NoWait = true // no need to wait for upgrade in all test cases from here on
iServiceMock.On("CheckInstallationState", mock.Anything).Return(installSDK.InstallationState{State: "InProgress"}, nil).Once()
r, err = i.UpgradeKyma()
require.NoError(t, err)
require.Empty(t, r)
// No Kyma on cluster
iServiceMock.On("CheckInstallationState", mock.Anything).Return(installSDK.InstallationState{State: installSDK.NoInstallationState}, nil).Once()
r, err = i.UpgradeKyma()
require.Error(t, err)
require.Empty(t, r)
// Error getting installation status
iServiceMock.On("CheckInstallationState", mock.Anything).Return(installSDK.InstallationState{}, errors.New("installation is hiding from us")).Once()
r, err = i.UpgradeKyma()
require.Error(t, err)
require.Empty(t, r)
// Empty installation status
iServiceMock.On("CheckInstallationState", mock.Anything).Return(installSDK.InstallationState{}, nil).Once()
r, err = i.UpgradeKyma()
require.Error(t, err)
require.Empty(t, r)
}