Skip to content

Commit 72ce0b3

Browse files
committed
chore: add .NET wrapper for SpannerLib
Adds a .NET wrapper and tests for SpannerLib.
1 parent 582f108 commit 72ce0b3

40 files changed

+3592
-0
lines changed

.github/workflows/spanner-lib-tests.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,56 @@ jobs:
7171
run: mvn -Djna.debug_load=true test
7272
working-directory: spannerlib/wrappers/spannerlib-java
7373
shell: bash
74+
75+
dotnet-wrapper:
76+
strategy:
77+
matrix:
78+
go-version: [1.25.x]
79+
os: [ubuntu-latest, macos-latest, windows-latest]
80+
runs-on: ${{ matrix.os }}
81+
steps:
82+
- name: Install dotnet
83+
uses: actions/setup-dotnet@v4
84+
with:
85+
dotnet-version: '9.0.x'
86+
- name: Install Go
87+
uses: actions/setup-go@v5
88+
with:
89+
go-version: ${{ matrix.go-version }}
90+
- name: Checkout code
91+
uses: actions/checkout@v4
92+
- name: Build shared library
93+
working-directory: spannerlib/shared
94+
run: go build -o spannerlib.so -buildmode=c-shared shared_lib.go
95+
- name: Copy to .NET wrapper
96+
working-directory: spannerlib
97+
run: |
98+
mkdir -p wrappers/spannerlib-dotnet/spannerlib-dotnet-native/libraries/any
99+
cp shared/spannerlib.so wrappers/spannerlib-dotnet/spannerlib-dotnet-native/libraries/any/spannerlib
100+
shell: bash
101+
- name: Build .NET native library package
102+
run: dotnet pack
103+
working-directory: spannerlib/wrappers/spannerlib-dotnet/spannerlib-dotnet-native
104+
shell: bash
105+
- name: Add .NET package source
106+
run: |
107+
if [ "$RUNNER_OS" == "Windows" ]; then
108+
echo ${GITHUB_WORKSPACE}"\spannerlib\wrappers\spannerlib-dotnet\spannerlib-dotnet-native\bin\Release"
109+
dotnet nuget add source ${GITHUB_WORKSPACE}"\spannerlib\wrappers\spannerlib-dotnet\spannerlib-dotnet-native\bin\Release" --name local
110+
else
111+
dotnet nuget add source "$PWD"/bin/Release --name local
112+
fi
113+
working-directory: spannerlib/wrappers/spannerlib-dotnet/spannerlib-dotnet-native
114+
shell: bash
115+
- name: Restore dependencies
116+
run: dotnet restore
117+
working-directory: spannerlib/wrappers/spannerlib-dotnet
118+
shell: bash
119+
- name: Build
120+
run: dotnet build --no-restore
121+
working-directory: spannerlib/wrappers/spannerlib-dotnet
122+
shell: bash
123+
- name: .NET Unit Tests
124+
working-directory: spannerlib/wrappers/spannerlib-dotnet/spannerlib-dotnet-tests
125+
run: dotnet test --no-build --verbosity normal
126+
shell: bash
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.idea
2+
obj
3+
bin
4+
*DotSettings.user
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"sdk": {
3+
"version": "9.0.0",
4+
"rollForward": "latestMinor",
5+
"allowPrerelease": false
6+
}
7+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using Microsoft.AspNetCore.Builder;
16+
using Microsoft.AspNetCore.Hosting;
17+
using Microsoft.Extensions.DependencyInjection;
18+
using Microsoft.Extensions.Hosting;
19+
20+
namespace Google.Cloud.SpannerLib.MockServer;
21+
22+
/// <summary>
23+
/// Helper class for starting an in-memory mock Spanner server that is used for testing.
24+
/// </summary>
25+
public class MockServerStartup(MockSpannerService mockSpannerService, MockDatabaseAdminService mockDatabaseAdminService)
26+
{
27+
/// <summary>
28+
/// The in-mem Spanner service.
29+
/// </summary>
30+
private MockSpannerService MockSpannerService { get; } = mockSpannerService;
31+
32+
/// <summary>
33+
/// The in-mem Spanner database admin service for executing DDL operations.
34+
/// </summary>
35+
private MockDatabaseAdminService MockDatabaseAdminService { get; } = mockDatabaseAdminService;
36+
37+
/// <summary>
38+
/// Configures the services that will be available on this gRPC server.
39+
/// This method is called by reflection when the tests are started.
40+
/// </summary>
41+
/// <param name="services">The services collection where the services should be added</param>
42+
public void ConfigureServices(IServiceCollection services)
43+
{
44+
services.AddGrpc();
45+
services.AddSingleton(MockSpannerService);
46+
services.AddSingleton(MockDatabaseAdminService);
47+
}
48+
49+
/// <summary>
50+
/// Configures the gRPC server. This method is called by reflection when the tests are started.
51+
/// </summary>
52+
/// <param name="app">The builder for the application that will be hosting the service</param>
53+
/// <param name="env">The webhost environment that is hosting the service</param>
54+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
55+
{
56+
if (env.IsDevelopment())
57+
{
58+
app.UseDeveloperExceptionPage();
59+
}
60+
61+
app.UseRouting();
62+
app.UseEndpoints(endpoints =>
63+
{
64+
endpoints.MapGrpcService<MockSpannerService>();
65+
endpoints.MapGrpcService<MockDatabaseAdminService>();
66+
});
67+
}
68+
}

0 commit comments

Comments
 (0)