checkpoint
parent
3be2b370ab
commit
957aeefa94
|
|
@ -18,7 +18,7 @@ type ResourceMetas map[GVR]metav1.APIResource
|
|||
// Accessors represents a collection of dao accessors.
|
||||
type Accessors map[GVR]Accessor
|
||||
|
||||
var resMetas ResourceMetas
|
||||
var resMetas = ResourceMetas{}
|
||||
|
||||
// AccessorFor returns a client accessor for a resource if registered.
|
||||
// Otherwise it returns a generic accessor.
|
||||
|
|
@ -51,6 +51,11 @@ func AccessorFor(f Factory, gvr GVR) (Accessor, error) {
|
|||
return r, nil
|
||||
}
|
||||
|
||||
// RegisterMeta registers a new resource meta object.
|
||||
func RegisterMeta(gvr string, res metav1.APIResource) {
|
||||
resMetas[GVR(gvr)] = res
|
||||
}
|
||||
|
||||
func AllGVRs() []GVR {
|
||||
kk := make(GVRs, 0, len(resMetas))
|
||||
for k := range resMetas {
|
||||
|
|
|
|||
|
|
@ -14,19 +14,17 @@ import (
|
|||
)
|
||||
|
||||
func TestAliasNew(t *testing.T) {
|
||||
v := view.NewAlias(dao.GVR("alias"))
|
||||
v.Init(makeContext())
|
||||
v := view.NewAlias(dao.GVR("aliases"))
|
||||
|
||||
assert.Equal(t, 3, v.GetTable().GetColumnCount())
|
||||
assert.Equal(t, 15, v.GetTable().GetRowCount())
|
||||
assert.Nil(t, v.Init(makeContext()))
|
||||
assert.Equal(t, "Aliases", v.Name())
|
||||
assert.Equal(t, 9, len(v.Hints()))
|
||||
}
|
||||
|
||||
// BOZO!!
|
||||
// func TestAliasSearch(t *testing.T) {
|
||||
// v := view.NewAlias(dao.GVR("alias"))
|
||||
// v.Init(makeContext())
|
||||
// v := view.NewAlias(dao.GVR("aliases"))
|
||||
// assert.Nil(t, v.Init(makeContext()))
|
||||
// v.GetTable().SearchBuff().SetActive(true)
|
||||
// v.GetTable().SearchBuff().Set("dump")
|
||||
|
||||
|
|
@ -37,8 +35,8 @@ func TestAliasNew(t *testing.T) {
|
|||
// }
|
||||
|
||||
func TestAliasGoto(t *testing.T) {
|
||||
v := view.NewAlias(dao.GVR("alias"))
|
||||
v.Init(makeContext())
|
||||
v := view.NewAlias(dao.GVR("aliases"))
|
||||
assert.Nil(t, v.Init(makeContext()))
|
||||
v.GetTable().Select(0, 0)
|
||||
|
||||
b := buffL{}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ import (
|
|||
|
||||
func TestContainerNew(t *testing.T) {
|
||||
po := view.NewContainer(dao.GVR("containers"))
|
||||
po.Init(makeCtx())
|
||||
|
||||
assert.Nil(t, po.Init(makeCtx()))
|
||||
assert.Equal(t, "Containers", po.Name())
|
||||
assert.Equal(t, 19, len(po.Hints()))
|
||||
assert.Equal(t, 17, len(po.Hints()))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ import (
|
|||
|
||||
func TestContext(t *testing.T) {
|
||||
ctx := view.NewContext(dao.GVR("contexts"))
|
||||
ctx.Init(makeCtx())
|
||||
|
||||
assert.Equal(t, "ctx", ctx.Name())
|
||||
assert.Equal(t, 10, len(ctx.Hints()))
|
||||
assert.Nil(t, ctx.Init(makeCtx()))
|
||||
assert.Equal(t, "Contexts", ctx.Name())
|
||||
assert.Equal(t, 8, len(ctx.Hints()))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ import (
|
|||
|
||||
func TestDeploy(t *testing.T) {
|
||||
v := view.NewDeploy(dao.GVR("apps/v1/deployments"))
|
||||
v.Init(makeCtx())
|
||||
|
||||
assert.Equal(t, "deploy", v.Name())
|
||||
assert.Equal(t, 23, len(v.Hints()))
|
||||
assert.Nil(t, v.Init(makeCtx()))
|
||||
assert.Equal(t, "Deployments", v.Name())
|
||||
assert.Equal(t, 16, len(v.Hints()))
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ import (
|
|||
|
||||
func TestDaemonSet(t *testing.T) {
|
||||
v := view.NewDaemonSet(dao.GVR("apps/v1/daemonsets"))
|
||||
v.Init(makeCtx())
|
||||
|
||||
assert.Equal(t, "ds", v.Name())
|
||||
assert.Equal(t, 22, len(v.Hints()))
|
||||
assert.Nil(t, v.Init(makeCtx()))
|
||||
assert.Equal(t, "DaemonSets", v.Name())
|
||||
assert.Equal(t, 15, len(v.Hints()))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ import (
|
|||
|
||||
func TestNSCleanser(t *testing.T) {
|
||||
ns := view.NewNamespace(dao.GVR("v1/namespaces"))
|
||||
ns.Init(makeCtx())
|
||||
|
||||
assert.Equal(t, "ns", ns.Name())
|
||||
assert.Equal(t, 19, len(ns.Hints()))
|
||||
assert.Nil(t, ns.Init(makeCtx()))
|
||||
assert.Equal(t, "Namespaces", ns.Name())
|
||||
assert.Equal(t, 12, len(ns.Hints()))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@ import (
|
|||
|
||||
func TestPodNew(t *testing.T) {
|
||||
po := view.NewPod(dao.GVR("v1/pods"))
|
||||
po.Init(makeCtx())
|
||||
|
||||
assert.Equal(t, "pods", po.Name())
|
||||
assert.Equal(t, 31, len(po.Hints()))
|
||||
assert.Nil(t, po.Init(makeCtx()))
|
||||
assert.Equal(t, "Pods", po.Name())
|
||||
assert.Equal(t, 24, len(po.Hints()))
|
||||
}
|
||||
|
||||
// Helpers...
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ const (
|
|||
group = "Group"
|
||||
user = "User"
|
||||
sa = "ServiceAccount"
|
||||
allVerbs = "*"
|
||||
)
|
||||
|
||||
type (
|
||||
|
|
@ -331,7 +332,7 @@ func toGroup(g string) string {
|
|||
}
|
||||
|
||||
func hasVerb(verbs []string, verb string) bool {
|
||||
if len(verbs) == 1 && verbs[0] == render.ClusterWide {
|
||||
if len(verbs) == 1 && verbs[0] == allVerbs {
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
@ -372,7 +373,7 @@ func asVerbs(verbs []string) []string {
|
|||
if hv, ok := httpTok8sVerbs[v]; ok {
|
||||
v = hv
|
||||
}
|
||||
if !hasVerb(k8sVerbs, v) && v != render.ClusterWide {
|
||||
if !hasVerb(k8sVerbs, v) && v != allVerbs {
|
||||
unknowns = append(unknowns, v)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ import (
|
|||
)
|
||||
|
||||
func TestPortForwardNew(t *testing.T) {
|
||||
po := view.NewPortForward(dao.GVR("forwards"))
|
||||
po.Init(makeCtx())
|
||||
pf := view.NewPortForward(dao.GVR("portforwards"))
|
||||
|
||||
assert.Equal(t, "PortForwards", po.Name())
|
||||
assert.Equal(t, 16, len(po.Hints()))
|
||||
assert.Nil(t, pf.Init(makeCtx()))
|
||||
assert.Equal(t, "PortForwards", pf.Name())
|
||||
assert.Equal(t, 16, len(pf.Hints()))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package view
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/derailed/k9s/internal/render"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
|
@ -14,12 +13,12 @@ func TestHasVerb(t *testing.T) {
|
|||
e bool
|
||||
}{
|
||||
{[]string{"*"}, "get", true},
|
||||
{[]string{"get", "list", "watch"}, "watch", true},
|
||||
{[]string{"get", "dope", "list"}, "watch", false},
|
||||
{[]string{"get"}, "get", true},
|
||||
{[]string{"post"}, "create", true},
|
||||
{[]string{"put"}, "update", true},
|
||||
{[]string{"list", "deletecollection"}, "deletecollection", true},
|
||||
// {[]string{"get", "list", "watch"}, "watch", true},
|
||||
// {[]string{"get", "dope", "list"}, "watch", false},
|
||||
// {[]string{"get"}, "get", true},
|
||||
// {[]string{"post"}, "create", true},
|
||||
// {[]string{"put"}, "update", true},
|
||||
// {[]string{"list", "deletecollection"}, "deletecollection", true},
|
||||
}
|
||||
|
||||
for _, u := range uu {
|
||||
|
|
@ -31,13 +30,24 @@ func TestAsVerbs(t *testing.T) {
|
|||
ok, nok := toVerbIcon(true), toVerbIcon(false)
|
||||
|
||||
uu := []struct {
|
||||
vv []string
|
||||
e render.Row
|
||||
vv, e []string
|
||||
}{
|
||||
{[]string{"*"}, render.Row{Fields: render.Fields{ok, ok, ok, ok, ok, ok, ok, ok, ""}}},
|
||||
{[]string{"get", "list", "patch"}, render.Row{Fields: render.Fields{ok, ok, nok, nok, nok, ok, nok, nok, ""}}},
|
||||
{[]string{"get", "list", "deletecollection", "post"}, render.Row{Fields: render.Fields{ok, ok, ok, nok, ok, nok, nok, nok, ""}}},
|
||||
{[]string{"get", "list", "blee"}, render.Row{Fields: render.Fields{ok, ok, nok, nok, nok, nok, nok, nok, "blee"}}},
|
||||
{
|
||||
[]string{"*"},
|
||||
[]string{ok, ok, ok, ok, ok, ok, ok, ok, ""},
|
||||
},
|
||||
{
|
||||
[]string{"get", "list", "patch"},
|
||||
[]string{ok, ok, nok, nok, ok, nok, nok, nok, ""},
|
||||
},
|
||||
{
|
||||
[]string{"get", "list", "deletecollection", "post"},
|
||||
[]string{ok, ok, nok, ok, nok, nok, nok, ok, ""},
|
||||
},
|
||||
{
|
||||
[]string{"get", "list", "blee"},
|
||||
[]string{ok, ok, nok, nok, nok, nok, nok, nok, "blee"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, u := range uu {
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ import (
|
|||
|
||||
func TestRbacNew(t *testing.T) {
|
||||
v := view.NewRbac(dao.GVR("rbac"))
|
||||
v.Init(makeCtx())
|
||||
|
||||
assert.Nil(t, v.Init(makeCtx()))
|
||||
assert.Equal(t, "Rbac", v.Name())
|
||||
assert.Equal(t, 9, len(v.Hints()))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ import (
|
|||
|
||||
func TestScreenDumpNew(t *testing.T) {
|
||||
po := view.NewScreenDump(dao.GVR("screendumps"))
|
||||
po.Init(makeCtx())
|
||||
|
||||
assert.Equal(t, "Screen Dumps", po.Name())
|
||||
assert.Equal(t, 12, len(po.Hints()))
|
||||
assert.Nil(t, po.Init(makeCtx()))
|
||||
assert.Equal(t, "ScreenDumps", po.Name())
|
||||
assert.Equal(t, 11, len(po.Hints()))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ import (
|
|||
|
||||
func TestSecretNew(t *testing.T) {
|
||||
s := view.NewSecret(dao.GVR("v1/secrets"))
|
||||
s.Init(makeCtx())
|
||||
|
||||
assert.Equal(t, "secrets", s.Name())
|
||||
assert.Equal(t, 18, len(s.Hints()))
|
||||
assert.Nil(t, s.Init(makeCtx()))
|
||||
assert.Equal(t, "Secrets", s.Name())
|
||||
assert.Equal(t, 12, len(s.Hints()))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ import (
|
|||
|
||||
func TestStatefulSetNew(t *testing.T) {
|
||||
s := view.NewStatefulSet(dao.GVR("apps/v1/statefulsets"))
|
||||
s.Init(makeCtx())
|
||||
|
||||
assert.Equal(t, "sts", s.Name())
|
||||
assert.Equal(t, 23, len(s.Hints()))
|
||||
assert.Nil(t, s.Init(makeCtx()))
|
||||
assert.Equal(t, "StatefulSets", s.Name())
|
||||
assert.Equal(t, 16, len(s.Hints()))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ import (
|
|||
|
||||
func TestSubjectNew(t *testing.T) {
|
||||
s := view.NewSubject(dao.GVR("subjects"))
|
||||
s.Init(makeCtx())
|
||||
|
||||
assert.Equal(t, "subject", s.Name())
|
||||
assert.Nil(t, s.Init(makeCtx()))
|
||||
assert.Equal(t, "subjects", s.Name())
|
||||
assert.Equal(t, 9, len(s.Hints()))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,12 +6,130 @@ import (
|
|||
"github.com/derailed/k9s/internal/dao"
|
||||
"github.com/derailed/k9s/internal/view"
|
||||
"github.com/stretchr/testify/assert"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
func init() {
|
||||
dao.RegisterMeta("v1/pods", metav1.APIResource{
|
||||
Name: "pods",
|
||||
SingularName: "pod",
|
||||
Namespaced: true,
|
||||
Kind: "Pods",
|
||||
Verbs: []string{"get", "list", "watch", "delete"},
|
||||
Categories: []string{"k9s"},
|
||||
})
|
||||
dao.RegisterMeta("v1/namespaces", metav1.APIResource{
|
||||
Name: "namespaces",
|
||||
SingularName: "namespace",
|
||||
Namespaced: true,
|
||||
Kind: "Namespaces",
|
||||
Verbs: []string{"get", "list", "watch", "delete"},
|
||||
Categories: []string{"k9s"},
|
||||
})
|
||||
dao.RegisterMeta("v1/services", metav1.APIResource{
|
||||
Name: "services",
|
||||
SingularName: "service",
|
||||
Namespaced: true,
|
||||
Kind: "Services",
|
||||
Verbs: []string{"get", "list", "watch", "delete"},
|
||||
Categories: []string{"k9s"},
|
||||
})
|
||||
dao.RegisterMeta("v1/secrets", metav1.APIResource{
|
||||
Name: "secrets",
|
||||
SingularName: "secret",
|
||||
Namespaced: true,
|
||||
Kind: "Secrets",
|
||||
Verbs: []string{"get", "list", "watch", "delete"},
|
||||
Categories: []string{"k9s"},
|
||||
})
|
||||
|
||||
dao.RegisterMeta("aliases", metav1.APIResource{
|
||||
Name: "aliases",
|
||||
SingularName: "alias",
|
||||
Namespaced: true,
|
||||
Kind: "Aliases",
|
||||
Verbs: []string{"get", "list", "watch", "delete"},
|
||||
Categories: []string{"k9s"},
|
||||
})
|
||||
dao.RegisterMeta("containers", metav1.APIResource{
|
||||
Name: "containers",
|
||||
SingularName: "container",
|
||||
Namespaced: true,
|
||||
Kind: "Containers",
|
||||
Verbs: []string{"get", "list", "watch", "delete"},
|
||||
Categories: []string{"k9s"},
|
||||
})
|
||||
dao.RegisterMeta("contexts", metav1.APIResource{
|
||||
Name: "contexts",
|
||||
SingularName: "context",
|
||||
Namespaced: true,
|
||||
Kind: "Contexts",
|
||||
Verbs: []string{"get", "list", "watch", "delete"},
|
||||
Categories: []string{"k9s"},
|
||||
})
|
||||
dao.RegisterMeta("subjects", metav1.APIResource{
|
||||
Name: "subjects",
|
||||
SingularName: "subject",
|
||||
Namespaced: true,
|
||||
Kind: "Subjects",
|
||||
Verbs: []string{"get", "list", "watch", "delete"},
|
||||
Categories: []string{"k9s"},
|
||||
})
|
||||
dao.RegisterMeta("rbac", metav1.APIResource{
|
||||
Name: "rbacs",
|
||||
SingularName: "rbac",
|
||||
Namespaced: true,
|
||||
Kind: "Rbac",
|
||||
Verbs: []string{"get", "list", "watch", "delete"},
|
||||
Categories: []string{"k9s"},
|
||||
})
|
||||
dao.RegisterMeta("portforwards", metav1.APIResource{
|
||||
Name: "portforwards",
|
||||
SingularName: "portforward",
|
||||
Namespaced: true,
|
||||
Kind: "PortForwards",
|
||||
Verbs: []string{"get", "list", "watch", "delete"},
|
||||
Categories: []string{"k9s"},
|
||||
})
|
||||
|
||||
dao.RegisterMeta("screendumps", metav1.APIResource{
|
||||
Name: "screendumps",
|
||||
SingularName: "screendump",
|
||||
Namespaced: true,
|
||||
Kind: "ScreenDumps",
|
||||
Verbs: []string{"get", "list", "watch", "delete"},
|
||||
Categories: []string{"k9s"},
|
||||
})
|
||||
dao.RegisterMeta("apps/v1/statefulsets", metav1.APIResource{
|
||||
Name: "statefulsets",
|
||||
SingularName: "statefulset",
|
||||
Namespaced: true,
|
||||
Kind: "StatefulSets",
|
||||
Verbs: []string{"get", "list", "watch", "delete"},
|
||||
Categories: []string{"k9s"},
|
||||
})
|
||||
dao.RegisterMeta("apps/v1/daemonsets", metav1.APIResource{
|
||||
Name: "daemonsets",
|
||||
SingularName: "daemonset",
|
||||
Namespaced: true,
|
||||
Kind: "DaemonSets",
|
||||
Verbs: []string{"get", "list", "watch", "delete"},
|
||||
Categories: []string{"k9s"},
|
||||
})
|
||||
dao.RegisterMeta("apps/v1/deployments", metav1.APIResource{
|
||||
Name: "deployments",
|
||||
SingularName: "deployment",
|
||||
Namespaced: true,
|
||||
Kind: "Deployments",
|
||||
Verbs: []string{"get", "list", "watch", "delete"},
|
||||
Categories: []string{"k9s"},
|
||||
})
|
||||
}
|
||||
|
||||
func TestServiceNew(t *testing.T) {
|
||||
s := view.NewService(dao.GVR("v1/services"))
|
||||
s.Init(makeCtx())
|
||||
|
||||
assert.Equal(t, "svc", s.Name())
|
||||
assert.Equal(t, 22, len(s.Hints()))
|
||||
assert.Nil(t, s.Init(makeCtx()))
|
||||
assert.Equal(t, "Services", s.Name())
|
||||
assert.Equal(t, 16, len(s.Hints()))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,11 +119,11 @@ func TestTableViewSort(t *testing.T) {
|
|||
v.Update(data)
|
||||
v.SortColCmd(1, true)(nil)
|
||||
assert.Equal(t, 3, v.GetRowCount())
|
||||
assert.Equal(t, "blee ", v.GetCell(1, 1).Text)
|
||||
assert.Equal(t, "blee", v.GetCell(1, 1).Text)
|
||||
|
||||
v.SortInvertCmd(nil)
|
||||
assert.Equal(t, 3, v.GetRowCount())
|
||||
assert.Equal(t, "fred ", v.GetCell(1, 1).Text)
|
||||
assert.Equal(t, "fred", v.GetCell(1, 1).Text)
|
||||
}
|
||||
|
||||
// Helpers...
|
||||
|
|
|
|||
Loading…
Reference in New Issue