From 6ebc68af417d4ce37af0075403eacfd4ad9d9555 Mon Sep 17 00:00:00 2001 From: Gabriel Erzse Date: Wed, 14 Feb 2024 17:56:34 +0200 Subject: [PATCH] Test binary package in CI Issue #195 In the integration workflows, publish the binary package into a local Nuget source and use it as a binary, to make sure it works that way. --- .github/workflows/reusable.yml | 14 ++++ PackageVerification/PackageVerification.cs | 84 +++++++++++++++++++ .../PackageVerification.csproj | 12 +++ 3 files changed, 110 insertions(+) create mode 100644 PackageVerification/PackageVerification.cs create mode 100644 PackageVerification/PackageVerification.csproj diff --git a/.github/workflows/reusable.yml b/.github/workflows/reusable.yml index 9eb29af8..48712181 100644 --- a/.github/workflows/reusable.yml +++ b/.github/workflows/reusable.yml @@ -78,3 +78,17 @@ jobs: verbose: true - name: Build run: dotnet pack -c Release + + - name: Test against Nuget package from local source + if: inputs.redis_stack_type == 'edge' + working-directory: PackageVerification + run: | + mkdir -p test-source + dotnet nuget add source $(readlink -f test-source) -n test-source + find .. -name '*.nupkg' | xargs -I {} dotnet nuget push {} -s test-source + ls -R + dotnet nuget remove source nuget.org + dotnet nuget list source + find . -name '*.csproj' | xargs -I {} sed -E -i 's|.*|${{inputs.clr_version}}|' {} + dotnet restore -s test-source + dotnet run diff --git a/PackageVerification/PackageVerification.cs b/PackageVerification/PackageVerification.cs new file mode 100644 index 00000000..84d41a45 --- /dev/null +++ b/PackageVerification/PackageVerification.cs @@ -0,0 +1,84 @@ +using NRedisStack.Core.DataTypes; +using NRedisStack.RedisStackCommands; +using NRedisStack.Search.Literals.Enums; +using NRedisStack.Search; +using NRedisStack; +using StackExchange.Redis; +using System.Collections.Generic; +using System.Threading; +using System; +using static NRedisStack.Search.Schema; + +/// +/// The goal of this code is to verify that the binary package is working correctly. +/// It should be orchestrated in such a way that the binary package is retrieved from +/// a local NuGet source and then the code is executed. +/// +public class PackageVerification +{ + public static void Main() + { + ConfigurationOptions configurationOptions = new ConfigurationOptions(); + configurationOptions.SyncTimeout = 20000; + configurationOptions.EndPoints.Add("localhost:6379"); + ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(configurationOptions); + + IDatabase db = redis.GetDatabase(); + db.Execute("FLUSHALL"); + + IJsonCommands json = db.JSON(); + + json.Set("product:15970", "$", new + { + id = 15970, + description = "Turtle Navy Blue Shirt", + price = 34.95, + }); + + json.Set("product:59263", "$", new + { + id = 59263, + description = "Titan Silver Watch", + price = 129.99, + }); + + ISearchCommands ft = db.FT(); + + try + { + ft.DropIndex("idx1"); + } + catch + { + } + + ft.Create("idx1", new FTCreateParams().On(IndexDataType.JSON) + .Prefix("product:"), + new Schema().AddNumericField(new FieldName("$.id", "id")) + .AddTextField(new FieldName("$.description", "description")) + .AddNumericField(new FieldName("$.price", "price"))); + + // wait for index to be created + Thread.Sleep(2000); + + List results = ft.Search("idx1", new Query("@description:Blue")).ToJson(); + + Assert(1 == results.Count); + + var expected = "{\"id\":15970,\"description\":\"Turtle Navy Blue Shirt\",\"price\":34.95}"; + Assert(expected == results[0]); + + Console.WriteLine("All good."); + } + + /// + /// Poor Man's assert, since we don't want to depend on NUnit. + /// + private static void Assert(bool condition) + { + if (!condition) + { + throw new System.Exception(); + } + } +} diff --git a/PackageVerification/PackageVerification.csproj b/PackageVerification/PackageVerification.csproj new file mode 100644 index 00000000..1291168b --- /dev/null +++ b/PackageVerification/PackageVerification.csproj @@ -0,0 +1,12 @@ + + + + Exe + netstandard2.0;net6.0;net7.0;net8.0 + + + + + + +