Skip to content

Commit 376a6b4

Browse files
authored
Removed the alias for chartNameForACR and chartPathForACR and added unit tests. (#13116)
* removing aliases for help chart save command * added unit tests for helm chart save command * addressing PR comments
1 parent 1aae4e7 commit 376a6b4

File tree

5 files changed

+73
-15
lines changed

5 files changed

+73
-15
lines changed

Tasks/HelmDeployV0/Tests/L0.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,5 +191,45 @@ describe("HelmDeployV0 Suite", function () {
191191
assert(tr.stdout.indexOf(`Successfully packaged chart and saved it to: ${shared.testDestinationPath}/testChartName.tgz`) !=-1 , "Chart should have been successfully packaged");
192192
assert(tr.succeeded, "task should have succeeded");
193193
done();
194-
});
194+
});
195+
196+
it("Run successfully with Helm save command (version 3)", function (done: MochaDone) {
197+
const tp = path.join(__dirname, "TestSetup.js");
198+
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
199+
process.env[shared.TestEnvVars.command] = shared.Commands.save;
200+
process.env[shared.TestEnvVars.connectionType] = shared.ConnectionTypes.None;
201+
process.env[shared.TestEnvVars.chartPathForACR] = shared.testChartPathForACR;
202+
process.env[shared.TestEnvVars.chartNameForACR] = shared.testChartNameForACR;
203+
process.env[shared.TestEnvVars.azureSubscriptionEndpointForACR] = shared.testAzureSubscriptionEndpointForACR;
204+
process.env[shared.TestEnvVars.azureResourceGroupForACR] = shared.testAzureResourceGroupForACR;
205+
process.env[shared.TestEnvVars.azureContainerRegistry] = shared.testAzureContainerRegistry;
206+
process.env[shared.TestEnvVars.failOnStderr] = "false";
207+
process.env[shared.isHelmV3] = "true";
208+
209+
tr.run();
210+
assert(tr.stdout.indexOf("Successfully saved the helm chart to local registry cache.") != -1, "Chart should have been successfully saved to local registry cache.");
211+
assert(tr.stdout.indexOf(`Successfully logged in to ${process.env[shared.TestEnvVars.azureContainerRegistry]}.`) != -1, "Azure container registry login should have been successful.");
212+
assert(tr.stdout.indexOf("Successfully pushed to the chart to container registry.") != -1, "Chart should have been successfully pushed to container registry.");
213+
assert(tr.stdout.indexOf("Successfully removed the chart from local cache.") != -1, "Chart should have been successfully removed from local cache.");
214+
assert(tr.succeeded, "task should have succeeded");
215+
done();
216+
});
217+
218+
it("Helm same should fail (version 2)", function (done: MochaDone) {
219+
const tp = path.join(__dirname, "TestSetup.js");
220+
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
221+
process.env[shared.TestEnvVars.command] = shared.Commands.save;
222+
process.env[shared.TestEnvVars.connectionType] = shared.ConnectionTypes.None;
223+
process.env[shared.TestEnvVars.chartPathForACR] = shared.testChartPathForACR;
224+
process.env[shared.TestEnvVars.chartNameForACR] = shared.testChartNameForACR;
225+
process.env[shared.TestEnvVars.azureSubscriptionEndpointForACR] = shared.testAzureSubscriptionEndpointForACR;
226+
process.env[shared.TestEnvVars.azureResourceGroupForACR] = shared.testAzureResourceGroupForACR;
227+
process.env[shared.TestEnvVars.azureContainerRegistry] = shared.testAzureContainerRegistry;
228+
process.env[shared.TestEnvVars.failOnStderr] = "false";
229+
230+
tr.run();
231+
assert(tr.failed, "task should have failed");
232+
assert(tr.stdout.indexOf("loc_mock_SaveSupportedInHelmsV3Only") != -1, "Chart save should have failed when helm version is not 3.");
233+
done();
234+
})
195235
});

Tasks/HelmDeployV0/Tests/TestSetup.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,30 @@ a.exec[kubectlClusterInfo] = {
268268
"stdout": `Kubernetes master is running at https://shigupt-cluster-dns-7489360e.hcp.southindia.azmk8s.io:443 \nhealthmodel-replicaset-service is running at https://shigupt-cluster-dns-7489360e.hcp.southindia.azmk8s.io:443/api/v1/namespaces/kube-system/services/healthmodel-replicaset-service/proxy \nCoreDNS is running at https://shigupt-cluster-dns-7489360e.hcp.southindia.azmk8s.io:443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy \nkubernetes-dashboard is running at https://shigupt-cluster-dns-7489360e.hcp.southindia.azmk8s.io:443/api/v1/namespaces/kube-system/services/kubernetes-dashboard/proxy \nMetrics-server is running at https://shigupt-cluster-dns-7489360e.hcp.southindia.azmk8s.io:443/api/v1/namespaces/kube-system/services/https:metrics-server:/proxy\n\nTo further debug and diagnose cluster problems, use "kubectl cluster-info dump".\n`
269269
}
270270

