|
1 | | -import * as path from 'path'; |
2 | | -import * as assert from 'assert'; |
3 | | -import * as ma from 'vsts-task-lib/mock-answer'; |
4 | | -import * as tmrm from 'vsts-task-lib/mock-run'; |
5 | | -import * as ttm from 'vsts-task-lib/mock-test'; |
6 | | -import * as mockery from 'mockery'; |
7 | | -import { INuGetXmlHelper } from '../INuGetXmlHelper'; |
| 1 | +import * as path from "path"; |
| 2 | +import * as assert from "assert"; |
| 3 | +import * as ma from "vsts-task-lib/mock-answer"; |
| 4 | +import * as tmrm from "vsts-task-lib/mock-run"; |
| 5 | +import * as ttm from "vsts-task-lib/mock-test"; |
| 6 | +import * as mockery from "mockery"; |
| 7 | +import { INuGetXmlHelper } from "../INuGetXmlHelper"; |
8 | 8 |
|
9 | 9 | class MockedTask { |
10 | 10 | private _proxyUrl: string; |
@@ -32,93 +32,122 @@ class MockedTask { |
32 | 32 | } |
33 | 33 |
|
34 | 34 | var mockedTask: MockedTask = new MockedTask(); |
35 | | -var mockedProxy: string = 'http://proxy/'; |
36 | | -var mockedUsername: string = 'mockedUsername'; |
37 | | -var mockedPassword: string = 'mockedPassword'; |
38 | | -mockery.registerMock('vsts-task-lib/task', mockedTask); |
| 35 | +var mockedProxy: string = "http://proxy/"; |
| 36 | +var mockedUsername: string = "mockedUsername"; |
| 37 | +var mockedPassword: string = "mockedPassword"; |
| 38 | +mockery.registerMock("vsts-task-lib/task", mockedTask); |
39 | 39 |
|
40 | | -describe('nuget-task-common Task Suite', function () { |
41 | | - before(() => { |
| 40 | +describe("nuget-task-common Task Suite", function() { |
| 41 | + beforeEach(() => { |
42 | 42 | mockery.enable({ |
43 | 43 | useCleanCache: true, |
| 44 | + warnOnReplace: false, |
44 | 45 | warnOnUnregistered: false |
45 | 46 | }); |
46 | 47 | }); |
47 | 48 |
|
48 | | - after(() => { |
| 49 | + afterEach(() => { |
49 | 50 | mockery.disable(); |
50 | 51 | }); |
51 | 52 |
|
52 | | - it('No HTTP_PROXY', (done:MochaDone) => { |
| 53 | + it("No HTTP_PROXY", (done: MochaDone) => { |
53 | 54 | mockedTask.setMockedValues(); |
54 | | - let ngToolRunner = require('../NuGetToolRunner'); |
| 55 | + let ngToolRunner = require("../NuGetToolRunner"); |
55 | 56 |
|
56 | 57 | let httpProxy: string = ngToolRunner.getNuGetProxyFromEnvironment(); |
57 | 58 | assert.strictEqual(httpProxy, undefined); |
58 | 59 |
|
59 | 60 | done(); |
60 | 61 | }); |
61 | 62 |
|
62 | | - it('Finds HTTP_PROXY', (done: MochaDone) => { |
| 63 | + it("Finds HTTP_PROXY", (done: MochaDone) => { |
63 | 64 | mockedTask.setMockedValues(mockedProxy); |
64 | | - let ngToolRunner = require('../NuGetToolRunner'); |
| 65 | + let ngToolRunner = require("../NuGetToolRunner"); |
65 | 66 |
|
66 | 67 | let httpProxy: string = ngToolRunner.getNuGetProxyFromEnvironment(); |
67 | 68 | assert.strictEqual(httpProxy, mockedProxy); |
68 | 69 |
|
69 | 70 | done(); |
70 | 71 | }); |
71 | 72 |
|
72 | | - it('Finds HTTP_PROXYUSERNAME', (done: MochaDone) => { |
| 73 | + it("Finds HTTP_PROXYUSERNAME", (done: MochaDone) => { |
73 | 74 | mockedTask.setMockedValues(mockedProxy, mockedUsername); |
74 | | - let ngToolRunner = require('../NuGetToolRunner'); |
| 75 | + let ngToolRunner = require("../NuGetToolRunner"); |
75 | 76 |
|
76 | 77 | let httpProxy: string = ngToolRunner.getNuGetProxyFromEnvironment(); |
77 | 78 | assert.strictEqual(httpProxy, `http://${mockedUsername}@proxy/`); |
78 | 79 |
|
79 | 80 | done(); |
80 | 81 | }); |
81 | 82 |
|
82 | | - it('Finds HTTP_PROXYPASSWORD', (done: MochaDone) => { |
| 83 | + it("Finds HTTP_PROXYPASSWORD", (done: MochaDone) => { |
83 | 84 | mockedTask.setMockedValues(mockedProxy, mockedUsername, mockedPassword); |
84 | | - let ngToolRunner = require('../NuGetToolRunner'); |
| 85 | + let ngToolRunner = require("../NuGetToolRunner"); |
85 | 86 |
|
86 | 87 | let httpProxy: string = ngToolRunner.getNuGetProxyFromEnvironment(); |
87 | 88 | assert.strictEqual(httpProxy, `http://${mockedUsername}:${mockedPassword}@proxy/`); |
88 | 89 |
|
89 | 90 | done(); |
90 | 91 | }); |
91 | 92 |
|
92 | | - it('NuGetXmlHelper adds source to NuGetConfig', (done: MochaDone) => { |
| 93 | + it("NuGetXmlHelper adds source to NuGetConfig", (done: MochaDone) => { |
93 | 94 | let configFile: string; |
94 | | - mockery.registerMock('fs', { |
| 95 | + mockery.registerMock("fs", { |
95 | 96 | readFileSync: () => configFile, |
96 | 97 | writeFileSync: (path, content) => { configFile = content; } |
97 | 98 | }); |
98 | 99 |
|
99 | | - let nugetXmlHelper = require('../NuGetXmlHelper'); |
| 100 | + let nugetXmlHelper = require("../NuGetXmlHelper"); |
100 | 101 | let helper: INuGetXmlHelper = new nugetXmlHelper.NuGetXmlHelper(); |
101 | 102 |
|
102 | | - configFile = '<configuration/>'; |
103 | | - helper.AddSourceToNuGetConfig('SourceName', 'http://source/'); |
| 103 | + configFile = "<configuration/>"; |
| 104 | + helper.AddSourceToNuGetConfig("SourceName", "http://source/"); |
104 | 105 | assert.strictEqual( |
105 | 106 | configFile, |
106 | 107 | '<configuration><packageSources><add key="SourceName" value="http://source/"/></packageSources></configuration>', |
107 | 108 | 'Helper should have added the "SourceName" source'); |
108 | 109 |
|
109 | | - helper.AddSourceToNuGetConfig('SourceCredentials', 'http://credentials', 'foo', 'bar'); |
| 110 | + helper.AddSourceToNuGetConfig("SourceCredentials", "http://credentials", "foo", "bar"); |
110 | 111 | assert.strictEqual( |
111 | 112 | configFile, |
112 | 113 | '<configuration><packageSources><add key="SourceName" value="http://source/"/><add key="SourceCredentials" value="http://credentials"/></packageSources><packageSourceCredentials><SourceCredentials><add key="Username" value="foo"/><add key="ClearTextPassword" value="bar"/></SourceCredentials></packageSourceCredentials></configuration>', |
113 | 114 | 'Helper should have added the "SourceCredentials" source with credentials'); |
114 | 115 |
|
115 | | - helper.RemoveSourceFromNuGetConfig('SourceCredentials'); |
| 116 | + helper.RemoveSourceFromNuGetConfig("SourceCredentials"); |
116 | 117 | assert.strictEqual( |
117 | 118 | configFile, |
118 | 119 | '<configuration><packageSources><add key="SourceName" value="http://source/"/></packageSources><packageSourceCredentials/></configuration>', |
119 | 120 | 'Helper should have removed the "SourceCredentials" source and its credentials'); |
120 | 121 |
|
121 | | - assert.throws(() => helper.SetApiKeyInNuGetConfig('http://ApiKeySource/', 'ApiKey'), 'SetApiKey should throw as it is not currently supported'); |
| 122 | + assert.throws(() => helper.SetApiKeyInNuGetConfig("http://ApiKeySource/", "ApiKey"), "SetApiKey should throw as it is not currently supported"); |
| 123 | + |
| 124 | + done(); |
| 125 | + }); |
| 126 | + |
| 127 | + it("NuGetXmlHelper correctly encodes element names", (done: MochaDone) => { |
| 128 | + let configFile: string; |
| 129 | + mockery.registerMock("fs", { |
| 130 | + readFileSync: () => configFile, |
| 131 | + writeFileSync: (path, content) => { configFile = content; } |
| 132 | + }); |
| 133 | + |
| 134 | + let nugetXmlHelper = require("../NuGetXmlHelper"); |
| 135 | + let helper: INuGetXmlHelper = new nugetXmlHelper.NuGetXmlHelper(); |
| 136 | + |
| 137 | + configFile = "<configuration/>"; |
| 138 | + helper.AddSourceToNuGetConfig("1Feed", "http://credentials", "foo", "bar"); |
| 139 | + assert.strictEqual( |
| 140 | + configFile, |
| 141 | + '<configuration><packageSources><add key="1Feed" value="http://credentials"/></packageSources><packageSourceCredentials><_x0031_Feed><add key="Username" value="foo"/><add key="ClearTextPassword" value="bar"/></_x0031_Feed></packageSourceCredentials></configuration>', |
| 142 | + 'Helper should have added the "1Feed" source with credentials'); |
| 143 | + helper.RemoveSourceFromNuGetConfig("1Feed"); |
| 144 | + |
| 145 | + helper.AddSourceToNuGetConfig("Feed with spaces and :", "http://credentials", "foo", "bar"); |
| 146 | + assert.strictEqual( |
| 147 | + configFile, |
| 148 | + '<configuration><packageSources><add key="Feed with spaces and :" value="http://credentials"/></packageSources><packageSourceCredentials><Feed_x0020_with_x0020_spaces_x0020_and_x0020__x003a_><add key="Username" value="foo"/><add key="ClearTextPassword" value="bar"/></Feed_x0020_with_x0020_spaces_x0020_and_x0020__x003a_></packageSourceCredentials></configuration>', |
| 149 | + 'Helper should have added the "Feed with spaces" source with credentials'); |
| 150 | + helper.RemoveSourceFromNuGetConfig("Feed with spaces"); |
122 | 151 |
|
123 | 152 | done(); |
124 | 153 | }); |
|
0 commit comments