forked from kyma-project/kyma
/
microfrontend.go
110 lines (94 loc) · 3.29 KB
/
microfrontend.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
package backupe2e
import (
"fmt"
"time"
"github.com/google/uuid"
. "github.com/smartystreets/goconvey/convey"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
uiV1alpha1v "github.com/kyma-project/kyma/common/microfrontend-client/pkg/apis/ui/v1alpha1"
mfClient "github.com/kyma-project/kyma/common/microfrontend-client/pkg/client/clientset/versioned"
"github.com/kyma-project/kyma/tests/end-to-end/backup-restore-test/utils/config"
)
type microfrontendTest struct {
microforntendName, uuid string
mfClient *mfClient.Clientset
coreClient *kubernetes.Clientset
}
func NewMicrofrontendTest() (microfrontendTest, error) {
restConfig, err := config.NewRestClientConfig()
if err != nil {
return microfrontendTest{}, err
}
mfClient, err := mfClient.NewForConfig(restConfig)
if err != nil {
return microfrontendTest{}, err
}
coreClient, err := kubernetes.NewForConfig(restConfig)
if err != nil {
return microfrontendTest{}, err
}
return microfrontendTest{
mfClient: mfClient,
coreClient: coreClient,
microforntendName: "test-mf",
uuid: uuid.New().String(),
}, nil
}
func (t microfrontendTest) CreateResources(namespace string) {
_, err := t.createMicrofrontend(namespace)
So(err, ShouldBeNil)
}
func (t microfrontendTest) TestResources(namespace string) {
mfs, err := t.getMicrofrontends(namespace, 2*time.Minute)
So(err, ShouldBeNil)
mfValue := mfs.Items[0]
So(mfValue.Name, ShouldEqual, t.microforntendName)
So(mfValue.Spec.Category, ShouldEqual, "Test")
So(mfValue.Spec.Version, ShouldEqual, "1")
So(mfValue.Spec.ViewBaseURL, ShouldEqual, "https://test.kyma.cx/mf-test")
So(len(mfValue.Spec.NavigationNodes), ShouldEqual, 1)
navNode := mfValue.Spec.NavigationNodes[0]
So(navNode.Label, ShouldEqual, "testMF")
So(navNode.NavigationPath, ShouldEqual, "path")
So(navNode.ViewURL, ShouldEqual, "/resourcePath")
So(navNode.ShowInNavigation, ShouldEqual, true)
}
func (t microfrontendTest) DeleteResources(namespace string) {
// There is not need to be implemented for this test.
}
func (t microfrontendTest) createMicrofrontend(namespace string) (*uiV1alpha1v.MicroFrontend, error) {
microfrontend := &uiV1alpha1v.MicroFrontend{
TypeMeta: metav1.TypeMeta{
APIVersion: "ui.kyma-project.io/v1alpha1",
Kind: "MicroFrontend",
},
ObjectMeta: metav1.ObjectMeta{
Name: t.microforntendName,
},
Spec: uiV1alpha1v.MicroFrontendSpec{
CommonMicroFrontendSpec: uiV1alpha1v.CommonMicroFrontendSpec{
Version: "1",
Category: "Test",
ViewBaseURL: "https://test.kyma.cx/mf-test",
NavigationNodes: []uiV1alpha1v.NavigationNode{
uiV1alpha1v.NavigationNode{
Label: "testMF",
NavigationPath: "path",
ViewURL: "/resourcePath",
ShowInNavigation: true,
},
},
},
},
}
return t.mfClient.UiV1alpha1().MicroFrontends(namespace).Create(microfrontend)
}
func (t microfrontendTest) getMicrofrontends(namespace string, waitmax time.Duration) (*uiV1alpha1v.MicroFrontendList, error) {
mfs, err := t.mfClient.UiV1alpha1().MicroFrontends(namespace).List(metav1.ListOptions{})
So(err, ShouldBeNil)
if 1 != int32(len(mfs.Items)) {
return nil, fmt.Errorf("Expected only one microfrontend, but got %v", len(mfs.Items))
}
return mfs, err
}