Files
kubevela/e2e/addon/addon_test.go
Jianbo Sun 09e628025a Feat: beautify addon list experience (#4807)
* Feat: beautify addon list experience

Signed-off-by: Jianbo Sun <jianbo.sjb@alibaba-inc.com>

* Fix: addon list e2e test

Signed-off-by: Jianbo Sun <jianbo.sjb@alibaba-inc.com>

* Chore: refine logs

Signed-off-by: Jianbo Sun <jianbo.sjb@alibaba-inc.com>

Signed-off-by: Jianbo Sun <jianbo.sjb@alibaba-inc.com>
2022-09-30 13:23:27 +08:00

174 lines
7.0 KiB
Go

/*
Copyright 2021 The KubeVela Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package e2e
import (
"context"
"fmt"
"strings"
"time"
"github.com/Netflix/go-expect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
"github.com/oam-dev/kubevela/e2e"
"github.com/oam-dev/kubevela/pkg/utils/common"
)
var _ = Describe("Addon Test", func() {
args := common.Args{Schema: common.Scheme}
k8sClient, err := args.GetClient()
Expect(err).Should(BeNil())
Context("List addons", func() {
It("List all addon", func() {
output, err := e2e.Exec("vela addon list")
Expect(err).NotTo(HaveOccurred())
Expect(output).To(ContainSubstring("test-addon"))
})
It("Enable addon test-addon", func() {
output, err := e2e.Exec("vela addon enable test-addon")
Expect(err).NotTo(HaveOccurred())
Expect(output).To(ContainSubstring("enabled successfully."))
})
It("Upgrade addon test-addon", func() {
output, err := e2e.Exec("vela addon upgrade test-addon")
Expect(err).NotTo(HaveOccurred())
Expect(output).To(ContainSubstring("enabled successfully."))
})
It("Disable addon test-addon", func() {
output, err := e2e.LongTimeExec("vela addon disable test-addon", 600*time.Second)
Expect(err).NotTo(HaveOccurred())
Expect(output).To(ContainSubstring("Successfully disable addon"))
Eventually(func(g Gomega) {
g.Expect(apierrors.IsNotFound(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-test-addon", Namespace: "vela-system"}, &v1beta1.Application{}))).Should(BeTrue())
g.Expect(apierrors.IsNotFound(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-secret-test-addon", Namespace: "vela-system"}, &v1.Secret{}))).Should(BeTrue())
}, 60*time.Second).Should(Succeed())
})
It("Enable addon with input", func() {
output, err := e2e.LongTimeExec("vela addon enable test-addon example=redis", 300*time.Second)
Expect(err).NotTo(HaveOccurred())
Expect(output).To(ContainSubstring("enabled successfully."))
})
It("Disable addon test-addon", func() {
output, err := e2e.LongTimeExec("vela addon disable test-addon", 600*time.Second)
Expect(err).NotTo(HaveOccurred())
Expect(output).To(ContainSubstring("Successfully disable addon"))
Eventually(func(g Gomega) {
g.Expect(apierrors.IsNotFound(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-test-addon", Namespace: "vela-system"}, &v1beta1.Application{}))).Should(BeTrue())
}, 60*time.Second).Should(Succeed())
})
It("Enable local addon with . as path", func() {
output, err := e2e.LongTimeExec("vela addon enable ../../e2e/addon/mock/testdata/sample/.", 600*time.Second)
Expect(err).NotTo(HaveOccurred())
Expect(output).To(ContainSubstring("sample enabled successfully."))
})
It("Test Change default namespace can work", func() {
output, err := e2e.LongTimeExecWithEnv("vela addon list", 600*time.Second, []string{"DEFAULT_VELA_NS=test-vela"})
Expect(err).NotTo(HaveOccurred())
Expect(output).To(ContainSubstring("test-addon"))
Expect(output).To(ContainSubstring("-"))
output, err = e2e.LongTimeExecWithEnv("vela addon enable test-addon", 600*time.Second, []string{"DEFAULT_VELA_NS=test-vela"})
Expect(err).NotTo(HaveOccurred())
Expect(output).To(ContainSubstring("enabled successfully."))
Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-test-addon", Namespace: "test-vela"}, &v1beta1.Application{})).Should(BeNil())
}, 60*time.Second).Should(Succeed())
output, err = e2e.LongTimeExecWithEnv("vela addon disable test-addon", 600*time.Second, []string{"DEFAULT_VELA_NS=test-vela"})
Expect(err).NotTo(HaveOccurred())
Expect(output).To(ContainSubstring("Successfully disable addon"))
Eventually(func(g Gomega) {
g.Expect(apierrors.IsNotFound(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-test-addon", Namespace: "test-vela"}, &v1beta1.Application{}))).Should(BeTrue())
}, 60*time.Second).Should(Succeed())
})
It("Enable fluxcd-test-version whose version can't suit system requirements", func() {
output, err := e2e.InteractiveExec("vela addon enable fluxcd-test-version", func(c *expect.Console) {
_, err = c.SendLine("y")
Expect(err).NotTo(HaveOccurred())
})
Expect(output).To(ContainSubstring("enabled successfully"))
Expect(err).NotTo(HaveOccurred())
})
It("Disable addon fluxcd-test-version", func() {
output, err := e2e.LongTimeExec("vela addon disable fluxcd-test-version", 600*time.Second)
Expect(err).NotTo(HaveOccurred())
Expect(output).To(ContainSubstring("Successfully disable addon"))
})
It("Enable fluxcd-test-version whose version can't suit system requirements with 'n' input", func() {
output, err := e2e.InteractiveExec("vela addon enable fluxcd-test-version", func(c *expect.Console) {
_, err = c.SendLine("n")
Expect(err).NotTo(HaveOccurred())
})
Expect(output).To(ContainSubstring("you can try another version by command"))
Expect(err).NotTo(HaveOccurred())
})
})
Context("Addon registry test", func() {
It("List all addon registry", func() {
output, err := e2e.Exec("vela addon registry list")
Expect(err).NotTo(HaveOccurred())
Expect(output).To(ContainSubstring("KubeVela"))
})
It("Get addon registry", func() {
output, err := e2e.Exec("vela addon registry get KubeVela")
Expect(err).NotTo(HaveOccurred())
Expect(output).To(ContainSubstring("KubeVela"))
})
It("Add test addon registry", func() {
output, err := e2e.LongTimeExec("vela addon registry add my-repo --type=git --endpoint=https://github.com/oam-dev/catalog --path=/experimental/addons", 600*time.Second)
Expect(err).NotTo(HaveOccurred())
Expect(output).To(ContainSubstring("Successfully add an addon registry my-repo"))
Eventually(func() error {
output, err := e2e.LongTimeExec("vela addon registry update my-repo --type=git --endpoint=https://github.com/oam-dev/catalog --path=/addons", 300*time.Second)
if err != nil {
return err
}
if !strings.Contains(output, "Successfully update an addon registry my-repo") {
return fmt.Errorf("cannot update addon registry")
}
return nil
}, 30*time.Second, 300*time.Millisecond).Should(BeNil())
output, err = e2e.LongTimeExec("vela addon registry delete my-repo", 600*time.Second)
Expect(err).NotTo(HaveOccurred())
Expect(output).To(ContainSubstring("Successfully delete an addon registry my-repo"))
})
})
})