This repository has been archived by the owner on Jun 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
workspace.go
156 lines (131 loc) · 6.63 KB
/
workspace.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
package workspacetype
import (
"fmt"
"strings"
"time"
g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"
e2e "k8s.io/kubernetes/test/e2e/framework"
exutil "github.com/kcp-dev/kcp-tests/test/extended/util"
)
var _ = g.Describe("[area/workspaces]", func() {
defer g.GinkgoRecover()
var (
k = exutil.NewCLIWithWorkSpace("kcp-workspace")
)
g.It("Author:pewang-Medium-[Smoke] Multi levels workspaces lifecycle should work", func() {
g.By("# Create a test workspace as parent workspace")
k.SetupWorkSpace()
parentWorkSpace := k.WorkSpace()
g.By("# Create five child workspaces under the parent workspace")
childWorkSpaces := []exutil.WorkSpace{}
for i := 1; i <= 5; i++ {
g.By(fmt.Sprintf("# Creating child workspace no.%v", i))
k.SetupWorkSpaceWithSpecificPath(parentWorkSpace.ServerURL)
childWorkSpace := k.WorkSpace()
childWorkSpaces = append(childWorkSpaces, childWorkSpace)
}
g.By(`# Check list workspaces command returns all columns`)
output, err := k.WithoutWorkSpaceServer().Run("get").Args("--server="+parentWorkSpace.ParentServerURL, "workspace").Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(output).Should(o.And(
o.ContainSubstring("NAME"),
o.ContainSubstring("TYPE"),
o.ContainSubstring("PHASE"),
o.ContainSubstring("URL"),
))
g.By(`# From the home workspace, I can list only the test "parent workspace" but cannot list the five "child workspaces"`)
homeSubWorkSpaces := k.ListWorkSpacesWithSpecificPath(parentWorkSpace.ParentServerURL)
// NOTE: use ContainSubstring as a workaround to WorkSpace name inequality bug: https://url.corp.redhat.com/1878a60
homeSubWorkSpacesString := strings.Join(homeSubWorkSpaces, ",")
o.Expect(homeSubWorkSpacesString).Should(o.ContainSubstring(parentWorkSpace.Name))
for _, childWorkSpace := range childWorkSpaces {
o.Expect(homeSubWorkSpacesString).ShouldNot(o.ContainSubstring(childWorkSpace.Name))
}
g.By("# From parent workspace, I can list its child workspaces")
parentSubWorkSpaces := k.ListWorkSpacesWithSpecificPath(parentWorkSpace.ServerURL)
// NOTE: use ContainSubstring as a workaround to WorkSpace name inequality bug: https://url.corp.redhat.com/1878a60
parentSubWorkSpacesString := strings.Join(parentSubWorkSpaces, ",")
for _, childWorkSpace := range childWorkSpaces {
o.Expect(parentSubWorkSpacesString).Should(o.ContainSubstring(childWorkSpace.Name))
}
g.By("# Delete child workspaces")
for _, childWorkSpace := range childWorkSpaces {
output, err := k.WithoutWorkSpaceServer().Run("delete").Args("--server="+parentWorkSpace.ServerURL, "workspace", childWorkSpace.Name).Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(output).Should(o.ContainSubstring("deleted"))
o.Eventually(func() string {
workSpaces, _ := k.WithoutWorkSpaceServer().Run("get").Args("--server="+parentWorkSpace.ServerURL, "workspace").Output()
return workSpaces
}, 60*time.Second, 5*time.Second).ShouldNot(o.ContainSubstring(childWorkSpace.Name))
}
g.By("# Delete parent workspace")
output, err = k.WithoutWorkSpaceServer().Run("delete").Args("--server="+parentWorkSpace.ParentServerURL, "workspace", parentWorkSpace.Name).Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(output).Should(o.ContainSubstring("deleted"))
o.Eventually(func() string {
workSpaces, _ := k.WithoutWorkSpaceServer().Run("get").Args("--server="+parentWorkSpace.ParentServerURL, "workspace").Output()
return workSpaces
}, 60*time.Second, 5*time.Second).ShouldNot(o.ContainSubstring(parentWorkSpace.Name))
})
// author: zxiao@redhat.com
g.It("Author:zxiao-Medium-[Serial] I can create context for a specific workspace and use it", func() {
g.By("# Create a test workspace")
k.SetupWorkSpace()
workSpace := k.WorkSpace()
g.By("# Get context before test run")
contextBeforeTestRun, err := k.Run("config").Args("current-context").Output()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("# Create context under this workspace")
err = k.WithoutWorkSpaceServer().Run("kcp").Args("workspace", "create-context", workSpace.Name, "--server="+workSpace.ParentServerURL).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("# Switch to the newly created context")
// NOTE: not doing assertion as to avoid double assertion failures, use DeferCleanup in ginkgo v2.0 in the future
defer func() {
err = k.Run("config").Args("use-context", contextBeforeTestRun).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
k.Run("config").Args("delete-context", workSpace.Name).Execute()
}()
err = k.Run("config").Args("use-context", workSpace.Name).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("# Check current context name")
currentContext, err := k.Run("config").Args("current-context").Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(currentContext).To(o.Equal(workSpace.Name))
g.By("# Recreate context, expect to show conflict")
output, err := k.WithoutWorkSpaceServer().Run("kcp").Args("workspace", "create-context", workSpace.Name, "--server="+workSpace.ParentServerURL).Output()
o.Expect(err).To(o.HaveOccurred())
o.Expect(output).To(o.ContainSubstring("already exists in kubeconfig"))
})
// author: zxiao@redhat.com
g.It("Author:zxiao-Low-[API] Can perform basic commands on custom resources using workspace URL", func() {
g.By("# Create a test workspace")
k.SetupWorkSpace()
serverURL := k.WorkSpace().ServerURL
g.By("# Create an APIResourceSchema in the test workspace")
rsName := "v1.widgets.example.io"
resourceName := "apiresourceschema.apis.kcp.dev/" + rsName
rsTemplate := exutil.FixturePath("testdata", "workspace", "api_rs.yaml")
_, err := exutil.CreateResourceFromTemplate(k, rsTemplate)
o.Expect(err).NotTo(o.HaveOccurred())
g.By("# Enter parent workspace")
err = k.Run("kcp").Args("workspace", "..").Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("# Test get command on the custom resource")
output, err := k.WithoutWorkSpaceServer().Run("get").Args(resourceName, "--server="+serverURL).Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(output).Should(o.ContainSubstring(rsName))
g.By("# Test delete command on the custom resource")
err = k.WithoutWorkSpaceServer().Run("delete").Args(resourceName, "--server="+serverURL).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("# Run get command on the custom resource")
o.Eventually(func() string {
output, err = k.WithoutWorkSpaceServer().Run("get").Args(resourceName, "--server="+serverURL).Output()
if err != nil {
e2e.Logf("Get %s failed of: %v", resourceName, err)
return "get command failed, try again"
}
return output
}, 60*time.Second, 5*time.Second).Should(o.ContainSubstring("not found"))
})
})