Files
kubevela/references/cli/top/model/managed_resource_test.go
T
Siege Lion bd728cbdbc Feat: Add more data field to application view and managed resource view in vela top (#4781)
* Fix: fix the bug of cluster list

Signed-off-by: HanMengnan <1448189829@qq.com>

* Feat: add some feature

1. add more column of application and managed resource

2. alter <ESC> to exist key and add <Q> as the back key
Signed-off-by: HanMengnan <1448189829@qq.com>

Signed-off-by: HanMengnan <1448189829@qq.com>
2022-09-30 10:45:49 +08:00

63 lines
1.7 KiB
Go

/*
Copyright 2022 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 model
import (
"context"
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/assert"
)
func TestListManagedResource(t *testing.T) {
list := ManagedResourceList{{"", "", "", "", "", "", ""}}
assert.Equal(t, list.ToTableBody(), [][]string{{"", "", "", "", "", "", ""}})
}
func TestManagedResourceList_FilterCluster(t *testing.T) {
list := ManagedResourceList{
{"", "", "", "", "1", "", ""},
{"", "", "", "", "2", "", ""},
}
list.FilterCluster("1")
assert.Equal(t, len(list), 1)
}
func TestManagedResourceList_FilterClusterNamespace(t *testing.T) {
list := ManagedResourceList{
{"", "1", "", "", "1", "", ""},
{"", "2", "", "", "2", "", ""},
}
list.FilterClusterNamespace("2")
assert.Equal(t, len(list), 1)
}
var _ = Describe("test managed resource", func() {
ctx := context.Background()
ctx = context.WithValue(ctx, &CtxKeyAppName, "first-vela-app")
ctx = context.WithValue(ctx, &CtxKeyNamespace, "default")
ctx = context.WithValue(ctx, &CtxKeyCluster, "local")
It("list managed resource", func() {
list, err := ListManagedResource(ctx, k8sClient)
Expect(err).NotTo(HaveOccurred())
Expect(len(list.ToTableBody())).To(Equal(4))
})
})