|
| 1 | +// ---------------------------------------------------------------------------------- |
| 2 | +// |
| 3 | +// Copyright Microsoft Corporation |
| 4 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// Unless required by applicable law or agreed to in writing, software |
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +// See the License for the specific language governing permissions and |
| 12 | +// limitations under the License. |
| 13 | +// ---------------------------------------------------------------------------------- |
| 14 | + |
| 15 | +using Microsoft.Azure.Commands.HDInsight; |
| 16 | +using Microsoft.Azure.Commands.HDInsight.ManagementCommands; |
| 17 | +using Microsoft.Azure.Commands.HDInsight.Models; |
| 18 | +using Microsoft.Azure.Commands.HDInsight.Test; |
| 19 | +using Microsoft.Azure.ServiceManagemenet.Common.Models; |
| 20 | +using Microsoft.WindowsAzure.Commands.Common; |
| 21 | +using Microsoft.WindowsAzure.Commands.ScenarioTest; |
| 22 | +using Moq; |
| 23 | +using System; |
| 24 | +using System.Management.Automation; |
| 25 | +using Xunit; |
| 26 | + |
| 27 | +namespace Commands.HDInsight.Test.UnitTests |
| 28 | +{ |
| 29 | + public class DataLakeStoreDefaultFilesystemTests : HDInsightTestBase |
| 30 | + { |
| 31 | + private NewAzureHDInsightClusterCommand cmdlet; |
| 32 | + private const string StorageName = "dummystorage.azuredatalakestore.net"; |
| 33 | + private const int ClusterSize = 4; |
| 34 | + private Guid ObjectId = new Guid("11111111-1111-1111-1111-111111111111"); |
| 35 | + private Guid AadTenantId = new Guid("11111111-1111-1111-1111-111111111111"); |
| 36 | + private string Certificate = ""; |
| 37 | + private string CertificatePassword = ""; |
| 38 | + private byte[] CertificateFileContents = { }; |
| 39 | + private readonly PSCredential _httpCred; |
| 40 | + private Mock<AzureHDInsightConfig> AzureHDInsightconfigMock; |
| 41 | + |
| 42 | + public DataLakeStoreDefaultFilesystemTests(Xunit.Abstractions.ITestOutputHelper output) |
| 43 | + { |
| 44 | + XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output)); |
| 45 | + base.SetupTestsForManagement(); |
| 46 | + _httpCred = new PSCredential("hadoopuser", string.Format("Password1!").ConvertToSecureString()); |
| 47 | + cmdlet = new NewAzureHDInsightClusterCommand |
| 48 | + { |
| 49 | + CommandRuntime = commandRuntimeMock.Object, |
| 50 | + HDInsightManagementClient = hdinsightManagementMock.Object |
| 51 | + }; |
| 52 | + AzureHDInsightconfigMock = new Mock<AzureHDInsightConfig>(); |
| 53 | + } |
| 54 | + |
| 55 | + [Fact] |
| 56 | + [Trait(Category.AcceptanceType, Category.CheckIn)] |
| 57 | + public void CanCreateClusterConfigWithDataLakeStoreParameters() |
| 58 | + { |
| 59 | + var newclusteridentitycmdlet = new NewAzureHDInsightClusterConfigCommand() |
| 60 | + { |
| 61 | + CommandRuntime = commandRuntimeMock.Object, |
| 62 | + HDInsightManagementClient = hdinsightManagementMock.Object, |
| 63 | + ObjectId = ObjectId, |
| 64 | + CertificateFilePath = Certificate, |
| 65 | + AadTenantId = AadTenantId, |
| 66 | + CertificatePassword = CertificatePassword, |
| 67 | + DefaultStorageAccountName = StorageName |
| 68 | + }; |
| 69 | + |
| 70 | + newclusteridentitycmdlet.ExecuteCmdlet(); |
| 71 | + commandRuntimeMock.Verify( |
| 72 | + f => |
| 73 | + f.WriteObject( |
| 74 | + It.Is<AzureHDInsightConfig>( |
| 75 | + c => |
| 76 | + c.AADTenantId == AadTenantId && |
| 77 | + c.CertificatePassword == CertificatePassword && |
| 78 | + c.ObjectId == ObjectId && |
| 79 | + c.CertificateFilePath == Certificate && |
| 80 | + c.DefaultStorageAccountName == StorageName |
| 81 | + )), |
| 82 | + Times.Once); |
| 83 | + } |
| 84 | + |
| 85 | + [Fact] |
| 86 | + [Trait(Category.AcceptanceType, Category.CheckIn)] |
| 87 | + public void CanCreateDataLakeClusterWithCertificateFileContents() |
| 88 | + { |
| 89 | + var clusterIdentityCmdlet = new NewAzureHDInsightClusterConfigCommand() |
| 90 | + { |
| 91 | + CommandRuntime = commandRuntimeMock.Object, |
| 92 | + HDInsightManagementClient = hdinsightManagementMock.Object, |
| 93 | + ObjectId = ObjectId, |
| 94 | + CertificateFileContents = CertificateFileContents, |
| 95 | + AadTenantId = AadTenantId, |
| 96 | + CertificatePassword = CertificatePassword, |
| 97 | + DefaultStorageAccountName = StorageName |
| 98 | + }; |
| 99 | + |
| 100 | + clusterIdentityCmdlet.ExecuteCmdlet(); |
| 101 | + commandRuntimeMock.Verify( |
| 102 | + f => |
| 103 | + f.WriteObject( |
| 104 | + It.Is<AzureHDInsightConfig>( |
| 105 | + c => |
| 106 | + c.AADTenantId == AadTenantId && |
| 107 | + c.CertificatePassword == CertificatePassword && |
| 108 | + c.ObjectId == ObjectId && |
| 109 | + c.CertificateFileContents == CertificateFileContents && |
| 110 | + c.DefaultStorageAccountName == StorageName |
| 111 | + )), |
| 112 | + Times.Once); |
| 113 | + } |
| 114 | + |
| 115 | + [Fact] |
| 116 | + [Trait(Category.AcceptanceType, Category.CheckIn)] |
| 117 | + public void ShouldThrowIfCertificateOptionsAreNotPassed() |
| 118 | + { |
| 119 | + var clusterIdentityCmdlet = new AddAzureHDInsightClusterIdentity() |
| 120 | + { |
| 121 | + CommandRuntime = commandRuntimeMock.Object, |
| 122 | + HDInsightManagementClient = hdinsightManagementMock.Object, |
| 123 | + ObjectId = ObjectId, |
| 124 | + AadTenantId = AadTenantId, |
| 125 | + CertificatePassword = CertificatePassword |
| 126 | + }; |
| 127 | + |
| 128 | + Assert.Throws<ArgumentException>(() => clusterIdentityCmdlet.ExecuteCmdlet()); |
| 129 | + } |
| 130 | + |
| 131 | + [Fact] |
| 132 | + [Trait(Category.AcceptanceType, Category.CheckIn)] |
| 133 | + public void ShouldThrowIfBothCertificateOptionsArePassed() |
| 134 | + { |
| 135 | + var clusterIdentityCmdlet = new AddAzureHDInsightClusterIdentity() |
| 136 | + { |
| 137 | + CommandRuntime = commandRuntimeMock.Object, |
| 138 | + HDInsightManagementClient = hdinsightManagementMock.Object, |
| 139 | + ObjectId = ObjectId, |
| 140 | + AadTenantId = AadTenantId, |
| 141 | + CertificatePassword = CertificatePassword, |
| 142 | + CertificateFileContents = CertificateFileContents, |
| 143 | + CertificateFilePath = Certificate |
| 144 | + }; |
| 145 | + |
| 146 | + Assert.Throws<ArgumentException>(() => clusterIdentityCmdlet.ExecuteCmdlet()); |
| 147 | + } |
| 148 | + } |
| 149 | +} |
| 150 | + |
0 commit comments