@@ -4,7 +4,8 @@ import * as base64 from 'base-64';
4
4
import { expect } from 'chai' ;
5
5
import * as https from 'https' ;
6
6
7
- import { Config , KubeConfig } from './config' ;
7
+ import { KubeConfig } from './config' ;
8
+ import { Cluster , Context , User } from './config_types' ;
8
9
9
10
const kcFileName = 'testdata/kubeconfig.yaml' ;
10
11
@@ -44,6 +45,64 @@ describe('KubeConfig', () => {
44
45
expect ( obj3 ) . to . equal ( null ) ;
45
46
} ) ;
46
47
} ) ;
48
+
49
+ describe ( 'loadFromClusterAndUser' , ( ) => {
50
+ it ( 'should load from cluster and user' , ( ) => {
51
+ const kc = new KubeConfig ( ) ;
52
+ const cluster = {
53
+ name : 'foo' ,
54
+ server : 'http://server.com' ,
55
+ } as Cluster ;
56
+
57
+ const user = {
58
+ name : 'my-user' ,
59
+ password : 'some-password' ,
60
+ } as User ;
61
+
62
+ kc . loadFromClusterAndUser ( cluster , user ) ;
63
+
64
+ const clusterOut = kc . getCurrentCluster ( ) ;
65
+ expect ( clusterOut ) . to . equal ( cluster ) ;
66
+
67
+ const userOut = kc . getCurrentUser ( ) ;
68
+ expect ( userOut ) . to . equal ( user ) ;
69
+ } ) ;
70
+ } ) ;
71
+
72
+ describe ( 'clusterConstructor' , ( ) => {
73
+ it ( 'should load from options' , ( ) => {
74
+ const cluster = {
75
+ name : 'foo' ,
76
+ server : 'http://server.com' ,
77
+ } as Cluster ;
78
+
79
+ const user = {
80
+ name : 'my-user' ,
81
+ password : 'some-password' ,
82
+ } as User ;
83
+
84
+ const context = {
85
+ name : 'my-context' ,
86
+ user : user . name ,
87
+ cluster : cluster . name ,
88
+ } ;
89
+
90
+ const kc = new KubeConfig ( ) ;
91
+ kc . loadFromOptions ( {
92
+ clusters : [ cluster ] ,
93
+ users : [ user ] ,
94
+ contexts : [ context ] ,
95
+ currentContext : context . name ,
96
+ } ) ;
97
+
98
+ const clusterOut = kc . getCurrentCluster ( ) ;
99
+ expect ( clusterOut ) . to . equal ( cluster ) ;
100
+
101
+ const userOut = kc . getCurrentUser ( ) ;
102
+ expect ( userOut ) . to . equal ( user ) ;
103
+ } ) ;
104
+ } ) ;
105
+
47
106
describe ( 'loadFromFile' , ( ) => {
48
107
it ( 'should load the kubeconfig file properly' , ( ) => {
49
108
const kc = new KubeConfig ( ) ;
0 commit comments