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

dep: remove go-cmp in codegen #506

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
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
Expand Up @@ -74,14 +74,10 @@ public final class SmithyGoDependency {
public static final GoDependency SMITHY_ENDPOINTS = smithy("endpoints", "smithyendpoints");
public static final GoDependency SMITHY_ENDPOINT_RULESFN = smithy("endpoints/private/rulesfn");

public static final GoDependency GO_CMP = goCmp("cmp");
public static final GoDependency GO_CMP_OPTIONS = goCmp("cmp/cmpopts");

public static final GoDependency GO_JMESPATH = goJmespath(null);
public static final GoDependency MATH = stdlib("math");

private static final String SMITHY_SOURCE_PATH = "github.com/aws/smithy-go";
private static final String GO_CMP_SOURCE_PATH = "github.com/google/go-cmp";
private static final String GO_JMESPATH_SOURCE_PATH = "github.com/jmespath/go-jmespath";

private SmithyGoDependency() {
Expand Down Expand Up @@ -116,10 +112,6 @@ private static GoDependency smithy(String relativePath, String alias) {
return relativePackage(SMITHY_SOURCE_PATH, relativePath, Versions.SMITHY_GO, alias);
}

private static GoDependency goCmp(String relativePath) {
return relativePackage(GO_CMP_SOURCE_PATH, relativePath, Versions.GO_CMP, null);
}

private static GoDependency goJmespath(String relativePath) {
return relativePackage(GO_JMESPATH_SOURCE_PATH, relativePath, Versions.GO_JMESPATH, null);
}
Expand All @@ -139,7 +131,6 @@ private static GoDependency relativePackage(

private static final class Versions {
private static final String GO_STDLIB = "1.15";
private static final String GO_CMP = "v0.5.4";
private static final String SMITHY_GO = "v1.4.0";
private static final String GO_JMESPATH = "v0.4.0";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ GoWriter.Writable generateExpectEndpoint(Optional<ExpectedEndpoint> expectEndpoi
commonCodegenArgs,
MapUtils.of(
"urlParse", SymbolUtils.createValueSymbolBuilder("Parse", SmithyGoDependency.NET_URL).build(),
"cmpDiff", SymbolUtils.createPointableSymbolBuilder("Diff", SmithyGoDependency.GO_CMP).build(),
"expectURL", endpoint.getUrl(),
"headers", generateHeaders(endpoint.getHeaders()),
"properties", generateProperties(endpoint.getProperties()),
Expand Down Expand Up @@ -256,14 +255,10 @@ GoWriter.Writable generateHeaders(Map<String, List<String>> headers) {

GoWriter.Writable generateAssertFields() {
return goTemplate("""
if diff := $cmpDiff:T(expectEndpoint.Headers, result.Headers); diff != "" {
t.Errorf("expect headers to match\\n%s", diff)
if !$T(expectEndpoint.Headers, result.Headers) {
t.Errorf("expect headers to match\\n%v != %v", expectEndpoint.Headers, result.Headers)
}
""",
MapUtils.of(
"cmpDiff", SymbolUtils.createPointableSymbolBuilder("Diff", SmithyGoDependency.GO_CMP).build(),
"cmpAllowUnexported", SymbolUtils.createPointableSymbolBuilder("AllowUnexported",
SmithyGoDependency.GO_CMP).build()));
""", SmithyGoDependency.REFLECT.valueSymbol("DeepEqual"));
}

GoWriter.Writable generateProperties(Map<String, Node> properties) {
Expand Down Expand Up @@ -357,16 +352,12 @@ public GoWriter.Writable stringNode(StringNode stringNode) {

GoWriter.Writable generateAssertProperties() {
return goTemplate("""
if diff := $cmpDiff:T(expectEndpoint.Properties, result.Properties,
$cmpAllowUnexported:T($propertiesType:T{}),
); diff != "" {
t.Errorf("expect properties to match\\n%s", diff)
if !$reflectDeepEqual:T(expectEndpoint.Properties, result.Properties) {
t.Errorf("expect properties to match\\n%v != %v", expectEndpoint.Properties, result.Properties)
}
""",
MapUtils.of(
"cmpDiff", SymbolUtils.createPointableSymbolBuilder("Diff", SmithyGoDependency.GO_CMP).build(),
"cmpAllowUnexported", SymbolUtils.createPointableSymbolBuilder("AllowUnexported",
SmithyGoDependency.GO_CMP).build(),
"reflectDeepEqual", SmithyGoDependency.REFLECT.valueSymbol("DeepEqual"),
"propertiesType", SymbolUtils.createValueSymbolBuilder("Properties",
SmithyGoDependency.SMITHY).build()));

Expand Down
Loading