Skip to content

Commit 4e21377

Browse files
gerzseshacharPash
andauthored
Test binary package in CI (#252)
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. Co-authored-by: Gabriel Erzse <[email protected]> Co-authored-by: shacharPash <[email protected]>
1 parent 29b4c61 commit 4e21377

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

.github/workflows/reusable.yml

+14
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,17 @@ jobs:
7878
verbose: true
7979
- name: Build
8080
run: dotnet pack -c Release
81+
82+
- name: Test against Nuget package from local source
83+
if: inputs.redis_stack_type == 'edge'
84+
working-directory: PackageVerification
85+
run: |
86+
mkdir -p test-source
87+
dotnet nuget add source $(readlink -f test-source) -n test-source
88+
find .. -name '*.nupkg' | xargs -I {} dotnet nuget push {} -s test-source
89+
ls -R
90+
dotnet nuget remove source nuget.org
91+
dotnet nuget list source
92+
find . -name '*.csproj' | xargs -I {} sed -E -i 's|<TargetFrameworks(.*)>.*</TargetFrameworks>|<TargetFramework\1>${{inputs.clr_version}}</TargetFramework>|' {}
93+
dotnet restore -s test-source
94+
dotnet run
+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using NRedisStack.Core.DataTypes;
2+
using NRedisStack.RedisStackCommands;
3+
using NRedisStack.Search.Literals.Enums;
4+
using NRedisStack.Search;
5+
using NRedisStack;
6+
using StackExchange.Redis;
7+
using System.Collections.Generic;
8+
using System.Threading;
9+
using System;
10+
using static NRedisStack.Search.Schema;
11+
12+
/// <summary>
13+
/// The goal of this code is to verify that the binary package is working correctly.
14+
/// It should be orchestrated in such a way that the binary package is retrieved from
15+
/// a local NuGet source and then the code is executed.
16+
/// </summary>
17+
public class PackageVerification
18+
{
19+
public static void Main()
20+
{
21+
ConfigurationOptions configurationOptions = new ConfigurationOptions();
22+
configurationOptions.SyncTimeout = 20000;
23+
configurationOptions.EndPoints.Add("localhost:6379");
24+
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(configurationOptions);
25+
26+
IDatabase db = redis.GetDatabase();
27+
db.Execute("FLUSHALL");
28+
29+
IJsonCommands json = db.JSON();
30+
31+
json.Set("product:15970", "$", new
32+
{
33+
id = 15970,
34+
description = "Turtle Navy Blue Shirt",
35+
price = 34.95,
36+
});
37+
38+
json.Set("product:59263", "$", new
39+
{
40+
id = 59263,
41+
description = "Titan Silver Watch",
42+
price = 129.99,
43+
});
44+
45+
ISearchCommands ft = db.FT();
46+
47+
try
48+
{
49+
ft.DropIndex("idx1");
50+
}
51+
catch
52+
{
53+
}
54+
55+
ft.Create("idx1", new FTCreateParams().On(IndexDataType.JSON)
56+
.Prefix("product:"),
57+
new Schema().AddNumericField(new FieldName("$.id", "id"))
58+
.AddTextField(new FieldName("$.description", "description"))
59+
.AddNumericField(new FieldName("$.price", "price")));
60+
61+
// wait for index to be created
62+
Thread.Sleep(2000);
63+
64+
List<string> results = ft.Search("idx1", new Query("@description:Blue")).ToJson();
65+
66+
Assert(1 == results.Count);
67+
68+
var expected = "{\"id\":15970,\"description\":\"Turtle Navy Blue Shirt\",\"price\":34.95}";
69+
Assert(expected == results[0]);
70+
71+
Console.WriteLine("All good.");
72+
}
73+
74+
/// <summary>
75+
/// Poor Man's assert, since we don't want to depend on NUnit.
76+
/// </summary>
77+
private static void Assert(bool condition)
78+
{
79+
if (!condition)
80+
{
81+
throw new System.Exception();
82+
}
83+
}
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFrameworks>netstandard2.0;net6.0;net7.0;net8.0</TargetFrameworks>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="NRedisStack" Version="*" />
10+
</ItemGroup>
11+
12+
</Project>

0 commit comments

Comments
 (0)