forked from ajuzadolfo/maven-settings-xml-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.test.js
133 lines (102 loc) · 6.55 KB
/
settings.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
var assert = require('assert');
var process = require('process');
var settings = require('../src/settings')
var XMLSerializer = require('xmldom').XMLSerializer;
var DOMParser = require('xmldom').DOMParser;
describe('run settings.js', function () {
describe('#updateServers', function () {
it('<server/> should be not be changed when input.server is missing', function () {
// given input
process.env['INPUT_SERVERS'] = '';
// and default settings
var xml = new DOMParser().parseFromString("<settings><servers/></settings>");
// when
settings.updateServers(xml);
// then
var expectedXml = '<settings><servers/></settings>';
assert.equal(new XMLSerializer().serializeToString(xml), expectedXml);
});
});
describe('#updateServers', function () {
it('<server/> should be appended with <server> when input.server is present', function () {
// given input
process.env['INPUT_SERVERS'] = '[{ "id": "foo", "username": "fu", "password": "bar" }]';
// and default settings
var xml = new DOMParser().parseFromString("<settings><servers/></settings>");
// when
settings.updateServers(xml);
// then
var expectedXml = '<settings><servers><server><id>foo</id><username>fu</username><password>bar</password></server></servers></settings>';
assert.equal(new XMLSerializer().serializeToString(xml), expectedXml);
});
});
describe('#updateMirrors', function () {
it('<mirrors/> should be appended with <mirror> when input.mirror is present', function () {
// given input
process.env['INPUT_MIRRORS'] = '[{ "id": "nexus", "mirrorOf": "!my-org-snapshots,*", "url": "http://redacted/nexus/content/groups/public" }]';
// and default settings
var xml = new DOMParser().parseFromString("<settings><mirrors/></settings>");
// when
settings.updateMirrors(xml);
// then
var expectedXml = '<settings><mirrors><mirror><id>nexus</id><mirrorOf>!my-org-snapshots,*</mirrorOf><url>http://redacted/nexus/content/groups/public</url></mirror></mirrors></settings>';
assert.equal(new XMLSerializer().serializeToString(xml), expectedXml);
});
});
describe('#updateRepositories', function () {
it('<repositories> should not be changed when input.repositories is missing', function () {
// given input
process.env['INPUT_REPOSITORIES'] = '[{ "id": "foo", "url": "http://foo.bar" }]';
// and default settings
var xml = new DOMParser().parseFromString(
"<settings><profiles><profile><id>github</id><repositories/><pluginRepositories/></profile></profiles></settings>");
// when
settings.updateRepositories(xml);
// then
var expectedXml = '<settings><profiles><profile><id>github</id><repositories><repository><id>foo</id><url>http://foo.bar</url></repository></repositories><pluginRepositories/></profile></profiles></settings>';
assert.equal(new XMLSerializer().serializeToString(xml), expectedXml);
});
});
describe('#updateRepositories', function () {
it('<repositories> should be appended with <repository> when input.repositories is present', function () {
// given input
process.env['INPUT_REPOSITORIES'] = '[{ "id": "foo", "name": "foo", "url": "http://foo.bar", "releases": { "enabled": "true" }, "snapshots": { "enabled": "true" } }]';
// and default settings
var xml = new DOMParser().parseFromString(
"<settings><profiles><profile><id>github</id><repositories/><pluginRepositories/></profile></profiles></settings>");
// when
settings.updateRepositories(xml);
// then
var expectedXml = '<settings><profiles><profile><id>github</id><repositories><repository><id>foo</id><name>foo</name><url>http://foo.bar</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></repository></repositories><pluginRepositories/></profile></profiles></settings>';
assert.equal(new XMLSerializer().serializeToString(xml), expectedXml);
});
});
describe('#updatePluginRepositories', function () {
it('<pluginRepositories> should be appended with <pluginRepository> when input.pluginRepositories is present', function () {
// given input
process.env['INPUT_PLUGIN_REPOSITORIES'] = '[{ "id": "foo.plugin", "name": "foo.plugin", "url": "http://foo.bar.plugin", "releases": { "enabled": "true" }, "snapshots": { "enabled": "true" } }]';
// and default settings
var xml = new DOMParser().parseFromString(
"<settings><profiles><profile><id>github</id><repositories/><pluginRepositories/></profile></profiles></settings>");
// when
settings.updatePluginRepositories(xml);
// then
var expectedXml = '<settings><profiles><profile><id>github</id><repositories/><pluginRepositories><pluginRepository><id>foo.plugin</id><name>foo.plugin</name><url>http://foo.bar.plugin</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></pluginRepository></pluginRepositories></profile></profiles></settings>';
assert.equal(new XMLSerializer().serializeToString(xml), expectedXml);
});
});
describe('#updateProfiles', function () {
it('<profiles> should be appended with <profile> when input.profiles is present', function () {
// given input
process.env['INPUT_PROFILES'] = '[{ "id": "foo.profile", "name": "foo.profile", "url": "http://foo.bar.profile", "properties": { "foo": "property-1", "bar": "property-2"} }]';
// and default settings
var xml = new DOMParser().parseFromString(
"<settings><profiles><profile><id>github</id><repositories/></profile></profiles></settings>");
// when
settings.updateProfiles(xml);
// then
var expectedXml = '<settings><profiles><profile><id>github</id><repositories/></profile><profile><id>foo.profile</id><name>foo.profile</name><url>http://foo.bar.profile</url><properties><foo>property-1</foo><bar>property-2</bar></properties></profile></profiles></settings>';
assert.equal(new XMLSerializer().serializeToString(xml), expectedXml);
});
});
});