|
1 | 1 | import cdk = require('@aws-cdk/core');
|
2 | 2 | import { Test } from 'nodeunit';
|
3 | 3 | import stepfunctions = require('../lib');
|
| 4 | +import { isPositiveInteger } from '../lib'; |
4 | 5 |
|
5 | 6 | export = {
|
6 | 7 | 'State Machine With Map State'(test: Test) {
|
@@ -42,9 +43,129 @@ export = {
|
42 | 43 | });
|
43 | 44 |
|
44 | 45 | test.done();
|
| 46 | + }, |
| 47 | + 'synth is successful'(test: Test) { |
| 48 | + |
| 49 | + const app = createAppWithMap((stack) => { |
| 50 | + const map = new stepfunctions.Map(stack, 'Map State', { |
| 51 | + maxConcurrency: 1, |
| 52 | + itemsPath: stepfunctions.Data.stringAt('$.inputForMap') |
| 53 | + }); |
| 54 | + map.iterator(new stepfunctions.Pass(stack, 'Pass State')); |
| 55 | + return map; |
| 56 | + }); |
| 57 | + |
| 58 | + app.synth(); |
| 59 | + test.done(); |
| 60 | + }, |
| 61 | + 'fails in synthesis if iterator is missing'(test: Test) { |
| 62 | + |
| 63 | + const app = createAppWithMap((stack) => { |
| 64 | + const map = new stepfunctions.Map(stack, 'Map State', { |
| 65 | + maxConcurrency: 1, |
| 66 | + itemsPath: stepfunctions.Data.stringAt('$.inputForMap') |
| 67 | + }); |
| 68 | + |
| 69 | + return map; |
| 70 | + }); |
| 71 | + |
| 72 | + test.throws(() => { |
| 73 | + app.synth(); |
| 74 | + }, /Map state must have a non-empty iterator/, 'A validation was expected'); |
| 75 | + |
| 76 | + test.done(); |
| 77 | + }, |
| 78 | + 'fails in synthesis when maxConcurrency is a float'(test: Test) { |
| 79 | + |
| 80 | + const app = createAppWithMap((stack) => { |
| 81 | + const map = new stepfunctions.Map(stack, 'Map State', { |
| 82 | + maxConcurrency: 1.2, |
| 83 | + itemsPath: stepfunctions.Data.stringAt('$.inputForMap') |
| 84 | + }); |
| 85 | + map.iterator(new stepfunctions.Pass(stack, 'Pass State')); |
| 86 | + |
| 87 | + return map; |
| 88 | + }); |
| 89 | + |
| 90 | + test.throws(() => { |
| 91 | + app.synth(); |
| 92 | + }, /maxConcurrency has to be a positive integer/, 'A validation was expected'); |
| 93 | + |
| 94 | + test.done(); |
| 95 | + |
| 96 | + }, |
| 97 | + 'fails in synthesis when maxConcurrency is a negative integer'(test: Test) { |
| 98 | + |
| 99 | + const app = createAppWithMap((stack) => { |
| 100 | + const map = new stepfunctions.Map(stack, 'Map State', { |
| 101 | + maxConcurrency: -1, |
| 102 | + itemsPath: stepfunctions.Data.stringAt('$.inputForMap') |
| 103 | + }); |
| 104 | + map.iterator(new stepfunctions.Pass(stack, 'Pass State')); |
| 105 | + |
| 106 | + return map; |
| 107 | + }); |
| 108 | + |
| 109 | + test.throws(() => { |
| 110 | + app.synth(); |
| 111 | + }, /maxConcurrency has to be a positive integer/, 'A validation was expected'); |
| 112 | + |
| 113 | + test.done(); |
| 114 | + }, |
| 115 | + 'fails in synthesis when maxConcurrency is too big to be an integer'(test: Test) { |
| 116 | + |
| 117 | + const app = createAppWithMap((stack) => { |
| 118 | + const map = new stepfunctions.Map(stack, 'Map State', { |
| 119 | + maxConcurrency: Number.MAX_VALUE, |
| 120 | + itemsPath: stepfunctions.Data.stringAt('$.inputForMap') |
| 121 | + }); |
| 122 | + map.iterator(new stepfunctions.Pass(stack, 'Pass State')); |
| 123 | + |
| 124 | + return map; |
| 125 | + }); |
| 126 | + |
| 127 | + test.throws(() => { |
| 128 | + app.synth(); |
| 129 | + }, /maxConcurrency has to be a positive integer/, 'A validation was expected'); |
| 130 | + |
| 131 | + test.done(); |
| 132 | + |
| 133 | + }, |
| 134 | + 'isPositiveInteger is false with negative number'(test: Test) { |
| 135 | + test.equals(isPositiveInteger(-1), false, '-1 is not a valid positive integer'); |
| 136 | + test.done(); |
| 137 | + }, |
| 138 | + 'isPositiveInteger is false with decimal number'(test: Test) { |
| 139 | + test.equals(isPositiveInteger(1.2), false, '1.2 is not a valid positive integer'); |
| 140 | + test.done(); |
| 141 | + }, |
| 142 | + 'isPositiveInteger is false with a value greater than safe integer '(test: Test) { |
| 143 | + const valueToTest = Number.MAX_SAFE_INTEGER + 1; |
| 144 | + test.equals(isPositiveInteger(valueToTest), false, `${valueToTest} is not a valid positive integer`); |
| 145 | + test.done(); |
| 146 | + }, |
| 147 | + 'isPositiveInteger is true with 0'(test: Test) { |
| 148 | + test.equals(isPositiveInteger(0), true, '0 is expected to be a positive integer'); |
| 149 | + test.done(); |
| 150 | + }, |
| 151 | + 'isPositiveInteger is true with 10'(test: Test) { |
| 152 | + test.equals(isPositiveInteger(10), true, '10 is expected to be a positive integer'); |
| 153 | + test.done(); |
| 154 | + }, |
| 155 | + 'isPositiveInteger is true with max integer value'(test: Test) { |
| 156 | + test.equals(isPositiveInteger(Number.MAX_SAFE_INTEGER), true, `${Number.MAX_SAFE_INTEGER} is expected to be a positive integer`); |
| 157 | + test.done(); |
45 | 158 | }
|
46 | 159 | };
|
47 | 160 |
|
48 | 161 | function render(sm: stepfunctions.IChainable) {
|
49 | 162 | return new cdk.Stack().resolve(new stepfunctions.StateGraph(sm.startState, 'Test Graph').toGraphJson());
|
50 | 163 | }
|
| 164 | + |
| 165 | +function createAppWithMap(mapFactory: (stack: cdk.Stack) => stepfunctions.Map) { |
| 166 | + const app = new cdk.App(); |
| 167 | + const stack = new cdk.Stack(app, 'my-stack'); |
| 168 | + const map = mapFactory(stack); |
| 169 | + new stepfunctions.StateGraph(map, 'Test Graph'); |
| 170 | + return app; |
| 171 | +} |
0 commit comments