@friggframework/devtools 2.0.0-next.39 → 2.0.0-next.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/infrastructure/README.md +19 -8
- package/infrastructure/aws-discovery.js +951 -345
- package/infrastructure/aws-discovery.test.js +1031 -184
- package/infrastructure/build-time-discovery.test.js +3 -0
- package/infrastructure/iam-generator.js +46 -0
- package/infrastructure/iam-generator.test.js +7 -4
- package/infrastructure/serverless-template.js +1096 -813
- package/infrastructure/serverless-template.test.js +1036 -21
- package/package.json +8 -6
- package/infrastructure/AWS-DISCOVERY-TROUBLESHOOTING.md +0 -245
- package/infrastructure/AWS-IAM-CREDENTIAL-NEEDS.md +0 -627
- package/infrastructure/README-TESTING.md +0 -332
|
@@ -1,332 +0,0 @@
|
|
|
1
|
-
# VPC/KMS/SSM Testing Strategy
|
|
2
|
-
|
|
3
|
-
This document outlines the comprehensive testing strategy for the VPC, KMS, and SSM support features in the Frigg framework.
|
|
4
|
-
|
|
5
|
-
## Overview
|
|
6
|
-
|
|
7
|
-
The testing suite covers:
|
|
8
|
-
- **AWS Discovery utilities** with mocked AWS SDK calls
|
|
9
|
-
- **Build-time discovery** with various app definition scenarios
|
|
10
|
-
- **Serverless template generation** with VPC/KMS/SSM configurations
|
|
11
|
-
- **Frigg serverless plugin** hooks and discovery integration
|
|
12
|
-
- **End-to-end integration tests** for complete workflows
|
|
13
|
-
- **Error handling and fallback scenarios**
|
|
14
|
-
|
|
15
|
-
## Test Structure
|
|
16
|
-
|
|
17
|
-
```
|
|
18
|
-
packages/devtools/infrastructure/
|
|
19
|
-
├── __tests__/
|
|
20
|
-
│ ├── fixtures/
|
|
21
|
-
│ │ └── mock-aws-resources.js # Mock AWS data and app definitions
|
|
22
|
-
│ └── helpers/
|
|
23
|
-
│ └── test-utils.js # Test utility functions
|
|
24
|
-
├── aws-discovery.test.js # Unit tests for AWSDiscovery class
|
|
25
|
-
├── build-time-discovery.test.js # Unit tests for BuildTimeDiscovery class
|
|
26
|
-
├── serverless-template.test.js # Unit tests for serverless template generation
|
|
27
|
-
├── integration.test.js # End-to-end integration tests
|
|
28
|
-
└── README-TESTING.md # This file
|
|
29
|
-
|
|
30
|
-
packages/serverless-plugin/
|
|
31
|
-
└── index.test.js # Unit tests for Frigg serverless plugin
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## Test Categories
|
|
35
|
-
|
|
36
|
-
### 1. Unit Tests
|
|
37
|
-
|
|
38
|
-
#### AWS Discovery (`aws-discovery.test.js`)
|
|
39
|
-
Tests the `AWSDiscovery` class methods:
|
|
40
|
-
- ✅ `getAccountId()` - STS caller identity retrieval
|
|
41
|
-
- ✅ `findDefaultVpc()` - Default VPC discovery with fallbacks
|
|
42
|
-
- ✅ `findPrivateSubnets()` - Private subnet identification
|
|
43
|
-
- ✅ `isSubnetPrivate()` - Route table analysis for subnet type
|
|
44
|
-
- ✅ `findDefaultSecurityGroup()` - Security group discovery (Frigg-specific then default)
|
|
45
|
-
- ✅ `findDefaultKmsKey()` - Customer-managed KMS key discovery
|
|
46
|
-
- ✅ `findPrivateRouteTable()` - Route table discovery for VPC endpoints
|
|
47
|
-
- ✅ `discoverResources()` - Complete resource discovery workflow
|
|
48
|
-
|
|
49
|
-
**Key Features Tested:**
|
|
50
|
-
- Mock AWS SDK v3 clients (EC2, KMS, STS)
|
|
51
|
-
- Error handling and fallback scenarios
|
|
52
|
-
- Single vs multiple subnet scenarios
|
|
53
|
-
- Customer vs AWS managed KMS keys
|
|
54
|
-
|
|
55
|
-
#### Build-Time Discovery (`build-time-discovery.test.js`)
|
|
56
|
-
Tests the `BuildTimeDiscovery` class:
|
|
57
|
-
- ✅ Resource discovery and configuration file generation
|
|
58
|
-
- ✅ Template variable replacement
|
|
59
|
-
- ✅ Serverless configuration processing
|
|
60
|
-
- ✅ Pre-build hook execution with app definitions
|
|
61
|
-
- ✅ Environment variable management
|
|
62
|
-
- ✅ Region-specific configuration
|
|
63
|
-
|
|
64
|
-
**Key Features Tested:**
|
|
65
|
-
- App definition parsing (VPC, KMS, SSM feature flags)
|
|
66
|
-
- Environment variable injection
|
|
67
|
-
- File I/O operations with mocked `fs`
|
|
68
|
-
- Error handling during discovery
|
|
69
|
-
|
|
70
|
-
#### Serverless Template (`serverless-template.test.js`)
|
|
71
|
-
Tests the `composeServerlessDefinition()` function:
|
|
72
|
-
- ✅ Basic serverless configuration generation
|
|
73
|
-
- ✅ VPC configuration (security groups, subnets, VPC endpoints)
|
|
74
|
-
- ✅ KMS configuration (IAM permissions, environment variables, plugins)
|
|
75
|
-
- ✅ SSM configuration (Lambda layers, IAM permissions)
|
|
76
|
-
- ✅ Integration-specific resources (functions, queues, workers)
|
|
77
|
-
- ✅ Combined feature configurations
|
|
78
|
-
- ✅ Edge cases and error scenarios
|
|
79
|
-
|
|
80
|
-
**Key Features Tested:**
|
|
81
|
-
- Conditional configuration based on app definition flags
|
|
82
|
-
- Environment variable referencing (`${env:AWS_DISCOVERY_*}`)
|
|
83
|
-
- Plugin management and ordering
|
|
84
|
-
- Default resource creation
|
|
85
|
-
|
|
86
|
-
#### Frigg Serverless Plugin (`packages/serverless-plugin/index.test.js`)
|
|
87
|
-
Tests the `FriggServerlessPlugin` class:
|
|
88
|
-
- ✅ Plugin initialization and hook registration
|
|
89
|
-
- ✅ AWS discovery triggering based on service configuration
|
|
90
|
-
- ✅ App definition creation from serverless service
|
|
91
|
-
- ✅ Environment variable injection during build
|
|
92
|
-
- ✅ Error handling with fallback values
|
|
93
|
-
- ✅ Offline mode queue creation (existing functionality)
|
|
94
|
-
|
|
95
|
-
**Key Features Tested:**
|
|
96
|
-
- Serverless framework hook integration
|
|
97
|
-
- Service configuration analysis
|
|
98
|
-
- BuildTimeDiscovery integration
|
|
99
|
-
- LocalStack queue creation for offline development
|
|
100
|
-
|
|
101
|
-
### 2. Integration Tests
|
|
102
|
-
|
|
103
|
-
#### End-to-End Workflow (`integration.test.js`)
|
|
104
|
-
Tests complete workflows:
|
|
105
|
-
- ✅ Full VPC + KMS + SSM configuration generation
|
|
106
|
-
- ✅ Individual feature testing (VPC-only, KMS-only, SSM-only)
|
|
107
|
-
- ✅ Plugin integration with discovery workflow
|
|
108
|
-
- ✅ Template variable resolution
|
|
109
|
-
- ✅ Error scenario handling
|
|
110
|
-
- ✅ Multi-region support
|
|
111
|
-
|
|
112
|
-
**Key Features Tested:**
|
|
113
|
-
- Complete discovery → configuration → deployment workflow
|
|
114
|
-
- Environment variable flow from discovery to serverless
|
|
115
|
-
- Plugin coordination with build-time discovery
|
|
116
|
-
- Realistic AWS resource scenarios
|
|
117
|
-
|
|
118
|
-
### 3. Test Fixtures and Utilities
|
|
119
|
-
|
|
120
|
-
#### Mock AWS Resources (`__tests__/fixtures/mock-aws-resources.js`)
|
|
121
|
-
Provides consistent test data:
|
|
122
|
-
- Mock VPC, subnets, security groups, route tables
|
|
123
|
-
- Mock KMS keys and metadata
|
|
124
|
-
- Mock STS caller identity
|
|
125
|
-
- Pre-defined app definitions for different scenarios
|
|
126
|
-
- Mock serverless service configurations
|
|
127
|
-
- Mock AWS SDK responses
|
|
128
|
-
|
|
129
|
-
#### Test Utilities (`__tests__/helpers/test-utils.js`)
|
|
130
|
-
Provides helper functions:
|
|
131
|
-
- Environment variable management
|
|
132
|
-
- Mock object creation (serverless, integrations, app definitions)
|
|
133
|
-
- Configuration verification functions
|
|
134
|
-
- Console output capture
|
|
135
|
-
- Async operation utilities
|
|
136
|
-
|
|
137
|
-
## Running Tests
|
|
138
|
-
|
|
139
|
-
### Prerequisites
|
|
140
|
-
|
|
141
|
-
Ensure you have the following installed:
|
|
142
|
-
- Node.js 18+ and npm
|
|
143
|
-
- Jest testing framework
|
|
144
|
-
- All project dependencies
|
|
145
|
-
|
|
146
|
-
### Running All Tests
|
|
147
|
-
|
|
148
|
-
```bash
|
|
149
|
-
# From the root of the Frigg project
|
|
150
|
-
npm test
|
|
151
|
-
|
|
152
|
-
# Run tests for specific packages
|
|
153
|
-
npm test --workspace=@friggframework/devtools
|
|
154
|
-
npm test --workspace=@friggframework/serverless-plugin
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
### Running Specific Test Suites
|
|
158
|
-
|
|
159
|
-
```bash
|
|
160
|
-
# AWS Discovery tests
|
|
161
|
-
npm test aws-discovery.test.js
|
|
162
|
-
|
|
163
|
-
# Build-time discovery tests
|
|
164
|
-
npm test build-time-discovery.test.js
|
|
165
|
-
|
|
166
|
-
# Serverless template tests
|
|
167
|
-
npm test serverless-template.test.js
|
|
168
|
-
|
|
169
|
-
# Plugin tests
|
|
170
|
-
npm test packages/serverless-plugin/index.test.js
|
|
171
|
-
|
|
172
|
-
# Integration tests
|
|
173
|
-
npm test integration.test.js
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
### Running Tests with Coverage
|
|
177
|
-
|
|
178
|
-
```bash
|
|
179
|
-
# Generate coverage report
|
|
180
|
-
npm test -- --coverage
|
|
181
|
-
|
|
182
|
-
# Coverage for specific files
|
|
183
|
-
npm test -- --coverage --collectCoverageFrom="**/infrastructure/**/*.js"
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
### Running Tests in Watch Mode
|
|
187
|
-
|
|
188
|
-
```bash
|
|
189
|
-
# Watch mode for development
|
|
190
|
-
npm test -- --watch
|
|
191
|
-
|
|
192
|
-
# Watch specific test files
|
|
193
|
-
npm test -- --watch aws-discovery.test.js
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
## Test Configuration
|
|
197
|
-
|
|
198
|
-
### Jest Configuration
|
|
199
|
-
|
|
200
|
-
Tests follow the existing Frigg Jest configuration:
|
|
201
|
-
- Timeout: 20,000ms for integration tests
|
|
202
|
-
- Test environment: Node.js
|
|
203
|
-
- Mock AWS SDK clients to avoid real AWS calls
|
|
204
|
-
- Environment variable isolation between tests
|
|
205
|
-
|
|
206
|
-
### Mock Strategy
|
|
207
|
-
|
|
208
|
-
**AWS SDK Mocking:**
|
|
209
|
-
- Mock AWS SDK v3 clients at the class level
|
|
210
|
-
- Use `jest.fn()` for consistent mock behavior
|
|
211
|
-
- Provide realistic response data matching AWS API schemas
|
|
212
|
-
|
|
213
|
-
**File System Mocking:**
|
|
214
|
-
- Mock `fs` operations for configuration file handling
|
|
215
|
-
- Test both success and error scenarios
|
|
216
|
-
|
|
217
|
-
**Environment Variable Isolation:**
|
|
218
|
-
- Save and restore original environment variables
|
|
219
|
-
- Clean up test environment variables after each test
|
|
220
|
-
|
|
221
|
-
## Testing Best Practices
|
|
222
|
-
|
|
223
|
-
### 1. Test Isolation
|
|
224
|
-
- Each test should be independent and not rely on previous test state
|
|
225
|
-
- Use `beforeEach` and `afterEach` to set up and clean up test state
|
|
226
|
-
- Mock external dependencies consistently
|
|
227
|
-
|
|
228
|
-
### 2. Error Scenario Testing
|
|
229
|
-
- Test AWS API failures and timeouts
|
|
230
|
-
- Test missing AWS resources
|
|
231
|
-
- Test invalid configuration scenarios
|
|
232
|
-
- Verify fallback mechanisms work correctly
|
|
233
|
-
|
|
234
|
-
### 3. Realistic Test Data
|
|
235
|
-
- Use realistic AWS resource IDs and ARNs
|
|
236
|
-
- Test with various AWS regions
|
|
237
|
-
- Test edge cases (single subnet, no customer KMS keys, etc.)
|
|
238
|
-
|
|
239
|
-
### 4. Integration Testing
|
|
240
|
-
- Test complete workflows from discovery to deployment
|
|
241
|
-
- Verify environment variable flow between components
|
|
242
|
-
- Test plugin coordination and timing
|
|
243
|
-
|
|
244
|
-
## Coverage Goals
|
|
245
|
-
|
|
246
|
-
### Current Coverage Targets
|
|
247
|
-
- **Unit Tests:** 95%+ line coverage for core functionality
|
|
248
|
-
- **Integration Tests:** 85%+ coverage for end-to-end workflows
|
|
249
|
-
- **Error Scenarios:** 90%+ coverage for error handling paths
|
|
250
|
-
|
|
251
|
-
### Critical Paths
|
|
252
|
-
Ensure 100% coverage for:
|
|
253
|
-
- AWS resource discovery logic
|
|
254
|
-
- App definition parsing
|
|
255
|
-
- Environment variable management
|
|
256
|
-
- Plugin hook execution
|
|
257
|
-
- Fallback value assignment
|
|
258
|
-
|
|
259
|
-
## Continuous Integration
|
|
260
|
-
|
|
261
|
-
### Pre-commit Hooks
|
|
262
|
-
- Run linting and type checking
|
|
263
|
-
- Execute fast unit tests
|
|
264
|
-
- Verify test file naming conventions
|
|
265
|
-
|
|
266
|
-
### CI Pipeline
|
|
267
|
-
- Run complete test suite on all pull requests
|
|
268
|
-
- Generate and upload coverage reports
|
|
269
|
-
- Test against multiple Node.js versions
|
|
270
|
-
- Verify tests in different AWS regions (if applicable)
|
|
271
|
-
|
|
272
|
-
## Debugging Tests
|
|
273
|
-
|
|
274
|
-
### Common Issues
|
|
275
|
-
|
|
276
|
-
**AWS SDK Mock Issues:**
|
|
277
|
-
```bash
|
|
278
|
-
# Verify mock setup
|
|
279
|
-
console.log('Mock called with:', mockEC2Send.mock.calls);
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
**Environment Variable Issues:**
|
|
283
|
-
```bash
|
|
284
|
-
# Check environment state
|
|
285
|
-
console.log('Current env:', process.env);
|
|
286
|
-
```
|
|
287
|
-
|
|
288
|
-
**Async Test Issues:**
|
|
289
|
-
```bash
|
|
290
|
-
# Ensure proper async handling
|
|
291
|
-
await expect(asyncFunction()).resolves.toEqual(expectedValue);
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
### Debug Commands
|
|
295
|
-
|
|
296
|
-
```bash
|
|
297
|
-
# Run single test with verbose output
|
|
298
|
-
npm test -- --verbose aws-discovery.test.js
|
|
299
|
-
|
|
300
|
-
# Run with console output
|
|
301
|
-
npm test -- --verbose --silent=false
|
|
302
|
-
|
|
303
|
-
# Debug specific test
|
|
304
|
-
npm test -- --testNamePattern="should discover all AWS resources"
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
## Contributing
|
|
308
|
-
|
|
309
|
-
When adding new VPC/KMS/SSM functionality:
|
|
310
|
-
|
|
311
|
-
1. **Add unit tests** for new functions/methods
|
|
312
|
-
2. **Update integration tests** to cover new workflows
|
|
313
|
-
3. **Add mock data** to fixtures for new AWS resources
|
|
314
|
-
4. **Update test utilities** if new helper functions are needed
|
|
315
|
-
5. **Document test coverage** for new features
|
|
316
|
-
6. **Verify CI pipeline** passes with new tests
|
|
317
|
-
|
|
318
|
-
### Test Naming Conventions
|
|
319
|
-
|
|
320
|
-
- Test files: `*.test.js`
|
|
321
|
-
- Test descriptions: Use clear, descriptive language
|
|
322
|
-
- Group related tests with `describe()` blocks
|
|
323
|
-
- Use `it()` for individual test cases
|
|
324
|
-
|
|
325
|
-
### Mock Data Guidelines
|
|
326
|
-
|
|
327
|
-
- Keep mock data realistic and consistent
|
|
328
|
-
- Use the fixtures file for shared test data
|
|
329
|
-
- Document any special mock scenarios
|
|
330
|
-
- Update mocks when AWS APIs change
|
|
331
|
-
|
|
332
|
-
This testing strategy ensures the VPC/KMS/SSM features are robust, reliable, and maintainable while following Frigg's existing testing patterns and conventions.
|