Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Commit

Permalink
Update unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
RealNickk committed Oct 17, 2022
1 parent 096b660 commit d04756f
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 148 deletions.
28 changes: 21 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ on:
branches:
- main
paths:
- ".github/workflows/**"
- "src/**"
- ".github/workflows/**" # This is the path to the workflow files
- "src/**" # Any source files

env:
GITHUB_ACTIONS: 1
IS_CI: 1 # Let the build know that it's running in CI, so it doesn't run stuff that'll fail

jobs:
ci:
Expand All @@ -27,14 +27,28 @@ jobs:
- name: Setup NuGet
uses: NuGet/[email protected]

- name: Setup NUnit
run: nuget install NUnit.ConsoleRunner -Version 3.15.2 -OutputDirectory nunit

- name: Restore packages
run: nuget restore src/Starlight.sln
run: nuget restore Starlight.sln

- name: Build solution
run: msbuild.exe src/Starlight.sln -p:Configuration=Release
run: msbuild.exe Starlight.sln -p:Configuration=Release

- name: Run tests
run: testrunner/NUnit.ConsoleRunner.3.15.2/tools/nunit3-console.exe src/Starlight.Test/bin/Release/Starlight.Test.dll

- name: Upload artifacts
uses: actions/[email protected]
with:
name: starlight-bundle
path: "src/Starlight/bin/Release"
name: bundle
path: "bin/Release/"

- name: Upload test artifacts # Maybe useful for debugging...
uses: actions/[email protected]
with:
name: test-results
path: |
"TestResult.xml"
"src/Starlight.Test/bin/Release/Logs/"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
##
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore

# Unit testing
/testrunner/

# User-specific files
*.rsuser
*.suo
Expand Down
61 changes: 0 additions & 61 deletions src/Starlight.Test/Bootstrapper.cs

This file was deleted.

106 changes: 106 additions & 0 deletions src/Starlight.Test/BootstrapperTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using NUnit.Framework;
using Starlight.Core;
using Starlight.Misc;
using System;
using System.IO;
using System.Threading;

namespace Starlight.Test
{
[TestFixture]
public class BootstrapperTests
{
[OneTimeSetUp]
public void InitLogger()
{
Logger.Init(true);
}

[Test]
public void GetLatestHash()
{
try
{
Bootstrapper.GetLatestHash();
}
catch (BootstrapException)
{
Assert.Inconclusive("Couldn't fetch latest hash.");
}
}

[Test]
public void FetchManifest()
{
var manifest = Bootstrapper.GetManifest(Bootstrapper.GetLatestHash());
if (manifest is null)
Assert.Inconclusive("Couldn't fetch manifest.");
}

static void PreNativeInstall()
{
var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
var installPath = Path.Combine(localAppData, "Roblox");

// Uninstall Roblox if it's installed.
if (Directory.Exists(installPath))
Directory.Delete(installPath, true);
}

[Test]
public void NativeInstall()
{
Env.AssertCi();

PreNativeInstall();
try
{
var client = Bootstrapper.NativeInstall();
Assert.IsFalse(client is null, "Client installation failed.");
}
catch (BootstrapException ex)
{
Assert.Fail("Client installation failed: " + ex.Message, ex);
}
Thread.Sleep(1000); // idk bruh it works lol
}

[Test]
public void Query()
{
Env.AssertCi();

if (Bootstrapper.GetClients().Count < 1)
Bootstrapper.Install();

var clients = Bootstrapper.GetClients();
if (clients.Count < 1)
Assert.Fail("Failed to find any clients.");

var client = Bootstrapper.QueryClient(clients[0].Hash);
Assert.IsFalse(client is null, "Client query failed.");
}

[Test]
public void Uninstall()
{
Env.AssertCi();

if (Bootstrapper.GetClients().Count < 1)
Bootstrapper.Install();

var clients = Bootstrapper.GetClients();
Bootstrapper.Uninstall(clients[0]);
}

[Test]
public void Install()
{
Env.AssertCi();

var client = Bootstrapper.Install();
if (client is null)
Assert.Fail("Client installation failed.");
}
}
}
18 changes: 18 additions & 0 deletions src/Starlight.Test/Env.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using NUnit.Framework;

namespace Starlight.Test
{
internal class Env
{
public static bool IsCi => Environment.GetEnvironmentVariable("IS_CI") is not null;

public static string AuthToken => Environment.GetEnvironmentVariable("AUTH_TOKEN");

public static void AssertCi()
{
if (IsCi)
Assert.Inconclusive("Cannot run this test on CI.");
}
}
}
18 changes: 18 additions & 0 deletions src/Starlight.Test/Initial.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using NUnit.Framework;
using Starlight.Misc;

namespace Starlight.Test
{
[TestFixture, Order(1)]
internal class Initial
{
[OneTimeSetUp]
public void Initialize()
{
Logger.Init(true);
if (Env.IsCi)
Console.WriteLine("Running on CI. ENSURE THAT INCONCLUSIVE TESTS PASS BEFORE YOU MERGE A PR!");
}
}
}
60 changes: 0 additions & 60 deletions src/Starlight.Test/Launcher.cs

This file was deleted.

50 changes: 50 additions & 0 deletions src/Starlight.Test/LauncherTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using NUnit.Framework;
using Starlight.Core;
using Starlight.Rbx;
using Starlight.Rbx.JoinGame;

namespace Starlight.Test
{
[TestFixture, Order(2)]
public class LauncherTests
{
[Test]
public void Launch()
{
Env.AssertCi();

if (Bootstrapper.GetClients().Count < 1)
Bootstrapper.Install();

if (Env.AuthToken is null)
Assert.Inconclusive("No Roblox token was provided. Please set the AUTH_TOKEN environment variable.");

var session = Session.Login(Env.AuthToken);
var ticket = session.GetTicket();

var info = new LaunchParams
{
// Roblox join stuff.
Ticket = ticket,
Request = new JoinRequest
{
PlaceId = 4483381587, // https://www.roblox.com/games/4483381587/a-literal-baseplate
ReqType = JoinType.Auto
},

// Should make everything run
FpsCap = 160,
Headless = true,
Spoof = true,
Resolution = "800x600"
};

// Launch Roblox
var inst = Launcher.Launch(info);
if (inst is null)
Assert.Fail("Failed to launch Roblox.");

inst.Proc.Kill();
}
}
}
20 changes: 0 additions & 20 deletions src/Starlight.Test/Setup.cs

This file was deleted.

Loading

0 comments on commit d04756f

Please sign in to comment.