Skip to content

Commit 3a580b3

Browse files
committed
Starting tests for Ollama integration
1 parent 61c7d64 commit 3a580b3

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

CommunityToolkit.Aspire.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Hos
4747
EndProject
4848
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Hosting.Ollama", "src\CommunityToolkit.Aspire.Hosting.Ollama\CommunityToolkit.Aspire.Hosting.Ollama.csproj", "{6C6696CB-8DCC-4E93-A667-A313D70E0220}"
4949
EndProject
50+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Hosting.Ollama.Tests", "tests\CommunityToolkit.Aspire.Hosting.Ollama.Tests\CommunityToolkit.Aspire.Hosting.Ollama.Tests.csproj", "{1DB27FA0-E7E4-42C1-B062-4DE0128D4FA1}"
51+
EndProject
5052
Global
5153
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5254
Debug|Any CPU = Debug|Any CPU
@@ -117,6 +119,10 @@ Global
117119
{6C6696CB-8DCC-4E93-A667-A313D70E0220}.Debug|Any CPU.Build.0 = Debug|Any CPU
118120
{6C6696CB-8DCC-4E93-A667-A313D70E0220}.Release|Any CPU.ActiveCfg = Release|Any CPU
119121
{6C6696CB-8DCC-4E93-A667-A313D70E0220}.Release|Any CPU.Build.0 = Release|Any CPU
122+
{1DB27FA0-E7E4-42C1-B062-4DE0128D4FA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
123+
{1DB27FA0-E7E4-42C1-B062-4DE0128D4FA1}.Debug|Any CPU.Build.0 = Debug|Any CPU
124+
{1DB27FA0-E7E4-42C1-B062-4DE0128D4FA1}.Release|Any CPU.ActiveCfg = Release|Any CPU
125+
{1DB27FA0-E7E4-42C1-B062-4DE0128D4FA1}.Release|Any CPU.Build.0 = Release|Any CPU
120126
EndGlobalSection
121127
GlobalSection(SolutionProperties) = preSolution
122128
HideSolutionNode = FALSE
@@ -141,6 +147,7 @@ Global
141147
{D3F5EF2B-CE37-4339-A8BD-50E6C5B2AFA1} = {261AC321-8982-4C3A-8DBF-DAFC95F97697}
142148
{E8F93376-1367-4A7B-A729-116199804356} = {899F0713-7FC6-4750-BAFC-AC650B35B453}
143149
{6C6696CB-8DCC-4E93-A667-A313D70E0220} = {414151D4-7009-4E78-A5C6-D99EBD1E67D1}
150+
{1DB27FA0-E7E4-42C1-B062-4DE0128D4FA1} = {899F0713-7FC6-4750-BAFC-AC650B35B453}
144151
EndGlobalSection
145152
GlobalSection(ExtensibilityGlobals) = postSolution
146153
SolutionGuid = {08B1D4B8-D2C5-4A64-BB8B-E1A2B29525F0}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<ItemGroup>
4+
<ProjectReference Include="..\..\src\CommunityToolkit.Aspire.Hosting.Ollama\CommunityToolkit.Aspire.Hosting.Ollama.csproj" />
5+
<ProjectReference Include="..\CommunityToolkit.Aspire.Testing\CommunityToolkit.Aspire.Testing.csproj" />
6+
</ItemGroup>
7+
8+
<PropertyGroup>
9+
<IsPackable>false</IsPackable>
10+
<IsTestProject>true</IsTestProject>
11+
</PropertyGroup>
12+
13+
</Project>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
using Aspire.Hosting;
2+
3+
namespace CommunityToolkit.Aspire.Hosting.Ollama.Tests;
4+
5+
public class ResourceCreationTests
6+
{
7+
[Fact]
8+
public void VerifyDefaultModel()
9+
{
10+
var builder = DistributedApplication.CreateBuilder();
11+
builder.AddOllama("ollama");
12+
13+
using var app = builder.Build();
14+
15+
var appModel = app.Services.GetRequiredService<DistributedApplicationModel>();
16+
17+
var resource = appModel.Resources.OfType<OllamaResource>().SingleOrDefault();
18+
19+
Assert.NotNull(resource);
20+
21+
Assert.Equal("ollama", resource.Name);
22+
23+
Assert.Equal("llama3", resource.ModelName);
24+
}
25+
26+
[Fact]
27+
public void VerifyCustomModel()
28+
{
29+
var builder = DistributedApplication.CreateBuilder();
30+
builder.AddOllama("ollama", modelName: "custom");
31+
32+
using var app = builder.Build();
33+
34+
var appModel = app.Services.GetRequiredService<DistributedApplicationModel>();
35+
36+
var resource = appModel.Resources.OfType<OllamaResource>().SingleOrDefault();
37+
38+
Assert.NotNull(resource);
39+
40+
Assert.Equal("ollama", resource.Name);
41+
42+
Assert.Equal("custom", resource.ModelName);
43+
}
44+
45+
[Fact]
46+
public void VerifyDefaultPort()
47+
{
48+
var builder = DistributedApplication.CreateBuilder();
49+
builder.AddOllama("ollama");
50+
51+
using var app = builder.Build();
52+
53+
var appModel = app.Services.GetRequiredService<DistributedApplicationModel>();
54+
55+
var resource = appModel.Resources.OfType<OllamaResource>().SingleOrDefault();
56+
57+
Assert.NotNull(resource);
58+
59+
var httpEndpoint = resource.GetEndpoint("ollama");
60+
61+
Assert.Equal(11434, httpEndpoint.TargetPort);
62+
}
63+
64+
[Fact]
65+
public void VerifyCustomPort()
66+
{
67+
var builder = DistributedApplication.CreateBuilder();
68+
builder.AddOllama("ollama", port: 12345);
69+
70+
using var app = builder.Build();
71+
72+
var appModel = app.Services.GetRequiredService<DistributedApplicationModel>();
73+
74+
var resource = appModel.Resources.OfType<OllamaResource>().SingleOrDefault();
75+
76+
Assert.NotNull(resource);
77+
78+
var httpEndpoint = resource.GetEndpoint("ollama");
79+
80+
Assert.Equal(12345, httpEndpoint.Port);
81+
}
82+
}

0 commit comments

Comments
 (0)