Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generator implementation for V2 smoke tests for C2J files. #3578

Draft
wants to merge 2 commits into
base: normj/v4-smoketests
Choose a base branch
from
Draft
Changes from all 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
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ namespace ServiceClientGenerator.Generators.TestFiles
{
public partial class SmokeTestsV2
{
#region Core Configuration Properties
public string GetRegion(JsonData testCase)
{
var config = testCase["config"];
@@ -21,17 +22,183 @@ public string GetRegion(JsonData testCase)
return region.ToJson();
}

public string GetUri(JsonData testCase)
{
var config = testCase["config"];
if (config == null)
return null;

var uri = config["uri"];
if (uri == null)
return null;

return $"\"{uri.ToString()}\"";
}

#endregion

#region Endpoint Configuration Properties
public bool? GetUseFipsEndpoint(JsonData testCase)
{
var config = testCase["config"];
if (config == null)
return null;

var useFips = config["useFips"];
if (useFips == null)
return null;

return (bool)useFips;
}

public bool? GetUseDualstackEndpoint(JsonData testCase)
{
var config = testCase["config"];
if (config == null)
return null;

var useDualstack = config["useDualstack"];
if (useDualstack == null)
return null;

return (bool)useDualstack;
}
#endregion

#region S3-Specific Configuration Properties
public bool? GetUseAccelerateEndpoint(JsonData testCase)
{
var config = testCase["config"];
if (config == null)
return null;

var useAccelerate = config["useAccelerate"];
if (useAccelerate == null)
return null;

return (bool)useAccelerate;
}

public bool? GetUseGlobalEndpoint(JsonData testCase)
{
var config = testCase["config"];
if (config == null)
return null;

var useGlobalEndpoint = config["useGlobalEndpoint"];
if (useGlobalEndpoint == null)
return null;

return (bool)useGlobalEndpoint;
}

public bool? GetUseArnRegion(JsonData testCase)
{
var config = testCase["config"];
if (config == null)
return null;

var useArnRegion = config["useArnRegion"];
if (useArnRegion == null)
return null;

return (bool)useArnRegion;
}

public bool? GetForcePathStyle(JsonData testCase)
{
var config = testCase["config"];
if (config == null)
return null;

var forcePathStyle = config["forcePathStyle"];
if (forcePathStyle == null)
return null;

return (bool)forcePathStyle;
}
#endregion

#region Authentication Configuration Properties
public bool? GetUseAccountIdRouting(JsonData testCase)
{
var config = testCase["config"];
if (config == null)
return null;

var useAccountIdRouting = config["useAccountIdRouting"];
if (useAccountIdRouting == null)
return null;

return (bool)useAccountIdRouting;
}

public string[] GetSigV4aRegionSet(JsonData testCase)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could just make the return type List<string>, which would remove the extra regions.ToArray() call at the end and instead just return regions.

{
var config = testCase["config"];
if (config == null)
return null;

var sigv4aRegionSet = config["sigv4aRegionSet"];
if (sigv4aRegionSet == null || !sigv4aRegionSet.IsArray)
return null;

var regions = new List<string>();
foreach (JsonData region in sigv4aRegionSet)
{
regions.Add(region.ToString());
}
return regions.ToArray();
}
#endregion

#region Test Case Properties
public JsonData GetInput(JsonData testCase)
{
return testCase["input"];
}

public bool IsSuccessExpected(JsonData testCase)
{
var expectation = testCase["expectation"];
return expectation["success"] != null;
}

public string GetExpectedErrorId(JsonData testCase)
{
var expectation = testCase["expectation"];
var failure = expectation["failure"];
return failure?["errorId"]?.ToString();
}
#endregion

/// <summary>
/// Finds the operation in the ServiceModel based on the operation name in the smoke2 json file. The
/// name in that file does not take any customizations that might have been put in place. So we need to
/// compare to the raw ShapeName instead of Name property which has customizations applied.
/// </summary>
/// <param name="operationShapeName"></param>
/// <returns></returns>
private Operation FindOperation(JsonData testCase)
{
var operationShapeName = testCase["operationName"].ToString();
return this.Config.ServiceModel.Operations.FirstOrDefault(x => string.Equals(x.ShapeName, operationShapeName));
}

/// <summary>
/// Finds the proper .NET property name for a given JSON key in the operation's input shape.
/// </summary>
private string FindPropertyName(Operation operation, string jsonKey)
{
// Get the input shape for the operation
var inputShape = operation.RequestStructure;
if (inputShape == null)
return jsonKey;

// Look for a member in the input shape that matches the json key
var member = inputShape.Members.FirstOrDefault(m =>
string.Equals(m.MarshallLocationName, jsonKey, StringComparison.OrdinalIgnoreCase));

// If found, return the .NET customized name, otherwise return original key
return member?.PropertyName ?? jsonKey;
}
}
}
Loading
Oops, something went wrong.
Loading
Oops, something went wrong.