-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunction.test.ts
More file actions
89 lines (75 loc) · 2.65 KB
/
function.test.ts
File metadata and controls
89 lines (75 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { describe, it, expect } from '@jest/globals';
import { Function } from './function.js';
import { loadTestCases, assertTestCase } from './test-helpers.js';
import { to } from '@crossplane-org/function-sdk-typescript';
import { glob } from 'glob';
describe('Function', () => {
it('should create a Function instance', () => {
const fn = new Function();
expect(fn).toBeInstanceOf(Function);
});
// Load and run all test cases from YAML files
const testCaseFiles = glob.sync('test-cases/**/*.yaml');
testCaseFiles.forEach((file) => {
const testCases = loadTestCases(file);
testCases.forEach((testCase) => {
it(`${testCase.name} (${file})`, async () => {
const fn = new Function();
// Build a complete request from the test input
// Use to() to ensure proper protobuf structure - it should preserve observed
const req = to(testCase.input) as any;
// Manually add observed since to() doesn't preserve it
if (testCase.input.observed) {
req.observed = testCase.input.observed;
}
// Run the function with the test input
const response = await fn.RunFunction(req);
// Assert the results match expectations
assertTestCase(response, testCase);
});
});
});
it('should create deployment with correct configuration', async () => {
const fn = new Function();
// Create a minimal request
const baseInput = {
meta: {
tag: 'test',
},
observed: {
composite: {
resource: {
apiVersion: 'platform.upbound.io/v1',
kind: 'App',
metadata: {
name: 'test-app',
},
},
},
},
desired: {
composite: {
resource: {},
},
resources: {},
},
};
const req = to(baseInput) as any;
if (baseInput.observed) {
req.observed = baseInput.observed;
}
const response = await fn.RunFunction(req);
expect(response).toBeDefined();
expect(response.desired).toBeDefined();
expect(response.desired?.resources).toBeDefined();
// Check deployment exists
const deployment = response.desired?.resources?.['deployment'];
expect(deployment).toBeDefined();
expect(deployment?.resource?.kind).toBe('Deployment');
expect(deployment?.resource?.apiVersion).toBe('apps/v1');
// Verify no service or ingress created (no config provided)
expect(response.desired?.resources?.['service']).toBeUndefined();
expect(response.desired?.resources?.['ingress']).toBeUndefined();
expect(response.desired?.resources?.['serviceaccount']).toBeUndefined();
});
});