Skip to content

Commit a03de51

Browse files
adamthom-amznsrchase
authored andcommitted
Add an integ tests subpackage
This tests package will generate an SSDK and then execute jest tests written against it.
1 parent 183e0d0 commit a03de51

File tree

9 files changed

+355
-0
lines changed

9 files changed

+355
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
import software.amazon.smithy.gradle.tasks.SmithyBuild
17+
18+
buildscript {
19+
repositories {
20+
mavenLocal()
21+
mavenCentral()
22+
}
23+
dependencies {
24+
classpath 'software.amazon.smithy:smithy-typescript-codegen:0.3.0'
25+
classpath 'software.amazon.smithy:smithy-aws-typescript-codegen:0.3.0'
26+
classpath "software.amazon.smithy:smithy-model:1.5.1"
27+
}
28+
}
29+
30+
plugins {
31+
id 'software.amazon.smithy' version '0.5.2'
32+
}
33+
34+
dependencies {
35+
implementation "software.amazon.smithy:smithy-aws-traits:1.5.1"
36+
}
37+
38+
repositories {
39+
mavenLocal()
40+
mavenCentral()
41+
}
42+
43+
jar.enabled = false
44+
smithyBuildJar.enabled = false
45+
46+
task generateServer(type: SmithyBuild) {}
47+
48+
build.dependsOn generateServer
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
namespace software.amazon.smithy.typescript.integ
2+
3+
use aws.protocols#restJson1
4+
5+
@restJson1
6+
service ValidationService {
7+
version: "2020-01-25",
8+
operations: [Test]
9+
}
10+
11+
@readonly
12+
@http(method: "POST", uri:"/test")
13+
operation Test {
14+
input: TestInput
15+
}
16+
17+
structure TestInput {
18+
enum: Enum,
19+
lengthTests: LengthTests,
20+
nestedTests: NestedUnionOne
21+
}
22+
23+
structure LengthTests {
24+
minMaxLengthString: MinMaxLengthString,
25+
26+
minMaxLengthList: MinMaxLengthList,
27+
28+
minMaxLengthMap: MinMaxLengthMap,
29+
30+
minMaxLengthBlob: MinMaxLengthBlob,
31+
32+
@length(min:13, max:27)
33+
minMaxLengthOverride: MinMaxLengthString,
34+
}
35+
36+
union NestedUnionOne {
37+
value1: NestedUnionTwo
38+
}
39+
40+
union NestedUnionTwo {
41+
value2: SetOfStructures
42+
}
43+
44+
set SetOfStructures {
45+
member: NestedStructureOne
46+
}
47+
48+
structure NestedStructureOne {
49+
unions: ListOfUnions
50+
}
51+
52+
list ListOfUnions {
53+
member: NestedUnionThree
54+
}
55+
56+
union NestedUnionThree {
57+
value3: MinMaxLengthString
58+
}
59+
60+
@enum([{"value" : "valueA"}, {"value": "valueB"}])
61+
string Enum
62+
63+
@length(min: 2, max: 7)
64+
string MinMaxLengthString
65+
66+
@length(min: 2, max: 4)
67+
map MinMaxLengthMap {
68+
key: MinMaxLengthString,
69+
70+
@range(min: 1, max: 7)
71+
value: Integer
72+
}
73+
74+
@length(min: 2, max: 4)
75+
list MinMaxLengthList {
76+
member: MinMaxLengthString
77+
}
78+
79+
@length(min: 2, max: 4)
80+
blob MinMaxLengthBlob

smithy-typescript-integ-tests/codegen/settings.gradle