271+
const helmSaveCommand = `helm chart save ${process.env[shared.TestEnvVars.chartPathForACR]} ${process.env[shared.TestEnvVars.azureContainerRegistry]}/helm/${process.env[shared.TestEnvVars.chartNameForACR]}`;
272+
a.exec[helmSaveCommand] = {
273+
"code": 0,
274+
"stdout": `ref: ${process.env[shared.TestEnvVars.azureContainerRegistry]}/helm/${process.env[shared.TestEnvVars.chartNameForACR]}:0.1.0 \n Successfully saved the helm chart to local registry cache.`
275+
}
276+
277+
const helmRegistryLoginCommand = `helm registry login ${process.env[shared.TestEnvVars.azureContainerRegistry]} --username --password`;
278+
a.exec[helmRegistryLoginCommand] = {
279+
"code": 0,
280+
"stdout": `Successfully logged in to ${process.env[shared.TestEnvVars.azureContainerRegistry]}.`
281+
};
282+
283+
const helmChartPushCommand = `helm chart push ${process.env[shared.TestEnvVars.azureContainerRegistry]}/helm/${process.env[shared.TestEnvVars.chartNameForACR]}:0.1.0`;
284+
a.exec[helmChartPushCommand] = {
285+
"code": 0,
286+
"stdout": "Successfully pushed to the chart to container registry."
287+
}
288+
289+
const helmChartRemoveCommand = `helm chart remove ${process.env[shared.TestEnvVars.azureContainerRegistry]}/helm/${process.env[shared.TestEnvVars.chartNameForACR]}:0.1.0`;
290+
a.exec[helmChartRemoveCommand] = {
291+
"code": 0,
292+
"stdout": "Successfully removed the chart from local cache."
293+
}
294+
271295
tr.setAnswers(<any>a);
272296
tr.registerMock("azure-pipelines-task-lib/toolrunner", require("azure-pipelines-task-lib/mock-toolrunner"));
273297

Tasks/HelmDeployV0/Tests/TestShared.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ export const testReleaseName = "testReleaseName";
6666
export const isHelmV3 = "__isHelmV3__";
6767
export const testNamespace = "testNamespace";
6868
export const testDestinationPath = "testDestinationPath";
69+
export const testChartNameForACR = "testChartNameForACR";
70+
export const testChartPathForACR = "test/testChartPathForACR";
71+
export const testAzureResourceGroupForACR = "test-rg";
72+
export const testAzureSubscriptionEndpointForACR = "RMTest";
73+
export const testAzureContainerRegistry = "sonayak.azurecr.io";
74+
6975
/**
7076
* Formats the given path to be appropriate for the operating system.
7177
* @param canonicalPath A non-rooted path using a forward slash (/) as a directory separator.

Tasks/HelmDeployV0/task.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 0,
1616
"Minor": 171,
17-
"Patch": 2
17+
"Patch": 3
1818
},
1919
"demands": [],
2020
"groups": [
@@ -436,9 +436,6 @@
436436
},
437437
{
438438
"name": "chartNameForACR",
439-
"aliases": [
440-
"chartName"
441-
],
442439
"label": "Chart Name For Azure Container Registry",
443440
"type": "string",
444441
"helpMarkDown": "Chart name with which the chart will be stored in Azure Container Registry.",
@@ -449,9 +446,6 @@
449446
},
450447
{
451448
"name": "chartPathForACR",
452-
"aliases": [
453-
"chartPath"
454-
],
455449
"label": "Chart Path for Azure Container Registry",
456450
"type": "filePath",
457451
"helpMarkDown": "Path to the chart directory.",

Tasks/HelmDeployV0/task.loc.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 0,
1616
"Minor": 171,
17-
"Patch": 2
17+
"Patch": 3
1818
},
1919
"demands": [],
2020
"groups": [
@@ -436,9 +436,6 @@
436436
},
437437
{
438438
"name": "chartNameForACR",
439-
"aliases": [
440-
"chartName"
441-
],
442439
"label": "ms-resource:loc.input.label.chartNameForACR",
443440
"type": "string",
444441
"helpMarkDown": "ms-resource:loc.input.help.chartNameForACR",
@@ -449,9 +446,6 @@
449446
},
450447
{
451448
"name": "chartPathForACR",
452-
"aliases": [
453-
"chartPath"
454-
],
455449
"label": "ms-resource:loc.input.label.chartPathForACR",
456450
"type": "filePath",
457451
"helpMarkDown": "ms-resource:loc.input.help.chartPathForACR",

0 commit comments

Comments
 (0)