Add unit tests to common package for allowedValues change#641
Add unit tests to common package for allowedValues change#641damntrecky wants to merge 16 commits intoaws:mainfrom
Conversation
| @@ -213,7 +213,7 @@ private CodeTypeDeclaration GenerateEnumStruct(MetricType type) | |||
| allowedValue.Replace(" ", "_").ToPascalCase().Replace(".", "").Replace("-", "")) | |||
| { | |||
| InitExpression = new CodeObjectCreateExpression(type.GetGeneratedTypeName(), | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
telemetry/csharp/AwsToolkit.Telemetry.Events.Tests/GeneratedCodeTests.cs
Show resolved
Hide resolved
| 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"]); |
There was a problem hiding this comment.
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() | |||
There was a problem hiding this comment.
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.
|
/retryBuilds |
- revert value conversion from _ and just conver key - update definition for preValidation - fix unit tests
…olkit-common into nardeck/add-unit-tests
| public enum class TestAllowedValues( | ||
| private val `value`: String, | ||
| ) { | ||
| TestSpacesAreReplaced("test spaces are replaced"), |
There was a problem hiding this comment.
Key is converted, but NOT the value. In general the advice was to avoid spaces for values.
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Update the values to NOT use spaces.
|
/retrybuilds |
|
/retryBuilds |
|
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. |
|
@damntrecky this PR contains two separate changes:
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). |
| Assert.Single(datum.Metadata); | ||
| } | ||
|
|
||
| /// <summary> |
There was a problem hiding this comment.
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
|
|
||
| /// <summary> | ||
| /// RecordCodeTransformIsDoubleClickedToTriggerInvalidProject was chosen as a sample call that has a | ||
| /// CodeTransformPreValidationError for allowedValues which have spaces in the values that |
There was a problem hiding this comment.
CodeTransformPreValidationError values no longer have spaces, does the comment need to be updated?
Problem
We rushed out a fix yesterday (#638) because there were
allowedValueswithspaces in the valuesand this wasn't supported by the build here. We didn't add unit tests for the fix to convert spaces to_underscoresSolution
Unfortunately it looks like for Kotlin and C# the
allowedValuesenum, 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.