@@ -34,9 +34,7 @@ describe('modules/manager/nuget/util', () => {
34
34
35
35
describe ( 'getConfiguredRegistries' , ( ) => {
36
36
it ( 'reads nuget config file' , async ( ) => {
37
- fs . findUpLocal . mockReturnValue (
38
- Promise . resolve < string | null > ( 'NuGet.config' ) ,
39
- ) ;
37
+ fs . findUpLocal . mockResolvedValue ( 'NuGet.config' ) ;
40
38
fs . readLocalFile . mockResolvedValueOnce (
41
39
codeBlock `
42
40
<configuration>
@@ -58,23 +56,22 @@ describe('modules/manager/nuget/util', () => {
58
56
) ;
59
57
60
58
const registries = await getConfiguredRegistries ( 'NuGet.config' ) ;
61
- expect ( registries ?. length ) . toBe ( 2 ) ;
62
- expect ( registries ! [ 0 ] . name ) . toBe ( 'nuget.org' ) ;
63
- expect ( registries ! [ 0 ] . url ) . toBe ( 'https://api.nuget.org/v3/index.json' ) ;
64
- expect ( registries ! [ 0 ] . sourceMappedPackagePatterns ) . toEqual ( [ '*' ] ) ;
65
-
66
- expect ( registries ! [ 1 ] . name ) . toBe ( 'contoso.com' ) ;
67
- expect ( registries ! [ 1 ] . url ) . toBe ( 'https://contoso.com/packages/' ) ;
68
- expect ( registries ! [ 1 ] . sourceMappedPackagePatterns ) . toEqual ( [
69
- 'Contoso.*' ,
70
- 'NuGet.Common' ,
59
+ expect ( registries ) . toEqual ( [
60
+ {
61
+ name : 'nuget.org' ,
62
+ url : 'https://api.nuget.org/v3/index.json' ,
63
+ sourceMappedPackagePatterns : [ '*' ] ,
64
+ } ,
65
+ {
66
+ name : 'contoso.com' ,
67
+ url : 'https://contoso.com/packages/' ,
68
+ sourceMappedPackagePatterns : [ 'Contoso.*' , 'NuGet.Common' ] ,
69
+ } ,
71
70
] ) ;
72
71
} ) ;
73
72
74
73
it ( 'reads nuget config file with default registry' , async ( ) => {
75
- fs . findUpLocal . mockReturnValue (
76
- Promise . resolve < string | null > ( 'NuGet.config' ) ,
77
- ) ;
74
+ fs . findUpLocal . mockResolvedValue ( 'NuGet.config' ) ;
78
75
fs . readLocalFile . mockResolvedValueOnce (
79
76
codeBlock `
80
77
<configuration>
@@ -94,18 +91,137 @@ describe('modules/manager/nuget/util', () => {
94
91
) ;
95
92
96
93
const registries = await getConfiguredRegistries ( 'NuGet.config' ) ;
97
- expect ( registries ?. length ) . toBe ( 2 ) ;
98
- expect ( registries ! [ 0 ] . name ) . toBe ( 'nuget.org' ) ;
99
- expect ( registries ! [ 0 ] . url ) . toBe ( 'https://api.nuget.org/v3/index.json' ) ;
100
- expect ( registries ! [ 0 ] . sourceMappedPackagePatterns ) . toEqual ( [ '*' ] ) ;
101
-
102
- expect ( registries ! [ 1 ] . name ) . toBe ( 'contoso.com' ) ;
103
- expect ( registries ! [ 1 ] . url ) . toBe ( 'https://contoso.com/packages/' ) ;
104
- expect ( registries ! [ 1 ] . sourceMappedPackagePatterns ) . toEqual ( [
105
- 'Contoso.*' ,
106
- 'NuGet.Common' ,
94
+ expect ( registries ) . toEqual ( [
95
+ {
96
+ name : 'nuget.org' ,
97
+ url : 'https://api.nuget.org/v3/index.json' ,
98
+ sourceMappedPackagePatterns : [ '*' ] ,
99
+ } ,
100
+ {
101
+ name : 'contoso.com' ,
102
+ url : 'https://contoso.com/packages/' ,
103
+ sourceMappedPackagePatterns : [ 'Contoso.*' , 'NuGet.Common' ] ,
104
+ } ,
107
105
] ) ;
108
106
} ) ;
107
+
108
+ it ( 'reads nuget config file with default registry disabled and added sources' , async ( ) => {
109
+ fs . findUpLocal . mockResolvedValue ( 'NuGet.config' ) ;
110
+ fs . readLocalFile . mockResolvedValueOnce (
111
+ codeBlock `
112
+ <configuration>
113
+ <packageSources>
114
+ <add key="contoso.com" value="https://contoso.com/packages/"/>
115
+ </packageSources>
116
+ <disabledPackageSources>
117
+ <add key="nuget.org" value="true" />
118
+ </disabledPackageSources>
119
+ </configuration>` ,
120
+ ) ;
121
+
122
+ const registries = await getConfiguredRegistries ( 'NuGet.config' ) ;
123
+ expect ( registries ) . toEqual ( [
124
+ {
125
+ name : 'contoso.com' ,
126
+ url : 'https://contoso.com/packages/' ,
127
+ } ,
128
+ ] ) ;
129
+ } ) ;
130
+
131
+ it ( 'reads nuget config file with default registry disabled given default registry added' , async ( ) => {
132
+ fs . findUpLocal . mockResolvedValue ( 'NuGet.config' ) ;
133
+ fs . readLocalFile . mockResolvedValueOnce (
134
+ codeBlock `
135
+ <configuration>
136
+ <packageSources>
137
+ <add key="nuget.org" value="https://api.nuget.org/v3/index.json"/>
138
+ <add key="contoso.com" value="https://contoso.com/packages/"/>
139
+ </packageSources>
140
+ <disabledPackageSources>
141
+ <add key="nuget.org" value="true" />
142
+ </disabledPackageSources>
143
+ </configuration>` ,
144
+ ) ;
145
+
146
+ const registries = await getConfiguredRegistries ( 'NuGet.config' ) ;
147
+ expect ( registries ) . toEqual ( [
148
+ {
149
+ name : 'contoso.com' ,
150
+ url : 'https://contoso.com/packages/' ,
151
+ } ,
152
+ ] ) ;
153
+ } ) ;
154
+
155
+ it ( 'reads nuget config file with unknown disabled source' , async ( ) => {
156
+ fs . findUpLocal . mockResolvedValue ( 'NuGet.config' ) ;
157
+ fs . readLocalFile . mockResolvedValueOnce (
158
+ codeBlock `
159
+ <configuration>
160
+ <packageSources>
161
+ <add key="contoso.com" value="https://contoso.com/packages/"/>
162
+ </packageSources>
163
+ <disabledPackageSources>
164
+ <add key="unknown" value="true" />
165
+ </disabledPackageSources>
166
+ </configuration>` ,
167
+ ) ;
168
+
169
+ const registries = await getConfiguredRegistries ( 'NuGet.config' ) ;
170
+ expect ( registries ) . toEqual ( [
171
+ {
172
+ name : 'nuget.org' ,
173
+ url : 'https://api.nuget.org/v3/index.json' ,
174
+ } ,
175
+ {
176
+ name : 'contoso.com' ,
177
+ url : 'https://contoso.com/packages/' ,
178
+ } ,
179
+ ] ) ;
180
+ } ) ;
181
+
182
+ it ( 'reads nuget config file with disabled source with value false' , async ( ) => {
183
+ fs . findUpLocal . mockResolvedValue ( 'NuGet.config' ) ;
184
+ fs . readLocalFile . mockResolvedValueOnce (
185
+ codeBlock `
186
+ <configuration>
187
+ <packageSources>
188
+ <clear />
189
+ <add key="nuget.org" value="https://api.nuget.org/v3/index.json"/>
190
+ <add key="contoso.com" value="https://contoso.com/packages/"/>
191
+ </packageSources>
192
+ <disabledPackageSources>
193
+ <add key="contoso.com" value="false" />
194
+ </disabledPackageSources>
195
+ </configuration>` ,
196
+ ) ;
197
+
198
+ const registries = await getConfiguredRegistries ( 'NuGet.config' ) ;
199
+ expect ( registries ) . toEqual ( [
200
+ {
201
+ name : 'nuget.org' ,
202
+ url : 'https://api.nuget.org/v3/index.json' ,
203
+ } ,
204
+ {
205
+ name : 'contoso.com' ,
206
+ url : 'https://contoso.com/packages/' ,
207
+ } ,
208
+ ] ) ;
209
+ } ) ;
210
+
211
+ it ( 'reads nuget config file without packageSources and ignores disabledPackageSources' , async ( ) => {
212
+ fs . findUpLocal . mockResolvedValue ( 'NuGet.config' ) ;
213
+ fs . readLocalFile . mockResolvedValueOnce (
214
+ codeBlock `
215
+ <configuration>
216
+ <disabledPackageSources>
217
+ <add key="contoso.com" value="true" />
218
+ </disabledPackageSources>
219
+ </configuration>` ,
220
+ ) ;
221
+
222
+ const registries = await getConfiguredRegistries ( 'NuGet.config' ) ;
223
+ expect ( registries ) . toBeUndefined ( ) ;
224
+ } ) ;
109
225
} ) ;
110
226
111
227
describe ( 'applyRegistries' , ( ) => {
0 commit comments