-
Notifications
You must be signed in to change notification settings - Fork 57
Add unit tests to common package for allowedValues change #641
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
base: main
Are you sure you want to change the base?
Changes from all commits
d36a467
e6197ca
66ae21f
088e482
a16a54d
c24e11a
a43ecff
76c203a
e394cc2
ad973de
4f5bc6f
e27cccc
5f7a447
6c3cf26
7e7edc2
1c83705
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,6 +217,41 @@ public void RecordMetricWithNewTransform() | |
Assert.Single(datum.Metadata); | ||
} | ||
|
||
/// <summary> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test to make sure Although its recommended to NOT have spaces in the values, the build should not fail and have consistent behavior across environments |
||
/// 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
/// should be converted to underscores for the "key". This way the language interprets | ||
/// the key value as pascal case and converts it. | ||
/// </summary> | ||
[Fact] | ||
public void RecordWithAllowedValues() | ||
{ | ||
var doubleClickRecord = new CodeTransformIsDoubleClickedToTriggerInvalidProject() | ||
{ | ||
CodeTransformPreValidationError = CodeTransformPreValidationError.NoJavaProject, | ||
CodeTransformSessionId = "test-session-id", | ||
Result = Result.Succeeded | ||
}; | ||
|
||
_telemetryLogger.Object.RecordCodeTransformIsDoubleClickedToTriggerInvalidProject(doubleClickRecord); | ||
|
||
Assert.NotNull(_recordedMetrics); | ||
_telemetryLogger.Verify( | ||
mock => mock.Record(_recordedMetrics), | ||
Times.Once | ||
); | ||
|
||
var datum = Assert.Single(_recordedMetrics.Data); | ||
Assert.NotNull(datum); | ||
Assert.Equal("codeTransform_isDoubleClickedToTriggerInvalidProject", datum.MetricName); | ||
Assert.Equal(Unit.None, datum.Unit); | ||
Assert.False(datum.Passive); | ||
Assert.True(datum.Metadata.ContainsKey("codeTransformSessionId")); | ||
Assert.Equal("test-session-id", datum.Metadata["codeTransformSessionId"]); | ||
Assert.True(datum.Metadata.ContainsKey("codeTransformPreValidationError")); | ||
Assert.Equal("NoJavaProject", datum.Metadata["codeTransformPreValidationError"]); | ||
} | ||
|
||
private MetricDatum TransformDuplicateReason(MetricDatum datum) | ||
{ | ||
datum.Metadata["reason1"] = datum.Metadata["reason"]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1041,14 +1041,14 @@ | |
"type": "string", | ||
"description": "Names of the pre-validation errors that can occur in the project", | ||
"allowedValues": [ | ||
"No pom.xml file found", | ||
"No Java project found", | ||
"Mixed Java project and another language found", | ||
"Project selected is not Java 8 or Java 11", | ||
"Only Maven projects supported", | ||
"Empty project", | ||
"Non SSO login", | ||
"Project running on backend" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the values to NOT use spaces. |
||
"NoPom", | ||
"NoJavaProject", | ||
"MixedLanguages", | ||
"UnsupportedJavaVersion", | ||
"NonMavenProject", | ||
"EmptyProject", | ||
"NonSsoLogin", | ||
"RemoteRunProject" | ||
] | ||
}, | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
{ | ||
"types": [ | ||
{ | ||
"name": "testAllowedValues", | ||
"allowedValues": [ | ||
"test spaces are replaced", | ||
"in allowed values output key" | ||
], | ||
"description": "A test object for parsing allowedValues" | ||
} | ||
], | ||
"metrics": [ | ||
{ | ||
"name": "test_metric", | ||
"description": "A test for defining allowedValues", | ||
"unit": "None", | ||
"metadata": [{ "type": "testAllowedValues" }] | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// THIS FILE IS GENERATED! DO NOT EDIT BY HAND! | ||
@file:Suppress("unused", "MemberVisibilityCanBePrivate") | ||
|
||
package software.aws.toolkits.telemetry | ||
|
||
import com.intellij.openapi.project.Project | ||
import java.time.Instant | ||
import kotlin.Boolean | ||
import kotlin.Double | ||
import kotlin.String | ||
import kotlin.Suppress | ||
import kotlin.Unit | ||
import software.aws.toolkits.core.ConnectionSettings | ||
import software.aws.toolkits.jetbrains.services.telemetry.MetricEventMetadata | ||
import software.aws.toolkits.jetbrains.services.telemetry.TelemetryService | ||
|
||
/** | ||
* A test object for parsing allowedValues | ||
*/ | ||
public enum class TestAllowedValues( | ||
private val `value`: String, | ||
) { | ||
damntrecky marked this conversation as resolved.
Show resolved
Hide resolved
|
||
TestSpacesAreReplaced("test spaces are replaced"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would expect this not be a breaking change, since no other |
||
InAllowedValuesOutputKey("in allowed values output key"), | ||
Unknown("unknown"), | ||
; | ||
|
||
public override fun toString(): String = value | ||
|
||
public companion object { | ||
public fun from(type: String): TestAllowedValues = values().firstOrNull { it.value == type } | ||
?: Unknown | ||
} | ||
} | ||
|
||
public object TestTelemetry { | ||
/** | ||
* A test for defining allowedValues | ||
*/ | ||
public fun metric( | ||
project: Project?, | ||
testAllowedValues: TestAllowedValues, | ||
passive: Boolean = false, | ||
`value`: Double = 1.0, | ||
createTime: Instant = Instant.now(), | ||
): Unit { | ||
TelemetryService.getInstance().record(project) { | ||
datum("test_metric") { | ||
createTime(createTime) | ||
unit(software.amazon.awssdk.services.toolkittelemetry.model.Unit.NONE) | ||
value(value) | ||
passive(passive) | ||
metadata("testAllowedValues", testAllowedValues.toString()) | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* A test for defining allowedValues | ||
*/ | ||
public fun metric( | ||
connectionSettings: ConnectionSettings? = null, | ||
testAllowedValues: TestAllowedValues, | ||
passive: Boolean = false, | ||
`value`: Double = 1.0, | ||
createTime: Instant = Instant.now(), | ||
): Unit { | ||
TelemetryService.getInstance().record(connectionSettings) { | ||
datum("test_metric") { | ||
createTime(createTime) | ||
unit(software.amazon.awssdk.services.toolkittelemetry.model.Unit.NONE) | ||
value(value) | ||
passive(passive) | ||
metadata("testAllowedValues", testAllowedValues.toString()) | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* A test for defining allowedValues | ||
*/ | ||
public fun metric( | ||
metadata: MetricEventMetadata, | ||
testAllowedValues: TestAllowedValues, | ||
passive: Boolean = false, | ||
`value`: Double = 1.0, | ||
createTime: Instant = Instant.now(), | ||
): Unit { | ||
TelemetryService.getInstance().record(metadata) { | ||
datum("test_metric") { | ||
createTime(createTime) | ||
unit(software.amazon.awssdk.services.toolkittelemetry.model.Unit.NONE) | ||
value(value) | ||
passive(passive) | ||
metadata("testAllowedValues", testAllowedValues.toString()) | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
{ | ||
"types": [ | ||
{ | ||
"name": "result", | ||
"allowedValues": ["Succeeded"], | ||
"description": "The result of the operation" | ||
}, | ||
{ | ||
"name": "reason", | ||
"type": "string", | ||
"description": "The reason for a metric or exception depending on context" | ||
}, | ||
{ | ||
"name": "duration", | ||
"type": "double", | ||
"description": "The duration of the operation in miliseconds" | ||
}, | ||
{ | ||
"name": "testAllowedValues", | ||
"allowedValues": [ | ||
"test spaces are replaced", | ||
"in allowed values output key" | ||
], | ||
"description": "A test object for parsing allowedValues" | ||
} | ||
], | ||
"metrics": [ | ||
{ | ||
"name": "test_metric", | ||
"description": "A test for defining allowedValues", | ||
"unit": "None", | ||
"metadata": [{ "type": "testAllowedValues" }] | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/*! | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
export interface MetricBase { | ||
/** The result of the operation */ | ||
readonly result?: Result | ||
/** The reason for a metric or exception depending on context */ | ||
readonly reason?: string | ||
/** The duration of the operation in miliseconds */ | ||
readonly duration?: number | ||
/** A flag indicating that the metric was not caused by the user. */ | ||
readonly passive?: boolean | ||
/** @deprecated Arbitrary "value" of the metric. */ | ||
readonly value?: number | ||
} | ||
|
||
export interface TestMetric extends MetricBase { | ||
/** A test object for parsing allowedValues */ | ||
readonly testAllowedValues: TestAllowedValues | ||
} | ||
|
||
export type Result = 'Succeeded' | ||
export type LambdaRuntime = 'dotnetcore2.1' | 'nodejs12.x' | ||
export type TestAllowedValues = 'test spaces are replaced' | 'in allowed values output key' | ||
|
||
export interface MetricDefinition { | ||
readonly unit: string | ||
readonly passive: boolean | ||
readonly requiredMetadata: readonly string[] | ||
} | ||
|
||
export interface MetricShapes { | ||
readonly test_metric: TestMetric | ||
} | ||
|
||
export type MetricName = keyof MetricShapes | ||
|
||
export const definitions: Record<string, MetricDefinition> = { | ||
test_metric: { unit: 'None', passive: false, requiredMetadata: ['testAllowedValues'] }, | ||
} | ||
|
||
export type Metadata<T extends MetricBase> = Partial<Omit<T, keyof MetricBase>> | ||
|
||
export interface Metric<T extends MetricBase = MetricBase> { | ||
readonly name: string | ||
/** Adds data to the metric which is preserved for the remainder of the execution context */ | ||
record(data: Metadata<T>): void | ||
/** Sends the metric to the telemetry service */ | ||
emit(data?: T): void | ||
/** Executes a callback, automatically sending the metric after completion */ | ||
run<U>(fn: (span: this) => U): U | ||
} | ||
|
||
export abstract class TelemetryBase { | ||
/** A test for defining allowedValues */ | ||
public get test_metric(): Metric<TestMetric> { | ||
return this.getMetric('test_metric') | ||
} | ||
|
||
protected abstract getMetric(name: string): Metric | ||
} |
Uh oh!
There was an error while loading. Please reload this page.