Skip to content

Commit

Permalink
[Tests] Replace azurestorage with a github repo. (dotnet#7524)
Browse files Browse the repository at this point in the history
Our `https://xamjenkinsartifact.azureedge.net` site for some of the
unit test data seems to have disappeared.

So lets use a github repo to store this data instead. The unit tests
can download the raw files directly from github. The repo will be
public as well so there won't be any need for authorization.

Update `DeleteBinObjTest` to use `7z`
  • Loading branch information
dellis1972 authored Nov 3, 2022
1 parent 6573c37 commit ca2c629
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ public void TearDown ()
Directory.Delete (tempDirectory, recursive: true);
}

Task<string> DownloadFromNuGet (string url) =>
Task.Factory.StartNew (() => new DownloadedCache ().GetAsFile (url));
Task<string> DownloadFromNuGet (string url, string filename = "") =>
Task.Factory.StartNew (() => new DownloadedCache ().GetAsFile (url, filename));

async Task<string []> GetAssembliesFromNuGet (string url, string path)
async Task<string []> GetAssembliesFromNuGet (string url, string filename, string path)
{
var assemblies = new List<string> ();
var nuget = await DownloadFromNuGet (url);
var nuget = await DownloadFromNuGet (url, filename);
using (var zip = ZipArchive.Open (nuget, FileMode.Open)) {
foreach (var entry in zip) {
if (entry.FullName.StartsWith (path, StringComparison.OrdinalIgnoreCase) &&
Expand Down Expand Up @@ -67,6 +67,7 @@ public async Task CircleImageView ()
{
var assemblies = await GetAssembliesFromNuGet (
"https://www.nuget.org/api/v2/package/Refractored.Controls.CircleImageView/1.0.1",
"Refractored.Controls.CircleImageView.1.0.1.nupkg",
"lib/MonoAndroid10/");
var actual = Run (assemblies);
var expected = new [] { "Refractored.Controls.CircleImageView.dll" };
Expand All @@ -78,6 +79,7 @@ public async Task XamarinForms ()
{
var assemblies = await GetAssembliesFromNuGet (
"https://www.nuget.org/api/v2/package/Xamarin.Forms/3.6.0.220655",
"Xamarin.Forms.3.6.0.220655.nupkg",
"lib/MonoAndroid90/");
var actual = Run (assemblies);
var expected = new [] {
Expand All @@ -93,6 +95,7 @@ public async Task GuavaListenableFuture ()
{
var assemblies = await GetAssembliesFromNuGet (
"https://www.nuget.org/api/v2/package/Xamarin.Google.Guava.ListenableFuture/1.0.0",
"Xamarin.Google.Guava.ListenableFuture.1.0.0.nupkg",
"lib/MonoAndroid50/");
var actual = Run (assemblies);
var expected = new [] { "Xamarin.Google.Guava.ListenableFuture.dll" };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ public string WebContent {
}

/// <summary>
/// NOTE: downloads a file from our https://xamjenkinsartifact.azureedge.net/ Azure Storage Account
/// NOTE: downloads a file from our https://github.com/dellis1972/xamarin-android-unittest-files repo
/// </summary>
public string WebContentFileNameFromAzure {
get { throw new NotSupportedException (); }
set { WebContent = $"https://xamjenkinsartifact.azureedge.net/mono-jenkins/xamarin-android-test/{value}"; }
set { WebContent = $"https://github.com/dellis1972/xamarin-android-unittest-files/blob/main/{value}?raw=true"; }
}

public string MetadataValues {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public DownloadedCache (string cacheDirectory)

public string CacheDirectory { get; private set; }

public string GetAsFile (string url)
public string GetAsFile (string url, string filename = "")
{
Directory.CreateDirectory (CacheDirectory);

var filename = Path.Combine (CacheDirectory, Path.GetFileName (new Uri (url).LocalPath));
filename = Path.Combine (CacheDirectory, string.IsNullOrEmpty (filename) ? Path.GetFileName (new Uri (url).LocalPath) : filename);
lock (locks.GetOrAdd (filename, _ => new object ())) {
if (File.Exists (filename))
return filename;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.IO;
using System.Diagnostics;

namespace Xamarin.ProjectTools {
public class SevenZipHelper : IDisposable {
public string ArchivePath { get; private set; }

public SevenZipHelper (string archivePath)
{
ArchivePath = archivePath;
}

public bool ExtractAll (string destinationDir)
{
using (var p = new Process ()) {
p.StartInfo.FileName = Path.Combine ("7z");
p.StartInfo.Arguments = $"x {ArchivePath} -o{destinationDir}";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.ErrorDataReceived += (sender, e) => {
if (e.Data != null) {
Console.WriteLine (e.Data);
}
};
p.ErrorDataReceived += (sender, e) => {
if (e.Data != null) {
Console.WriteLine (e.Data);
}
};

p.Start ();
p.BeginOutputReadLine ();
p.BeginErrorReadLine ();
bool completed = p.WaitForExit ((int) new TimeSpan (0, 15, 0).TotalMilliseconds);
return completed && p.ExitCode == 0;
}
}

public void Dispose ()
{
}

public static SevenZipHelper Open (string path, FileMode fileMode)
{
return new SevenZipHelper (path);
}
}
}
8 changes: 3 additions & 5 deletions tests/MSBuildDeviceIntegration/Tests/DeleteBinObjTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@
using System.Collections.Generic;
using System.IO;
using Xamarin.ProjectTools;
using Xamarin.Tools.Zip;

namespace Xamarin.Android.Build.Tests
{
[TestFixture]
[Category ("DotNetIgnore"), Category ("Node-1")] // .csproj files are legacy projects that won't build under dotnet
public class DeleteBinObjTest : DeviceTest
{
const string BaseUrl = "https://xamjenkinsartifact.azureedge.net/mono-jenkins/xamarin-android-test/";
const string BaseUrl = "https://github.com/dellis1972/xamarin-android-unittest-files/blob/main/";
readonly DownloadedCache Cache = new DownloadedCache ();

string HostOS => IsWindows ? "Windows" : "Darwin";

void RunTest (string name, string sln, string csproj, string version, string revision, string packageName, string javaPackageName, bool isRelease)
{
var configuration = isRelease ? "Release" : "Debug";
var zipPath = Cache.GetAsFile ($"{BaseUrl}{name}-{version}-{HostOS}-{revision}.zip");
var zipPath = Cache.GetAsFile ($"{BaseUrl}{name}-{version}-{HostOS}-{revision}.7z?raw=true");
using (var builder = CreateApkBuilder (Path.Combine ("temp", TestName)))
using (var zip = ZipArchive.Open (zipPath, FileMode.Open)) {
using (var zip = SevenZipHelper.Open (zipPath, FileMode.Open)) {
builder.AutomaticNuGetRestore = false;

if (!builder.TargetFrameworkExists ("v9.0")) {
Expand Down

0 comments on commit ca2c629

Please sign in to comment.