@@ -66,6 +66,17 @@ suite('Environment Info cache', () => {
66
66
assert . strictEqual ( result , undefined ) ;
67
67
} ) ;
68
68
69
+ test ( '`getAllEnvs` should return a deep copy of the environments currently in memory' , ( ) => {
70
+ const envsCache = new PythonEnvInfoCache ( allEnvsComplete ) ;
71
+
72
+ envsCache . initialize ( ) ;
73
+ const envs = envsCache . getAllEnvs ( ) ! ;
74
+
75
+ envs [ 0 ] . name = 'some-other-name' ;
76
+
77
+ assert . ok ( envs [ 0 ] !== envInfoArray [ 0 ] ) ;
78
+ } ) ;
79
+
69
80
test ( '`getAllEnvs` should return undefined if nothing has been set' , ( ) => {
70
81
const envsCache = new PythonEnvInfoCache ( allEnvsComplete ) ;
71
82
@@ -85,8 +96,8 @@ suite('Environment Info cache', () => {
85
96
} ) ;
86
97
87
98
test ( '`getEnv` should return an environment that matches all non-undefined properties of its argument' , ( ) => {
88
- const envsCache = new PythonEnvInfoCache ( allEnvsComplete ) ;
89
99
const env :PythonEnvInfo = { name : 'my-venv-env' } as unknown as PythonEnvInfo ;
100
+ const envsCache = new PythonEnvInfoCache ( allEnvsComplete ) ;
90
101
91
102
envsCache . initialize ( ) ;
92
103
@@ -97,9 +108,24 @@ suite('Environment Info cache', () => {
97
108
} ) ;
98
109
} ) ;
99
110
100
- test ( '`getEnv` should return undefined if no environment matches the properties of its argument' , ( ) => {
111
+ test ( '`getEnv` should return a deep copy of an environment' , ( ) => {
112
+ const envToFind = {
113
+ kind : PythonEnvKind . System , name : 'my-system-env' , defaultDisplayName : 'env-system' ,
114
+ } as unknown as PythonEnvInfo ;
115
+ const env :PythonEnvInfo = { name : 'my-system-env' } as unknown as PythonEnvInfo ;
101
116
const envsCache = new PythonEnvInfoCache ( allEnvsComplete ) ;
117
+
118
+ envsCache . setAllEnvs ( [ ...envInfoArray , envToFind ] ) ;
119
+
120
+ const result = envsCache . getEnv ( env ) ! ;
121
+ result . name = 'some-other-name' ;
122
+
123
+ assert . ok ( result !== envToFind ) ;
124
+ } ) ;
125
+
126
+ test ( '`getEnv` should return undefined if no environment matches the properties of its argument' , ( ) => {
102
127
const env :PythonEnvInfo = { name : 'my-nonexistent-env' } as unknown as PythonEnvInfo ;
128
+ const envsCache = new PythonEnvInfoCache ( allEnvsComplete ) ;
103
129
104
130
envsCache . initialize ( ) ;
105
131
0 commit comments