diff --git a/pkg/kor/namespaces_test.go b/pkg/kor/namespaces_test.go index 167902bd..b53f7b89 100644 --- a/pkg/kor/namespaces_test.go +++ b/pkg/kor/namespaces_test.go @@ -2,6 +2,8 @@ package kor import ( "testing" + + "k8s.io/apimachinery/pkg/runtime/schema" ) func TestIgnoreResourceType(t *testing.T) { @@ -53,3 +55,81 @@ func TestIgnoreResourceType(t *testing.T) { }) } } + +func TestGetGVR(t *testing.T) { + type args struct { + name string + splitGV []string + } + tests := []struct { + name string + args args + want *schema.GroupVersionResource + expectErr bool + }{ + { + name: "number of parts 0 - expect error", + args: args{ + name: "deployments", + splitGV: []string{}, + }, + want: nil, + expectErr: true, + }, + { + name: "number of parts 1", + args: args{ + name: "secrets", + splitGV: []string{ + "v1", + }, + }, + want: &schema.GroupVersionResource{ + Group: "", + Version: "v1", + Resource: "secrets", + }, + expectErr: false, + }, + { + name: "number of parts 2", + args: args{ + name: "deployments", + splitGV: []string{ + "apps", + "v1", + }, + }, + want: &schema.GroupVersionResource{ + Group: "apps", + Version: "v1", + Resource: "deployments", + }, + expectErr: false, + }, + { + name: "number of parts 4 - expect error", + args: args{ + name: "deployments", + splitGV: []string{ + "apps", + "v1", + "test-deploy01", + }, + }, + want: nil, + expectErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := getGVR(tt.args.name, tt.args.splitGV) + if (err != nil) != tt.expectErr { + t.Errorf("getGVR() = expected error: %t, got: '%v'", tt.expectErr, err) + } + if got != nil && *got != *tt.want { + t.Errorf("getGVR() = %+v, want %+v", got, tt.want) + } + }) + } +}