-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Viji
committed
Sep 30, 2024
1 parent
99437b8
commit e93bb7e
Showing
11 changed files
with
705 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,12 @@ | |
using System.Linq; | ||
using LCT.ArtifactoryUploader.Model; | ||
using LCT.APICommunications; | ||
using System.Net.Http; | ||
using System.Net; | ||
using LCT.APICommunications.Model.AQL; | ||
using LCT.Services.Interface; | ||
using Moq; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel; | ||
|
||
namespace AritfactoryUploader.UTest | ||
{ | ||
|
@@ -317,5 +323,262 @@ private static List<Component> GetComponentList() | |
componentLists.Add(comp4); | ||
return componentLists; | ||
} | ||
|
||
[Test] | ||
public void GetUploadPackageDetails_CoversAllScenarios() | ||
{ | ||
// Arrange | ||
DisplayPackagesInfo displayPackagesInfo = new DisplayPackagesInfo() | ||
{ | ||
JfrogFoundPackagesConan = new List<ComponentsToArtifactory>() | ||
{ | ||
new ComponentsToArtifactory() | ||
{ | ||
ResponseMessage = new HttpResponseMessage() | ||
{ | ||
StatusCode = HttpStatusCode.OK | ||
} | ||
} | ||
}, | ||
JfrogFoundPackagesMaven = new List<ComponentsToArtifactory>() | ||
{ | ||
new ComponentsToArtifactory() | ||
{ | ||
ResponseMessage = new HttpResponseMessage() | ||
{ | ||
StatusCode = HttpStatusCode.OK | ||
} | ||
} | ||
}, | ||
JfrogFoundPackagesNpm = new List<ComponentsToArtifactory>() | ||
{ | ||
new ComponentsToArtifactory() | ||
{ | ||
ResponseMessage = new HttpResponseMessage() | ||
{ | ||
StatusCode = HttpStatusCode.OK | ||
} | ||
} | ||
}, | ||
JfrogFoundPackagesNuget = new List<ComponentsToArtifactory>() | ||
{ | ||
new ComponentsToArtifactory() | ||
{ | ||
ResponseMessage = new HttpResponseMessage() | ||
{ | ||
StatusCode = HttpStatusCode.OK | ||
} | ||
} | ||
}, | ||
JfrogFoundPackagesPython = new List<ComponentsToArtifactory>() | ||
{ | ||
new ComponentsToArtifactory() | ||
{ | ||
ResponseMessage = new HttpResponseMessage() | ||
{ | ||
StatusCode = HttpStatusCode.OK | ||
} | ||
} | ||
}, | ||
JfrogFoundPackagesDebian = new List<ComponentsToArtifactory>() | ||
{ | ||
new ComponentsToArtifactory() | ||
{ | ||
ResponseMessage = new HttpResponseMessage() | ||
{ | ||
StatusCode = HttpStatusCode.OK | ||
} | ||
} | ||
} | ||
}; | ||
|
||
// Act | ||
List<ComponentsToArtifactory> uploadedPackages = PackageUploadHelper.GetUploadePackageDetails(displayPackagesInfo); | ||
|
||
// Assert | ||
Assert.AreEqual(6, uploadedPackages.Count); | ||
} | ||
|
||
[Test] | ||
public async Task GetSrcRepoDetailsForPyPiOrConanPackages_WhenPypiRepoExists_ReturnsArtifactoryRepoName() | ||
{ | ||
// Arrange | ||
Property prop1 = new Property | ||
{ | ||
Name = Dataconstant.Cdx_ArtifactoryRepoName, | ||
Value = "Reponame" | ||
}; | ||
List<Property> properties = new List<Property>() { prop1 }; | ||
var item = new Component | ||
{ | ||
Purl = "pypi://example-package", | ||
Properties = properties, | ||
Name = "pypi component", | ||
Version = "1.0.0" | ||
}; | ||
|
||
//GetInternalComponentDataByRepo | ||
var aqlResultList = new List<AqlResult> | ||
{ | ||
new AqlResult | ||
{ | ||
Repo = "pypi-repo", | ||
Path = "path/to/package", | ||
Name = "pypi component-1.0.0", | ||
} | ||
}; | ||
var jFrogServiceMock = new Mock<IJFrogService>(); | ||
jFrogServiceMock.Setup(x => x.GetInternalComponentDataByRepo(It.IsAny<string>())).ReturnsAsync(aqlResultList); | ||
PackageUploadHelper.jFrogService = jFrogServiceMock.Object; | ||
|
||
// Act | ||
var result = await PackageUploadHelper.GetSrcRepoDetailsForPyPiOrConanPackages(item); | ||
|
||
// Assert | ||
Assert.IsNotNull(result); | ||
Assert.AreEqual("pypi-repo", result.Repo); | ||
Assert.AreEqual("path/to/package", result.Path); | ||
} | ||
|
||
[Test] | ||
public async Task GetSrcRepoDetailsForPyPiOrConanPackages_WhenConanRepoExists_ReturnsArtifactoryRepoName() | ||
{ | ||
// Arrange | ||
Property prop1 = new Property | ||
{ | ||
Name = Dataconstant.Cdx_ArtifactoryRepoName, | ||
Value = "Reponame" | ||
}; | ||
List<Property> properties = new List<Property>() { prop1 }; | ||
|
||
var item = new Component | ||
{ | ||
Purl = "conan://example-package", | ||
Properties = properties, | ||
Name = "conan component", | ||
Version = "1.0.0" | ||
}; | ||
|
||
var aqlResultList = new List<AqlResult> | ||
{ | ||
new AqlResult | ||
{ | ||
Repo = "conan-repo", | ||
Path = "path/to/conan component/1.0.0", | ||
Name = "conan component-1.0.0", | ||
} | ||
}; | ||
|
||
var jFrogServiceMock = new Mock<IJFrogService>(); | ||
jFrogServiceMock.Setup(x => x.GetInternalComponentDataByRepo(It.IsAny<string>())).ReturnsAsync(aqlResultList); | ||
PackageUploadHelper.jFrogService = jFrogServiceMock.Object; | ||
|
||
// Act | ||
var result = await PackageUploadHelper.GetSrcRepoDetailsForPyPiOrConanPackages(item); | ||
|
||
// Assert | ||
Assert.IsNotNull(result); | ||
Assert.AreEqual("conan-repo", result.Repo); | ||
Assert.AreEqual("path/to/conan component/1.0.0", result.Path); | ||
} | ||
|
||
[Test] | ||
public async Task GetSrcRepoDetailsForPyPiOrConanPackages_WhenNoRepoExists_ReturnsNull() | ||
{ | ||
// Arrange | ||
var item = new Component | ||
{ | ||
Purl = "unknown://example-package" | ||
}; | ||
var jFrogServiceMock = new Mock<IJFrogService>(); | ||
PackageUploadHelper.jFrogService = jFrogServiceMock.Object; | ||
|
||
// Act | ||
var result = await PackageUploadHelper.GetSrcRepoDetailsForPyPiOrConanPackages(item); | ||
|
||
// Assert | ||
Assert.IsNull(result); | ||
} | ||
|
||
[Test] | ||
[TestCase("NPM", ".tgz")] | ||
[TestCase("NUGET", ".nupkg")] | ||
[TestCase("MAVEN", ".jar")] | ||
[TestCase("DEBIAN", ".deb")] | ||
[TestCase("PYTHON", ".whl")] | ||
[TestCase("CONAN", "package.tgz")] | ||
public void GetPkgeNameExtensionBasedOnComponentType_GivenType_ReturnsPkgNameExtension(string type, string extension) | ||
{ | ||
// Arrange | ||
var package = new ComponentsToArtifactory(); | ||
package.ComponentType = type; | ||
// Act | ||
var actualExtension = PackageUploadHelper.GetPackageNameExtensionBasedOnComponentType(package); | ||
// Assert | ||
Assert.AreEqual(extension, actualExtension); | ||
} | ||
|
||
[Test] | ||
public void GetJfrogApiCommInstance_GivenComponent_ReturnsJfrogApiCommunicationInstance() | ||
{ | ||
// Arrange | ||
var component = new ComponentsToArtifactory | ||
{ | ||
ComponentType = "MAVEN", | ||
JfrogApi = "https://api.jfrog.com", | ||
SrcRepoName = "maven-repo", | ||
ApiKey = "api-key", | ||
Email = "[email protected]" | ||
}; | ||
var timeout = 5000; | ||
|
||
// Act | ||
var result = PackageUploadHelper.GetJfrogApiCommInstance(component, timeout); | ||
|
||
// Assert | ||
Assert.IsInstanceOf<MavenJfrogApiCommunication>(result); | ||
} | ||
|
||
[Test] | ||
public void GetJfrogApiCommInstance_GivenComponentWithPythonType_ReturnsJfrogApiCommunicationInstance() | ||
{ | ||
// Arrange | ||
var component = new ComponentsToArtifactory | ||
{ | ||
ComponentType = "PYTHON", | ||
JfrogApi = "https://api.jfrog.com", | ||
SrcRepoName = "python-repo", | ||
ApiKey = "api-key", | ||
Email = "[email protected]" | ||
}; | ||
var timeout = 5000; | ||
|
||
// Act | ||
var result = PackageUploadHelper.GetJfrogApiCommInstance(component, timeout); | ||
|
||
// Assert | ||
Assert.IsInstanceOf<PythonJfrogApiCommunication>(result); | ||
} | ||
|
||
[Test] | ||
public void GetJfrogApiCommInstance_GivenComponentWithUnknownType_ReturnsJfrogApiCommunicationInstance() | ||
{ | ||
// Arrange | ||
var component = new ComponentsToArtifactory | ||
{ | ||
ComponentType = "UNKNOWN", | ||
JfrogApi = "https://api.jfrog.com", | ||
SrcRepoName = "unknown-repo", | ||
ApiKey = "api-key", | ||
Email = "[email protected]" | ||
}; | ||
var timeout = 5000; | ||
|
||
// Act | ||
var result = PackageUploadHelper.GetJfrogApiCommInstance(component, timeout); | ||
|
||
// Assert | ||
Assert.IsInstanceOf<NpmJfrogApiCommunication>(result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// SPDX-FileCopyrightText: 2024 Siemens AG | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
using LCT.Common.Runtime; | ||
using NUnit.Framework; | ||
using System; | ||
|
||
namespace LCT.Common.UTest | ||
{ | ||
[TestFixture] | ||
internal class EnvironmentTypeTests | ||
{ | ||
[Test] | ||
public void EnumValues_ShouldMatchExpectedValues() | ||
{ | ||
// Arrange | ||
var expectedValues = new[] | ||
{ | ||
EnvironmentType.Unknown, | ||
EnvironmentType.GitLab, | ||
EnvironmentType.AzurePipeline, | ||
EnvironmentType.AzureRelease | ||
}; | ||
|
||
// Act | ||
var actualValues = (EnvironmentType[])Enum.GetValues(typeof(EnvironmentType)); | ||
|
||
// Assert | ||
Assert.That(actualValues.Length, Is.EqualTo(expectedValues.Length)); | ||
for (int i = 0; i < expectedValues.Length; i++) | ||
{ | ||
Assert.That(actualValues[i], Is.EqualTo(expectedValues[i])); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.