Files
kubevela/references/cli/uninstall_test.go
wyike a6460d67b6 Feat: check if an addon is been used while disabling. (#3457)
* first commit

add more tests

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>

fix ci

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>

fix ci

fix test

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>

* fetch only definitions from registry for lagacy addon app

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>

fix ci

* fix error test

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>
2022-03-21 10:38:56 +08:00

101 lines
2.5 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 cli
import (
"context"
"fmt"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"sigs.k8s.io/yaml"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
"github.com/oam-dev/kubevela/pkg/oam/util"
)
var _ = Describe("Test Install Command", func() {
BeforeEach(func() {
fluxcd := v1beta1.Application{}
err := yaml.Unmarshal([]byte(fluxcdYaml), &fluxcd)
Expect(err).Should(BeNil())
Expect(k8sClient.Create(context.Background(), &fluxcd)).Should(SatisfyAny(BeNil(), util.AlreadyExistMatcher{}))
rollout := v1beta1.Application{}
err = yaml.Unmarshal([]byte(rolloutYaml), &rollout)
Expect(err).Should(BeNil())
Expect(k8sClient.Create(context.Background(), &rollout)).Should(SatisfyAny(BeNil(), util.AlreadyExistMatcher{}))
})
It("Test check addon enabled", func() {
addons, err := checkInstallAddon(k8sClient)
Expect(err).Should(BeNil())
Expect(len(addons)).Should(BeEquivalentTo(2))
})
It("Test disable all addons", func() {
err := forceDisableAddon(context.Background(), k8sClient, cfg)
Expect(err).Should(BeNil())
Eventually(func() error {
addons, err := checkInstallAddon(k8sClient)
if err != nil {
return err
}
if len(addons) != 0 {
return fmt.Errorf("%v still exist", addons)
}
return nil
}, 1*time.Minute, 5*time.Second).Should(BeNil())
})
})
var fluxcdYaml = `
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: addon-fluxcd
namespace: vela-system
labels:
addons.oam.dev/name: fluxcd
spec:
components:
- name: ns-flux-system
properties:
apiVersion: v1
kind: Namespace
metadata:
name: flux-system
`
var rolloutYaml = `
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: addon-rollout
namespace: vela-system
labels:
addons.oam.dev/name: rollout
spec:
components:
- name: test-ns
properties:
apiVersion: v1
kind: Namespace
metadata:
name: test-ns
`