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

Add unit tests to common package for allowedValues change #641

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

damntrecky
Copy link
Contributor

@damntrecky damntrecky commented Dec 6, 2023

Problem

We rushed out a fix yesterday (#638) because there were allowedValues with spaces in the values and this wasn't supported by the build here. We didn't add unit tests for the fix to convert spaces to _ underscores

Solution

Unfortunately it looks like for Kotlin and C# the allowedValues enum, or output metdata key WAS converted, but the value itself was NOT converted to have _ underscores.

This PR fixes that and adds unit tests for all three languages. I also updated the README for each section as it might not be obvious for developers on how to run the tests for each language. Especially if they are not familiar with that language.

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@damntrecky damntrecky requested a review from a team as a code owner December 6, 2023 22:08
@@ -213,7 +213,7 @@ private CodeTypeDeclaration GenerateEnumStruct(MetricType type)
allowedValue.Replace(" ", "_").ToPascalCase().Replace(".", "").Replace("-", ""))
{
InitExpression = new CodeObjectCreateExpression(type.GetGeneratedTypeName(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For C# we converted the "key" but not the "value" to get rid of spaces. This was an oversight and testing of course caught this.

Thanks for pushing for testing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Were any Toolkits released with spaces in the values? This change would create a discrepancy in emitted values across Toolkit versions.

Why not change the definition data to remove the spaces? I don't understand why the values cannot contain spaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There were spaces deployed this week. But we can revert this quickly as our slack discussion aligns with this being better for backend ingestion now and in the future.

Assert.True(datum.Metadata.ContainsKey("codeTransformSessionId"));
Assert.Equal("test-session-id", datum.Metadata["codeTransformSessionId"]);
Assert.True(datum.Metadata.ContainsKey("codeTransformPreValidationError"));
Assert.Equal("No_Java_project_found", datum.Metadata["codeTransformPreValidationError"]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Strictly assert the new change/value here.

@@ -86,7 +86,7 @@ private fun FileSpec.Builder.generateTelemetryEnumType(item: TelemetryMetricType
item.allowedValues!!.forEach { enumValue ->
enum.addEnumConstant(
enumValue.toString().replace(Regex("\\s"), "_").toTypeFormat(), TypeSpec.anonymousClassBuilder()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For Kotlin we converted the "key" but not the "value" to get rid of spaces. This was an oversight and testing of course caught this.

Thanks for pushing for testing.

@damntrecky
Copy link
Contributor Author

/retryBuilds

Nick Ardecky added 2 commits December 6, 2023 14:49
- revert value conversion from _ and just conver key
- update definition for preValidation
- fix unit tests
public enum class TestAllowedValues(
private val `value`: String,
) {
TestSpacesAreReplaced("test spaces are replaced"),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Key is converted, but NOT the value. In general the advice was to avoid spaces for values.

Copy link
Contributor Author

@damntrecky damntrecky Dec 8, 2023

Choose a reason for hiding this comment

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

I would expect this not be a breaking change, since no other allowedValues have spaces other than the values my team introduced this week. This means the enum keys will only change for our team.

"Only Maven projects supported",
"Empty project",
"Non SSO login",
"Project running on backend"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update the values to NOT use spaces.

@damntrecky
Copy link
Contributor Author

/retrybuilds

@damntrecky
Copy link
Contributor Author

/retryBuilds

@damntrecky
Copy link
Contributor Author

Kotlin build failing fixed here -> https://github.com/aws/aws-toolkit-common/pull/646/files

I believe this current change WILL be a breaking changes for anyone who pulls it in and should be separate from the change above. Ideally, once this change is deployed my team can fix the breaking changes (which are for Elastic gumby/ amazon q code transform) intelliJ and vscode instances.

@awschristou
Copy link
Contributor

@damntrecky this PR contains two separate changes:

  • updating enum values in telemetry/definitions/commonDefinitions.json to preferred values (removing spaces from values)
  • fixing and validating generators to handle spaces in values

These need to be split into two separate PRs. If we need to investigate a regression, or revert a change, this PR as-is makes the repo harder to manage. The enum values update is needed sooner than the validation update. Please create a separate PR with just that change. Once that is merged in, this PR can be revisited in order to handle the testing (which is less urgent, as we won't have enum values containing spaces).

@@ -217,6 +217,41 @@ public void RecordMetricWithNewTransform()
Assert.Single(datum.Metadata);
}

/// <summary>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test to make sure allowedValues with spaces converts the key properly and make sure the allowedValue -> value has spaces for now.

Although its recommended to NOT have spaces in the values, the build should not fail and have consistent behavior across environments

@@ -217,6 +217,41 @@ public void RecordMetricWithNewTransform()
Assert.Single(datum.Metadata);
}

/// <summary>
/// RecordCodeTransformIsDoubleClickedToTriggerInvalidProject was chosen as a sample call that has a
/// CodeTransformPreValidationError for allowedValues which have spaces in the values that
Copy link
Contributor

Choose a reason for hiding this comment

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

CodeTransformPreValidationError values no longer have spaces, does the comment need to be updated?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants