From e743a1cd7bfa2816f00b013441221fe7ad40a469 Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 21 Nov 2024 14:17:57 +0100 Subject: [PATCH] basic info tests --- ProjectPlugins/CodexPlugin/CodexAccess.cs | 16 ++++++ ProjectPlugins/CodexPlugin/CodexNode.cs | 6 +++ .../NodeTests/BasicInfoTests.cs | 54 ++++++++++++++++++- 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/ProjectPlugins/CodexPlugin/CodexAccess.cs b/ProjectPlugins/CodexPlugin/CodexAccess.cs index 8140ff5..3e28ab3 100644 --- a/ProjectPlugins/CodexPlugin/CodexAccess.cs +++ b/ProjectPlugins/CodexPlugin/CodexAccess.cs @@ -32,6 +32,22 @@ namespace CodexPlugin return mapper.Map(OnCodex(api => api.GetDebugInfoAsync())); } + public string GetSpr() + { + return CrashCheck(() => + { + var endpoint = GetEndpoint(); + var json = endpoint.HttpGetString("spr"); + var response = JsonConvert.DeserializeObject(json); + return response!.Spr; + }); + } + + private class SprResponse + { + public string Spr { get; set; } = string.Empty; + } + public DebugPeer GetDebugPeer(string peerId) { // Cannot use openAPI: debug/peer endpoint is not specified there. diff --git a/ProjectPlugins/CodexPlugin/CodexNode.cs b/ProjectPlugins/CodexPlugin/CodexNode.cs index fe978c6..2b6ddcb 100644 --- a/ProjectPlugins/CodexPlugin/CodexNode.cs +++ b/ProjectPlugins/CodexPlugin/CodexNode.cs @@ -15,6 +15,7 @@ namespace CodexPlugin string GetName(); string GetPeerId(); DebugInfo GetDebugInfo(); + string GetSpr(); DebugPeer GetDebugPeer(string peerId); ContentId UploadFile(TrackedFile file); ContentId UploadFile(TrackedFile file, Action onFailure); @@ -130,6 +131,11 @@ namespace CodexPlugin return debugInfo; } + public string GetSpr() + { + return CodexAccess.GetSpr(); + } + public DebugPeer GetDebugPeer(string peerId) { return CodexAccess.GetDebugPeer(peerId); diff --git a/Tests/CodexReleaseTests/NodeTests/BasicInfoTests.cs b/Tests/CodexReleaseTests/NodeTests/BasicInfoTests.cs index 94533ec..914bedd 100644 --- a/Tests/CodexReleaseTests/NodeTests/BasicInfoTests.cs +++ b/Tests/CodexReleaseTests/NodeTests/BasicInfoTests.cs @@ -1,12 +1,62 @@ -using System; +using CodexPlugin; +using CodexTests; +using NUnit.Framework; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Utils; namespace CodexReleaseTests.NodeTests { - internal class BasicInfoTests + [TestFixture] + public class BasicInfoTests : CodexDistTest { + [Test] + public void QuotaTest() + { + var size = 3.GB(); + var node = StartCodex(s => s.WithStorageQuota(size)); + var space = node.Space(); + + Assert.That(space.QuotaMaxBytes, Is.EqualTo(size.SizeInBytes)); + } + + [Test] + public void Spr() + { + var node = StartCodex(); + + var info = node.GetDebugInfo(); + Assert.That(!string.IsNullOrEmpty(info.Spr)); + + var spr = node.GetSpr(); + Assert.That(!string.IsNullOrEmpty(spr)); + + Assert.That(info.Spr, Is.EqualTo(spr)); + } + + [Test] + public void VersionInfo() + { + var node = StartCodex(); + + var info = node.GetDebugInfo(); + Assert.That(!string.IsNullOrEmpty(info.Version.Version)); + Assert.That(!string.IsNullOrEmpty(info.Version.Revision)); + } + + [Test] + public void AnnounceAddress() + { + var node = StartCodex(); + var addr = node.Container.GetInternalAddress(CodexContainerRecipe.ListenPortTag); + + var info = node.GetDebugInfo(); + + Assert.That(info.AnnounceAddresses.Count, Is.GreaterThan(0)); + // Ideally we'd assert the pod IP is in the announce address, but we can't access it from here. + } } }