Skip to content

Commit

Permalink
dep: remove go-cmp in codegen (#506)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucix-aws authored Mar 7, 2024
1 parent 5893827 commit 4f85511
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
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

0 comments on commit 4f85511

Please sign in to comment.