@@ -8,6 +8,7 @@ import { GenericClass } from "../types";
8
8
import { ClusterRole , Ingress , Pod } from "../upstream" ;
9
9
import { Filters } from "./types" ;
10
10
import { k8sExec , pathBuilder } from "./utils" ;
11
+ import { RegisterKind } from "../kinds" ;
11
12
12
13
jest . mock ( "https" ) ;
13
14
jest . mock ( "../fetch" ) ;
@@ -20,6 +21,44 @@ describe("pathBuilder Function", () => {
20
21
expect ( ( ) => pathBuilder ( "" , model , filters ) ) . toThrow ( "Kind not specified for Unknown" ) ;
21
22
} ) ;
22
23
24
+ it ( "should generate a path for core group kinds (with custom filters)" , ( ) => {
25
+ const filters : Filters = {
26
+ namespace : "default" ,
27
+ name : "mypod" ,
28
+ fields : { iamafield : "iamavalue" } ,
29
+ labels : { iamalabel : "iamalabelvalue" } ,
30
+ } ;
31
+ const result = pathBuilder ( serverUrl , Pod , filters ) ;
32
+ const expected = new URL (
33
+ "/api/v1/namespaces/default/pods/mypod?fieldSelector=iamafield%3Diamavalue&labelSelector=iamalabel%3Diamalabelvalue" ,
34
+ serverUrl ,
35
+ ) ;
36
+ expect ( result ) . toEqual ( expected ) ;
37
+ } ) ;
38
+
39
+ it ( "Version not specified in a Kind" , ( ) => {
40
+ const filters : Filters = {
41
+ namespace : "default" ,
42
+ name : "mypod" ,
43
+ } ;
44
+ class Fake {
45
+ name : string ;
46
+ constructor ( ) {
47
+ this . name = "Fake" ;
48
+ }
49
+ }
50
+ RegisterKind ( Fake , {
51
+ kind : "Fake" ,
52
+ version : "" ,
53
+ group : "fake" ,
54
+ } ) ;
55
+ try {
56
+ pathBuilder ( serverUrl , Fake , filters ) ;
57
+ } catch ( e ) {
58
+ expect ( e . message ) . toEqual ( `Version not specified for Fake` ) ;
59
+ }
60
+ } ) ;
61
+
23
62
it ( "should generate a path for core group kinds" , ( ) => {
24
63
const filters : Filters = { namespace : "default" , name : "mypod" } ;
25
64
const result = pathBuilder ( serverUrl , Pod , filters ) ;
0 commit comments