mirror of
https://github.com/kubevela/kubevela.git
synced 2026-02-14 18:10:21 +00:00
add back the test after the cue templates are updated (#328)
* add back the test * enhance e2e test
This commit is contained in:
@@ -3,6 +3,7 @@ package e2e
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/oam-dev/kubevela/api/types"
|
||||
"github.com/oam-dev/kubevela/e2e"
|
||||
"github.com/oam-dev/kubevela/pkg/server/apis"
|
||||
|
||||
@@ -15,12 +16,16 @@ var (
|
||||
Name: "capability-center-e2e-basic",
|
||||
URL: "https://github.com/oam-dev/kubevela/tree/master/pkg/plugins/testdata",
|
||||
}
|
||||
/*
|
||||
capabilityBasic = types.Capability{
|
||||
Name: "manualscaler",
|
||||
Type: types.TypeTrait,
|
||||
}
|
||||
*/
|
||||
|
||||
scaleCapability = types.Capability{
|
||||
Name: "scale",
|
||||
Type: types.TypeTrait,
|
||||
}
|
||||
|
||||
routeCapability = types.Capability{
|
||||
Name: "route",
|
||||
Type: types.TypeTrait,
|
||||
}
|
||||
)
|
||||
|
||||
var _ = ginkgo.Describe("Capability", func() {
|
||||
@@ -46,28 +51,27 @@ var _ = ginkgo.Describe("Capability", func() {
|
||||
})
|
||||
|
||||
ginkgo.Context("capability", func() {
|
||||
// TODO: revert after the PR is merged
|
||||
/*
|
||||
ginkgo.It("install a capability to cluster", func() {
|
||||
cli := fmt.Sprintf("vela cap add %s/%s", capabilityCenterBasic.Name, capabilityBasic.Name)
|
||||
output, err := e2e.Exec(cli)
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
expectedSubStr1 := fmt.Sprintf("Installing %s capability", capabilityBasic.Type)
|
||||
expectedSubStr2 := fmt.Sprintf("Successfully installed capability %s from %s", capabilityBasic.Name, capabilityCenterBasic.Name)
|
||||
gomega.Expect(output).To(gomega.ContainSubstring(expectedSubStr1))
|
||||
gomega.Expect(output).To(gomega.ContainSubstring(expectedSubStr2))
|
||||
})
|
||||
ginkgo.It("install a capability to cluster", func() {
|
||||
cli := fmt.Sprintf("vela cap add %s/%s", capabilityCenterBasic.Name, scaleCapability.Name)
|
||||
output, err := e2e.Exec(cli)
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
expectedSubStr1 := fmt.Sprintf("Installing %s capability", scaleCapability.Type)
|
||||
expectedSubStr2 := fmt.Sprintf("Successfully installed capability %s from %s", scaleCapability.Name, capabilityCenterBasic.Name)
|
||||
gomega.Expect(output).To(gomega.ContainSubstring(expectedSubStr1))
|
||||
gomega.Expect(output).To(gomega.ContainSubstring(expectedSubStr2))
|
||||
})
|
||||
|
||||
ginkgo.It("list all capabilities", func() {
|
||||
cli := fmt.Sprintf("vela cap ls %s", capabilityCenterBasic.Name)
|
||||
output, err := e2e.Exec(cli)
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
gomega.Expect(output).To(gomega.ContainSubstring("NAME"))
|
||||
gomega.Expect(output).To(gomega.ContainSubstring("CENTER"))
|
||||
gomega.Expect(output).To(gomega.ContainSubstring(scaleCapability.Name))
|
||||
gomega.Expect(output).To(gomega.ContainSubstring(routeCapability.Name))
|
||||
gomega.Expect(output).To(gomega.ContainSubstring("installed"))
|
||||
})
|
||||
|
||||
ginkgo.It("list all capabilities", func() {
|
||||
cli := fmt.Sprintf("vela cap ls %s", capabilityCenterBasic.Name)
|
||||
output, err := e2e.Exec(cli)
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
gomega.Expect(output).To(gomega.ContainSubstring("NAME"))
|
||||
gomega.Expect(output).To(gomega.ContainSubstring("CENTER"))
|
||||
gomega.Expect(output).To(gomega.ContainSubstring(capabilityBasic.Name))
|
||||
gomega.Expect(output).To(gomega.ContainSubstring("installed"))
|
||||
})
|
||||
*/
|
||||
ginkgo.It("delete a capability center", func() {
|
||||
cli := fmt.Sprintf("vela cap center remove %s", capabilityCenterBasic.Name)
|
||||
output, err := e2e.Exec(cli)
|
||||
|
||||
@@ -19,6 +19,19 @@ import (
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
)
|
||||
|
||||
func GetCapabilitiesFromCluster(ctx context.Context, namespace string, c client.Client, syncDir string, selector labels.Selector) ([]types.Capability, error) {
|
||||
workloads, err := GetWorkloadsFromCluster(ctx, namespace, c, syncDir, selector)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
traits, err := GetTraitsFromCluster(ctx, namespace, c, syncDir, selector)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
workloads = append(workloads, traits...)
|
||||
return workloads, nil
|
||||
}
|
||||
|
||||
func GetWorkloadsFromCluster(ctx context.Context, namespace string, c client.Client, syncDir string, selector labels.Selector) ([]types.Capability, error) {
|
||||
var templates []types.Capability
|
||||
var workloadDefs corev1alpha2.WorkloadDefinitionList
|
||||
|
||||
@@ -30,71 +30,70 @@ var _ = Describe("DefinitionFiles", func() {
|
||||
},
|
||||
CrdName: "routes.test",
|
||||
}
|
||||
// TODO: revert after the PR is merged
|
||||
/*
|
||||
deployment := types.Capability{
|
||||
Name: "deployment",
|
||||
Type: types.TypeWorkload,
|
||||
CrdName: "deployments.testapps",
|
||||
Parameters: []types.Parameter{
|
||||
{
|
||||
Name: "name",
|
||||
Required: true,
|
||||
Type: cue.StringKind,
|
||||
Default: "",
|
||||
},
|
||||
{
|
||||
Type: cue.ListKind,
|
||||
Name: "env",
|
||||
},
|
||||
{
|
||||
Name: "image",
|
||||
Type: cue.StringKind,
|
||||
Default: "",
|
||||
Short: "i",
|
||||
Required: true,
|
||||
Usage: "specify app image",
|
||||
},
|
||||
{
|
||||
Name: "port",
|
||||
Type: cue.IntKind,
|
||||
Short: "p",
|
||||
Default: int64(8080),
|
||||
Usage: "specify port for container",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
websvc := types.Capability{
|
||||
Name: "webservice",
|
||||
Type: types.TypeWorkload,
|
||||
CueTemplateURI: "https://raw.githubusercontent.com/oam-dev/kubevela/master/vela-templates/web-service.cue",
|
||||
Parameters: []types.Parameter{
|
||||
{
|
||||
Name: "name",
|
||||
Required: true,
|
||||
Default: "",
|
||||
Type: cue.StringKind,
|
||||
},
|
||||
{
|
||||
Name: "image",
|
||||
Type: cue.StringKind,
|
||||
Default: "",
|
||||
Short: "i",
|
||||
Required: true,
|
||||
Usage: "specify app image",
|
||||
},
|
||||
{
|
||||
Name: "port",
|
||||
Type: cue.IntKind,
|
||||
Short: "p",
|
||||
Default: int64(6379),
|
||||
Usage: "specify port for container",
|
||||
},
|
||||
deployment := types.Capability{
|
||||
Name: "deployment",
|
||||
Type: types.TypeWorkload,
|
||||
CrdName: "deployments.testapps",
|
||||
Parameters: []types.Parameter{
|
||||
{
|
||||
Name: "name",
|
||||
Required: true,
|
||||
Type: cue.StringKind,
|
||||
Default: "",
|
||||
},
|
||||
CrdName: "webservice.testapps",
|
||||
}
|
||||
*/
|
||||
{
|
||||
Type: cue.ListKind,
|
||||
Name: "env",
|
||||
},
|
||||
{
|
||||
Name: "image",
|
||||
Type: cue.StringKind,
|
||||
Default: "",
|
||||
Short: "i",
|
||||
Required: true,
|
||||
Usage: "specify app image",
|
||||
},
|
||||
{
|
||||
Name: "port",
|
||||
Type: cue.IntKind,
|
||||
Short: "p",
|
||||
Default: int64(8080),
|
||||
Usage: "specify port for container",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
websvc := types.Capability{
|
||||
Name: "webservice",
|
||||
Type: types.TypeWorkload,
|
||||
CueTemplateURI: "https://raw.githubusercontent.com/oam-dev/kubevela/master/vela-templates/web-service.cue",
|
||||
Parameters: []types.Parameter{
|
||||
{
|
||||
Name: "name",
|
||||
Required: true,
|
||||
Default: "",
|
||||
Type: cue.StringKind,
|
||||
},
|
||||
{
|
||||
Name: "image",
|
||||
Type: cue.StringKind,
|
||||
Default: "",
|
||||
Short: "i",
|
||||
Required: true,
|
||||
Usage: "specify app image",
|
||||
},
|
||||
{
|
||||
Name: "port",
|
||||
Type: cue.IntKind,
|
||||
Short: "p",
|
||||
Default: int64(6379),
|
||||
Usage: "specify port for container",
|
||||
},
|
||||
},
|
||||
CrdName: "webservice.testapps",
|
||||
}
|
||||
|
||||
req, _ := labels.NewRequirement("usecase", selection.Equals, []string{"forplugintest"})
|
||||
selector := labels.NewSelector().Add(*req)
|
||||
|
||||
@@ -110,29 +109,28 @@ var _ = Describe("DefinitionFiles", func() {
|
||||
}
|
||||
Expect(traitDefs).Should(Equal([]types.Capability{route}))
|
||||
})
|
||||
// TODO: revert after the PR is merged
|
||||
/*
|
||||
// Notice!! DefinitionPath Object is Cluster Scope object
|
||||
// which means objects created in other DefinitionNamespace will also affect here.
|
||||
It("getworkload", func() {
|
||||
workloadDefs, err := GetWorkloadsFromCluster(context.Background(), DefinitionNamespace, k8sClient, definitionDir, selector)
|
||||
Expect(err).Should(BeNil())
|
||||
logf.Log.Info(fmt.Sprintf("Getting workload definitions %v", workloadDefs))
|
||||
for i := range workloadDefs {
|
||||
workloadDefs[i].CueTemplate = ""
|
||||
workloadDefs[i].DefinitionPath = ""
|
||||
}
|
||||
Expect(workloadDefs).Should(Equal([]types.Capability{deployment, websvc}))
|
||||
})
|
||||
It("getall", func() {
|
||||
alldef, err := GetCapabilitiesFromCluster(context.Background(), DefinitionNamespace, k8sClient, definitionDir, selector)
|
||||
Expect(err).Should(BeNil())
|
||||
logf.Log.Info(fmt.Sprintf("Getting all definitions %v", alldef))
|
||||
for i := range alldef {
|
||||
alldef[i].CueTemplate = ""
|
||||
alldef[i].DefinitionPath = ""
|
||||
}
|
||||
Expect(alldef).Should(Equal([]types.Capability{deployment, websvc, route}))
|
||||
})
|
||||
*/
|
||||
|
||||
// Notice!! DefinitionPath Object is Cluster Scope object
|
||||
// which means objects created in other DefinitionNamespace will also affect here.
|
||||
It("getworkload", func() {
|
||||
workloadDefs, err := GetWorkloadsFromCluster(context.Background(), DefinitionNamespace, k8sClient, definitionDir, selector)
|
||||
Expect(err).Should(BeNil())
|
||||
logf.Log.Info(fmt.Sprintf("Getting workload definitions %v", workloadDefs))
|
||||
for i := range workloadDefs {
|
||||
workloadDefs[i].CueTemplate = ""
|
||||
workloadDefs[i].DefinitionPath = ""
|
||||
}
|
||||
Expect(workloadDefs).Should(Equal([]types.Capability{deployment, websvc}))
|
||||
})
|
||||
It("getall", func() {
|
||||
alldef, err := GetCapabilitiesFromCluster(context.Background(), DefinitionNamespace, k8sClient, definitionDir, selector)
|
||||
Expect(err).Should(BeNil())
|
||||
logf.Log.Info(fmt.Sprintf("Getting all definitions %v", alldef))
|
||||
for i := range alldef {
|
||||
alldef[i].CueTemplate = ""
|
||||
alldef[i].DefinitionPath = ""
|
||||
}
|
||||
Expect(alldef).Should(Equal([]types.Capability{deployment, websvc, route}))
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user