Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/spanner-lib-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,60 @@ jobs:
run: mvn -Djna.debug_load=true test
working-directory: spannerlib/wrappers/spannerlib-java
shell: bash

dotnet-wrapper:
strategy:
matrix:
go-version: [1.25.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v4
- name: Build shared library
working-directory: spannerlib/shared
run: go build -o spannerlib.so -buildmode=c-shared shared_lib.go
- name: Copy to .NET wrapper
working-directory: spannerlib
run: |
mkdir -p wrappers/spannerlib-dotnet/spannerlib-dotnet-native/libraries/any
if [ "$RUNNER_OS" == "Windows" ]; then
cp shared/spannerlib.so wrappers/spannerlib-dotnet/spannerlib-dotnet-native/libraries/any/spannerlib.dll
else
cp shared/spannerlib.so wrappers/spannerlib-dotnet/spannerlib-dotnet-native/libraries/any/spannerlib
fi
shell: bash
- name: Build .NET native library package
run: dotnet pack
working-directory: spannerlib/wrappers/spannerlib-dotnet/spannerlib-dotnet-native
shell: bash
- name: Add .NET package source
run: |
if [ "$RUNNER_OS" == "Windows" ]; then
echo ${GITHUB_WORKSPACE}"\spannerlib\wrappers\spannerlib-dotnet\spannerlib-dotnet-native\bin\Release"
dotnet nuget add source ${GITHUB_WORKSPACE}"\spannerlib\wrappers\spannerlib-dotnet\spannerlib-dotnet-native\bin\Release" --name local
else
dotnet nuget add source "$PWD"/bin/Release --name local
fi
working-directory: spannerlib/wrappers/spannerlib-dotnet/spannerlib-dotnet-native
shell: bash
- name: Restore dependencies
run: dotnet restore
working-directory: spannerlib/wrappers/spannerlib-dotnet
shell: bash
- name: Build
run: dotnet build --no-restore
working-directory: spannerlib/wrappers/spannerlib-dotnet
shell: bash
- name: .NET Unit Tests
working-directory: spannerlib/wrappers/spannerlib-dotnet/spannerlib-dotnet-tests
run: dotnet test --no-build --verbosity normal
shell: bash
4 changes: 4 additions & 0 deletions spannerlib/wrappers/spannerlib-dotnet/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea
obj
bin
*DotSettings.user
7 changes: 7 additions & 0 deletions spannerlib/wrappers/spannerlib-dotnet/global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sdk": {
"version": "9.0.0",
"rollForward": "latestMinor",
"allowPrerelease": false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace Google.Cloud.SpannerLib.MockServer;

/// <summary>
/// Helper class for starting an in-memory mock Spanner server that is used for testing.
/// </summary>
public class MockServerStartup(MockSpannerService mockSpannerService, MockDatabaseAdminService mockDatabaseAdminService)
{
/// <summary>
/// The in-mem Spanner service.
/// </summary>
private MockSpannerService MockSpannerService { get; } = mockSpannerService;

/// <summary>
/// The in-mem Spanner database admin service for executing DDL operations.
/// </summary>
private MockDatabaseAdminService MockDatabaseAdminService { get; } = mockDatabaseAdminService;

/// <summary>
/// Configures the services that will be available on this gRPC server.
/// This method is called by reflection when the tests are started.
/// </summary>
/// <param name="services">The services collection where the services should be added</param>
public void ConfigureServices(IServiceCollection services)
{
services.AddGrpc();
services.AddSingleton(MockSpannerService);
services.AddSingleton(MockDatabaseAdminService);
}

/// <summary>
/// Configures the gRPC server. This method is called by reflection when the tests are started.
/// </summary>
/// <param name="app">The builder for the application that will be hosting the service</param>
/// <param name="env">The webhost environment that is hosting the service</param>
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapGrpcService<MockSpannerService>();
endpoints.MapGrpcService<MockDatabaseAdminService>();
});
}
}
Loading
Loading