11import { V1Namespace } from '@kubernetes/client-node' ;
2+ import { config } from '../../../src/common/config' ;
23
34import * as watchers from '../../../src/supervisor/watchers' ;
4- import { kubernetesInternalNamespaces } from '../../../src/supervisor/watchers/internal-namespaces' ;
5+ import {
6+ kubernetesInternalNamespaces ,
7+ openshiftInternalNamespaces ,
8+ } from '../../../src/supervisor/watchers/internal-namespaces' ;
59
6- describe ( 'extractNamespaceName() tests ' , ( ) => {
10+ describe ( 'extractNamespaceName()' , ( ) => {
711 test . each ( [
8- [ 'extractNamespaceName() throws on empty input' , { } as V1Namespace ] ,
9- [
10- 'extractNamespaceName() throws on empty metadata' ,
11- { metadata : { } } as V1Namespace ,
12- ] ,
13- [
14- 'extractNamespaceName() throws on undefined name' ,
15- { metadata : { name : undefined } } as V1Namespace ,
16- ] ,
17- [
18- 'extractNamespaceName() throws on empty name' ,
19- { metadata : { name : '' } } as V1Namespace ,
20- ] ,
21- ] ) ( '%s' , ( _testCaseName , input ) => {
12+ [ 'empty input' , { } as V1Namespace ] ,
13+ [ 'empty metadata' , { metadata : { } } as V1Namespace ] ,
14+ [ 'undefined name' , { metadata : { name : undefined } } as V1Namespace ] ,
15+ [ 'empty name' , { metadata : { name : '' } } as V1Namespace ] ,
16+ ] ) ( 'throws on %s' , ( _testCaseName , input ) => {
2217 expect ( ( ) => watchers . extractNamespaceName ( input ) ) . toThrowError (
2318 'Namespace missing metadata.name' ,
2419 ) ;
2520 } ) ;
2621
27- test ( 'extractNamespaceName() returns namespace.metadata.name' , ( ) => {
22+ test ( 'returns namespace.metadata.name' , ( ) => {
2823 expect (
2924 watchers . extractNamespaceName ( {
3025 metadata : { name : 'literally anything else' } ,
@@ -33,18 +28,16 @@ describe('extractNamespaceName() tests', () => {
3328 } ) ;
3429} ) ;
3530
36- describe ( 'internal Kubernetes namespaces tests ' , ( ) => {
37- test ( 'internal namespaces list against snapshot' , ( ) => {
31+ describe ( 'isExcludedNamespace() internal Kubernetes namespaces' , ( ) => {
32+ test ( 'list against snapshot' , ( ) => {
3833 expect ( kubernetesInternalNamespaces ) . toMatchSnapshot ( ) ;
3934 } ) ;
4035
41- test ( 'isKubernetesInternalNamespace(): internal Kubernetes namespaces are used' , ( ) => {
42- for ( const internalNamespace of kubernetesInternalNamespaces ) {
43- expect ( watchers . isKubernetesInternalNamespace ( internalNamespace ) ) . toEqual (
44- true ,
45- ) ;
46- }
47- } ) ;
36+ for ( const internalNamespace of kubernetesInternalNamespaces ) {
37+ test ( `isExcludedNamespace(${ internalNamespace } ) -> true` , ( ) => {
38+ expect ( watchers . isExcludedNamespace ( internalNamespace ) ) . toEqual ( true ) ;
39+ } ) ;
40+ }
4841
4942 test . each ( [
5043 [ 'kube-node-lease-' ] ,
@@ -53,7 +46,59 @@ describe('internal Kubernetes namespaces tests', () => {
5346 [ 'egg' ] ,
5447 [ '' ] ,
5548 [ ( undefined as unknown ) as string ] ,
56- ] ) ( 'isKubernetesInternalNamespace(%s) -> false' , ( input ) => {
57- expect ( watchers . isKubernetesInternalNamespace ( input ) ) . toEqual ( false ) ;
49+ ] ) ( 'isExcludedNamespace(%s) -> false' , ( input ) => {
50+ expect ( watchers . isExcludedNamespace ( input ) ) . toEqual ( false ) ;
51+ } ) ;
52+ } ) ;
53+
54+ describe ( 'isExcludedNamespace() openshift internal namespaces' , ( ) => {
55+ test ( 'list against snapshot' , ( ) => {
56+ expect ( openshiftInternalNamespaces ) . toMatchSnapshot ( ) ;
57+ } ) ;
58+
59+ for ( const internalNamespace of openshiftInternalNamespaces ) {
60+ test ( `isExcludedNamespace(${ internalNamespace } ) -> true` , ( ) => {
61+ expect ( watchers . isExcludedNamespace ( internalNamespace ) ) . toEqual ( true ) ;
62+ } ) ;
63+ }
64+
65+ test . each ( [
66+ [ 'openshif' ] ,
67+ [ 'openshift-' ] ,
68+ [ 'egg' ] ,
69+ [ '' ] ,
70+ [ ( undefined as unknown ) as string ] ,
71+ ] ) ( 'isExcludedNamespace(%s) -> false' , ( input ) => {
72+ expect ( watchers . isExcludedNamespace ( input ) ) . toEqual ( false ) ;
73+ } ) ;
74+ } ) ;
75+
76+ describe ( 'isExcludedNamespace() excluded namespaces from config' , ( ) => {
77+ const excludedNamespacesFromConfig = [ 'one' , 'two' , 'three' ] ;
78+ beforeAll ( ( ) => {
79+ config . EXCLUDED_NAMESPACES = excludedNamespacesFromConfig ;
80+ } ) ;
81+
82+ afterAll ( ( ) => {
83+ config . EXCLUDED_NAMESPACES = null ;
84+ } ) ;
85+
86+ excludedNamespacesFromConfig . forEach ( ( namespace ) => {
87+ test ( `[excluded namespaces from config] isExcludedNamespace(${ namespace } ) -> true` , ( ) => {
88+ expect ( watchers . isExcludedNamespace ( namespace ) ) . toEqual ( true ) ;
89+ } ) ;
5890 } ) ;
91+
92+ for ( const internalNamespace of openshiftInternalNamespaces ) {
93+ test ( `[openshift internal namespaces] isExcludedNamespace(${ internalNamespace } ) -> true` , ( ) => {
94+ expect ( watchers . isExcludedNamespace ( internalNamespace ) ) . toEqual ( true ) ;
95+ } ) ;
96+ }
97+
98+ test . each ( [ [ 'kube-system' ] [ 'egg' ] , [ '' ] , [ ( undefined as unknown ) as string ] ] ) (
99+ 'isExcludedNamespace(%s) -> false' ,
100+ ( input ) => {
101+ expect ( watchers . isExcludedNamespace ( input ) ) . toEqual ( false ) ;
102+ } ,
103+ ) ;
59104} ) ;
0 commit comments