Whitespace-only changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"version" : "1.0",
3+
"outputDirectory" : "build/output",
4+
"projections" : {
5+
"ts-server" : {
6+
"plugins": {
7+
"typescript-ssdk-codegen" : {
8+
"package" : "@aws-smithy/typescript-integ-test-types",
9+
"packageVersion": "1.0.0"
10+
}
11+
}
12+
}
13+
}
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
preset: "ts-jest",
3+
testEnvironment: "node",
4+
transform: {
5+
"^.+\\.(ts|tsx)$": "ts-jest",
6+
},
7+
testMatch: ["**/src/**/?(*.)+(spec|test).ts"],
8+
globals: {
9+
"ts-jest": {
10+
tsconfig: "tsconfig.json",
11+
},
12+
},
13+
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "@aws-smithy/typescript-integ-tests",
3+
"private": true,
4+
"version": "1.0.0",
5+
"description": "TypeScript tests against generated Smithy types",
6+
"main": "./dist/cjs/index.js",
7+
"types": "./dist/types/index.d.ts",
8+
"scripts": {
9+
"prepublishOnly": "yarn build",
10+
"pretest": "yarn generate && yarn build:generated && yarn build",
11+
"generate": "cd codegen && gradle build",
12+
"build:generated": "cd codegen/build/smithyprojections/codegen/ts-server/typescript-ssdk-codegen && yarn install && yarn link @aws-smithy/server-common && yarn build",
13+
"build": "tsc -p tsconfig.json",
14+
"test": "jest"
15+
},
16+
"repository": {
17+
"type": "git",
18+
"url": "git+https://github.com/awslabs/smithy-typescript.git",
19+
"directory": "smithy-typescript-integ-tests"
20+
},
21+
"author": "AWS Smithy Team",
22+
"license": "Apache-2.0",
23+
"dependencies": {
24+
},
25+
"devDependencies": {
26+
"@types/jest": "^26.0.22",
27+
"@types/node": "^14.14.37",
28+
"jest": "^26.6.3",
29+
"ts-jest": "^26.5.2",
30+
"typescript": "^4.2.2",
31+
"@aws-smithy/typescript-integ-test-types": "1.0.0"
32+
},
33+
"engines": {
34+
"node": ">= 14.0.0"
35+
},
36+
"bugs": {
37+
"url": "https://github.com/awslabs/smithy-typescript/issues"
38+
},
39+
"homepage": "https://github.com/awslabs/smithy-typescript#readme",
40+
"workspaces": [
41+
"codegen/build/smithyprojections/codegen/ts-server/typescript-ssdk-codegen"
42+
]
43+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
import {LengthTests} from "@aws-smithy/typescript-integ-test-types";
17+
18+
describe("length constraints", () => {
19+
it("work for strings", () => {
20+
expect(LengthTests.validate({ minMaxLengthString: "much longer than 7" })).toEqual([{
21+
constraintType: "length",
22+
constraintValues: [ 2, 7 ],
23+
failureValue: 18,
24+
memberName: "minMaxLengthString",
25+
}]);
26+
expect(LengthTests.validate({ minMaxLengthString: "a" })).toEqual([{
27+
constraintType: "length",
28+
constraintValues: [ 2, 7 ],
29+
failureValue: 1,
30+
memberName: "minMaxLengthString",
31+
}]);
32+
});
33+
it("work for maps", () => {
34+
expect(LengthTests.validate({ minMaxLengthMap: { "abc": 1 }})).toEqual([{
35+
constraintType: "length",
36+
constraintValues: [ 2, 4 ],
37+
failureValue: 1,
38+
memberName: "minMaxLengthMap",
39+
}]);
40+
expect(LengthTests.validate({ minMaxLengthMap: { "abc": 1, "bcd": 2, "cde": 3, "def": 4, "efg": 5 }})).toEqual([{
41+
constraintType: "length",
42+
constraintValues: [ 2, 4 ],
43+
failureValue: 5,
44+
memberName: "minMaxLengthMap",
45+
}]);
46+
});
47+
it("also work on map keys", () => {
48+
expect(LengthTests.validate({ minMaxLengthMap: { "a": 1, "bcd": 2, "cde": 3 }})).toEqual([{
49+
constraintType: "length",
50+
constraintValues: [ 2, 7 ],
51+
failureValue: 1,
52+
memberName: "minMaxLengthMap",
53+
}]);
54+
expect(LengthTests.validate({ minMaxLengthMap: { "abcdefghijk": 5, "bcd": 2, "cde": 3 }})).toEqual([{
55+
constraintType: "length",
56+
constraintValues: [ 2, 7 ],
57+
failureValue: 11,
58+
memberName: "minMaxLengthMap",
59+
}]);
60+
});
61+
it("work for lists", () => {
62+
expect(LengthTests.validate({ minMaxLengthList: ["abc"]})).toEqual([{
63+
constraintType: "length",
64+
constraintValues: [ 2, 4 ],
65+
failureValue: 1,
66+
memberName: "minMaxLengthList",
67+
}]);
68+
expect(LengthTests.validate({ minMaxLengthList: [ "abc", "bcd", "cde", "def", "efg" ]})).toEqual([{
69+
constraintType: "length",
70+
constraintValues: [ 2, 4 ],
71+
failureValue: 5,
72+
memberName: "minMaxLengthList",
73+
}]);
74+
});
75+
it("also work on list values", () => {
76+
expect(LengthTests.validate({ minMaxLengthList: ["abcdefghijk", "def"]})).toEqual([{
77+
constraintType: "length",
78+
constraintValues: [ 2, 7 ],
79+
failureValue: 11,
80+
memberName: "minMaxLengthList",
81+
}]);
82+
});
83+
it("work for blobs", () => {
84+
expect(LengthTests.validate({ minMaxLengthBlob: Buffer.of(1) })).toEqual([{
85+
constraintType: "length",
86+
constraintValues: [ 2, 4 ],
87+
failureValue: 1,
88+
memberName: "minMaxLengthBlob",
89+
}]);
90+
expect(LengthTests.validate({ minMaxLengthBlob: Buffer.of(1, 2, 3, 4, 5)})).toEqual([{
91+
constraintType: "length",
92+
constraintValues: [ 2, 4 ],
93+
failureValue: 5,
94+
memberName: "minMaxLengthBlob",
95+
}]);
96+
});
97+
it("can be overridden on members", () => {
98+
expect(LengthTests.validate({ minMaxLengthOverride: "abcdef" })).toEqual([{
99+
constraintType: "length",
100+
constraintValues: [ 13, 27 ],
101+
failureValue: 6,
102+
memberName: "minMaxLengthOverride",
103+
}]);
104+
})
105+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
import {NestedUnionOne} from "@aws-smithy/typescript-integ-test-types";
17+
18+
describe("ridiculously nested structures", () => {
19+
it("still work", () => {
20+
expect(NestedUnionOne.validate({ value1: { value2: [ { unions: [ { value3: "abcdefghijk"}] } ] } }))
21+
.toEqual([]);
22+
})
23+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"compilerOptions": {
3+
"stripInternal": true,
4+
"declarationDir": "./dist/types",
5+
"rootDir": "./src",
6+
"outDir": "./dist/cjs",
7+
"baseUrl": ".",
8+
"downlevelIteration": true,
9+
"resolveJsonModule": true,
10+
"experimentalDecorators": true,
11+
"noUnusedParameters": false,
12+
"removeComments": false,
13+
"incremental": true,
14+
"preserveConstEnums": true,
15+
"noFallthroughCasesInSwitch": true,
16+
"esModuleInterop": true,
17+
"module": "commonjs",
18+
"moduleResolution": "node",
19+
"target": "ES2018",
20+
"lib": ["es2015", "dom"],
21+
"strict": true,
22+
"declaration": true,
23+
"importHelpers": true,
24+
"noEmitHelpers": true,
25+
"inlineSourceMap": true,
26+
"inlineSources": true
27+
},
28+
"include": ["src/"]
29+
}

0 commit comments

Comments
 (0)