Skip to content

Commit dc93d1e

Browse files
committed
fix: Temporary workaround for conformance client output
When running via a buildpack, the conformance client expects the output file to be in /workspace, but the working directory is /workspace/bin. Ideally, the conformance client should have a way of telling the function where to write the file, but for the moment this workaround should at least allow it to validate in both contexts.
1 parent 56b6558 commit dc93d1e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/Google.Cloud.Functions.ConformanceTests/HttpFunction.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using Google.Cloud.Functions.Framework;
1616
using Microsoft.AspNetCore.Http;
17+
using System;
1718
using System.IO;
1819
using System.Threading.Tasks;
1920

@@ -22,7 +23,12 @@ public class HttpFunction : IHttpFunction
2223
{
2324
public async Task HandleAsync(HttpContext context)
2425
{
25-
using var output = File.OpenWrite("function_output.json");
26+
// Temporary hack: when running in buildpack validation mode, we need to change
27+
// where we write the output.
28+
var outputFile = Environment.CurrentDirectory == "/workspace/bin"
29+
? "/workspace/function_output.json" : "function_output.json";
30+
31+
using var output = File.OpenWrite(outputFile);
2632
await context.Request.Body.CopyToAsync(output);
2733
}
2834
}

src/Google.Cloud.Functions.ConformanceTests/UntypedCloudEventFunction.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using CloudNative.CloudEvents;
1616
using CloudNative.CloudEvents.SystemTextJson;
1717
using Google.Cloud.Functions.Framework;
18+
using System;
1819
using System.IO;
1920
using System.Threading;
2021
using System.Threading.Tasks;
@@ -24,9 +25,14 @@ public class UntypedCloudEventFunction : ICloudEventFunction
2425
{
2526
public async Task HandleAsync(CloudEvent cloudEvent, CancellationToken cancellationToken)
2627
{
28+
// Temporary hack: when running in buildpack validation mode, we need to change
29+
// where we write the output.
30+
var outputFile = Environment.CurrentDirectory == "/workspace/bin"
31+
? "/workspace/function_output.json" : "function_output.json";
32+
2733
// Write out a structured JSON representation of the CloudEvent
2834
var formatter = new JsonEventFormatter();
2935
var bytes = formatter.EncodeStructuredModeMessage(cloudEvent, out var contentType);
30-
await File.WriteAllBytesAsync("function_output.json", bytes.ToArray());
36+
await File.WriteAllBytesAsync(outputFile, bytes.ToArray());
3137
}
3238
}

0 commit comments

Comments
 (0)