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 smoke test traits #2005

Merged
merged 2 commits into from
Oct 12, 2023
Merged

Conversation

milesziemer
Copy link
Contributor

This commit adds a new package containing the smithy model for smoke tests and their implementation. The model uses the smithy.test namespace, which it shares with other test trait models like protocol tests.

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

This commit adds a new package containing the smithy model for
smoke tests and their implementation. The model uses the
`smithy.test` namespace, which it shares with other test trait
models like protocol tests.
@milesziemer milesziemer requested a review from a team as a code owner October 9, 2023 17:29

/// A single smoke test case definition.
@private
structure SmokeTestCase {
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like we should share some test case definitions, maybe as mixins. A lot of this is exactly the same as protocol testsvand endpoint tests. It might make writing generators easier too if we have shared interfaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, there's a lot of crossover, but I wanted to just focus on smoke tests in this PR. If you think we should try to get it all in one though I can update it.

}

/// A single smoke test case definition.
@private
Copy link
Contributor

Choose a reason for hiding this comment

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

What is and isn't private isn't consistent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made Tag private. Is that all you meant?

Comment on lines 43 to 57
public static Expectation failure(FailureExpectation failure) {
return new Expectation(failure);
}

public boolean isSuccess() {
return failure == null;
}

public boolean isFailure() {
return failure != null;
}

public Optional<FailureExpectation> getFailure() {
return Optional.ofNullable(failure);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

public methods need docs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added docs

Comment on lines 59 to 61
if (!vendorParamsOptional.isPresent()) {
events.add(warning(shape, trait,
"Smoke test case defined a `vendorParamsShape` but no `vendorParams`"));
Copy link
Contributor

Choose a reason for hiding this comment

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

We should put a warning for the case where they have vendor params but no shape too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

events.add(warning(shape, trait,
"Smoke test case defined a `vendorParamsShape` but no `vendorParams`"));
} else {
Shape vendorParamsShape = model.expectShape(vendorParamsShapeOptional.get());
Copy link
Contributor

Choose a reason for hiding this comment

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

You shouldn't use expectShape here since if the shape is missing then we lose out on validating all the other test cases. The idRef will already put an ERROR event in if the shape isn't present, so you don't need to duplicate that here, but you should tolerate the shape not being available.

(The http request test validator also has this unfortunate bit)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Although I think we need to update the protocol test validator then:

Shape vendorParamsShape = model.expectShape(vendorParamsShapeOptional.get());

Comment on lines 36 to 43
Map<String, List<Shape>> testCaseIdsToOperations = new HashMap<>();
Set<Shape> shapes = model.getShapesWithTrait(SmokeTestsTrait.class);
for (Shape shape : shapes) {
SmokeTestsTrait trait = shape.expectTrait(SmokeTestsTrait.class);
for (SmokeTestCase testCase : trait.getTestCases()) {
testCaseIdsToOperations.computeIfAbsent(testCase.getId(), id -> new ArrayList<>()).add(shape);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You should be checking that no two cases within the scope of a service share ids (or within the trait if there's no service), but this will check every trait loaded.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed and updated test cases.

union Expectation {
/// Indicates that the call is expeted to not throw an error. No other
/// assertions are made about the response.
success: Unit
Copy link
Member

Choose a reason for hiding this comment

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

I guess if we ever wanted to do assertions on the output, we could add a new Expectation variant

@@ -0,0 +1,67 @@
/*
* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Copy link
Member

Choose a reason for hiding this comment

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

I think we remove the date now, and maybe use the short form of license headers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the date, I'm not sure what the short form of license headers is though. Do you have an example?

@milesziemer milesziemer merged commit 557d285 into smithy-lang:main Oct 12, 2023
10 checks passed
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