pulumi/sdk/dotnet/Pulumi.Tests/Serialization/ConverterTests.cs
Fraser Waters d39a14432f
Don't throw on type mismatches in the dotnet sdk (#8286)
* Don't throw on type mismatches in the dotnet sdk

Fixes #7329

The converter will no longer throw if resource providers return data
that does not match the expected type declared in the dotnet sdk.
Instead a warning will be logged for the resource and the value will be
set to `default(T)`.
2021-10-29 17:35:17 +01:00

46 lines
1.5 KiB
C#

// Copyright 2016-2019, Pulumi Corporation
using System;
using System.Threading.Tasks;
using Google.Protobuf.WellKnownTypes;
using Pulumi.Serialization;
namespace Pulumi.Tests.Serialization
{
public abstract class ConverterTests : PulumiTest
{
protected static readonly Value UnknownValue = new Value { StringValue = Constants.UnknownValue };
protected static Value CreateSecretValue(Value value)
=> new Value
{
StructValue = new Struct
{
Fields =
{
{ Constants.SpecialSigKey, new Value { StringValue = Constants.SpecialSecretSig } },
{ Constants.SecretValueName, value },
}
}
};
protected async Task<Value> SerializeToValueAsync(object? value, bool keepResources = true)
{
var serializer = new Serializer(excessiveDebugOutput: false);
return Serializer.CreateValue(
await serializer.SerializeAsync(ctx: "", value, keepResources).ConfigureAwait(false));
}
protected static T DeserializeValue<T>(Value value)
{
var v = Deserializer.Deserialize(value).Value;
return v == null ? default! : (T)v;
}
protected static void NoWarn(string error)
{
throw new Exception("Test did not expect warn to be called");
}
}
}