pepr 0.3.0-rc0 → 0.3.0
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/README.md +3 -46
- package/dist/package.json +1 -1
- package/package.json +1 -1
- package/dist/fixtures/data/cm1.json +0 -75
- package/dist/fixtures/data/deployment1.json +0 -170
- package/dist/fixtures/data/ns1.json +0 -72
- package/dist/fixtures/data/pod1.json +0 -271
- package/dist/fixtures/data/pod2.json +0 -257
- package/dist/fixtures/data/svc1.json +0 -100
- package/dist/fixtures/loader.js +0 -60
- package/dist/src/cli/init/utils.test.js +0 -29
- package/dist/src/cli/init/walkthrough.test.js +0 -21
- package/dist/src/lib/fetch.test.js +0 -98
- package/dist/src/lib/filter.test.js +0 -208
- package/dist/src/lib/k8s/kinds.test.js +0 -296
- package/dist/src/lib/logger.test.js +0 -64
- package/docs/.prettierrc.json +0 -13
- package/docs/actions.md +0 -58
- package/docs/capabilities.md +0 -17
- package/docs/cli.md +0 -58
- package/docs/module.md +0 -90
- package/osv-scanner.toml +0 -4
- package/src/lib/fetch.test.ts +0 -115
- package/src/lib/filter.test.ts +0 -231
- package/src/lib/k8s/kinds.test.ts +0 -333
- package/src/lib/logger.test.ts +0 -80
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"uid": "e40aafc4-db17-4368-89e9-e7bda15b814d",
|
|
3
|
-
"kind": {
|
|
4
|
-
"group": "",
|
|
5
|
-
"version": "v1",
|
|
6
|
-
"kind": "Pod"
|
|
7
|
-
},
|
|
8
|
-
"resource": {
|
|
9
|
-
"group": "",
|
|
10
|
-
"version": "v1",
|
|
11
|
-
"resource": "pods"
|
|
12
|
-
},
|
|
13
|
-
"requestKind": {
|
|
14
|
-
"group": "",
|
|
15
|
-
"version": "v1",
|
|
16
|
-
"kind": "Pod"
|
|
17
|
-
},
|
|
18
|
-
"requestResource": {
|
|
19
|
-
"group": "",
|
|
20
|
-
"version": "v1",
|
|
21
|
-
"resource": "pods"
|
|
22
|
-
},
|
|
23
|
-
"name": "lifespan-seven",
|
|
24
|
-
"namespace": "apps",
|
|
25
|
-
"operation": "CREATE",
|
|
26
|
-
"userInfo": {
|
|
27
|
-
"username": "kubernetes-admin",
|
|
28
|
-
"groups": ["system:masters", "system:authenticated"]
|
|
29
|
-
},
|
|
30
|
-
"object": {
|
|
31
|
-
"kind": "Pod",
|
|
32
|
-
"apiVersion": "v1",
|
|
33
|
-
"metadata": {
|
|
34
|
-
"name": "lifespan-seven",
|
|
35
|
-
"namespace": "apps",
|
|
36
|
-
"uid": "6cc7f934-7054-4387-9a69-84fb3dc9fd87",
|
|
37
|
-
"creationTimestamp": "2023-03-31T18:15:31Z",
|
|
38
|
-
"labels": {
|
|
39
|
-
"acme.com/lifespan-requested": "7"
|
|
40
|
-
},
|
|
41
|
-
"annotations": {
|
|
42
|
-
"kubectl.kubernetes.io/last-applied-configuration": {
|
|
43
|
-
"apiVersion": "v1",
|
|
44
|
-
"kind": "Pod",
|
|
45
|
-
"metadata": {
|
|
46
|
-
"annotations": {},
|
|
47
|
-
"labels": {
|
|
48
|
-
"acme.com/lifespan-requested": "7"
|
|
49
|
-
},
|
|
50
|
-
"name": "lifespan-seven",
|
|
51
|
-
"namespace": "apps"
|
|
52
|
-
},
|
|
53
|
-
"spec": {
|
|
54
|
-
"containers": [
|
|
55
|
-
{
|
|
56
|
-
"args": ["sleep", "3600"],
|
|
57
|
-
"image": "busybox",
|
|
58
|
-
"name": "lifespan-seven"
|
|
59
|
-
}
|
|
60
|
-
],
|
|
61
|
-
"restartPolicy": "Always"
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
"managedFields": [
|
|
66
|
-
{
|
|
67
|
-
"manager": "kubectl-client-side-apply",
|
|
68
|
-
"operation": "Update",
|
|
69
|
-
"apiVersion": "v1",
|
|
70
|
-
"time": "2023-03-31T18:15:31Z",
|
|
71
|
-
"fieldsType": "FieldsV1",
|
|
72
|
-
"fieldsV1": {
|
|
73
|
-
"f:metadata": {
|
|
74
|
-
"f:annotations": {
|
|
75
|
-
".": {},
|
|
76
|
-
"f:kubectl.kubernetes.io/last-applied-configuration": {}
|
|
77
|
-
},
|
|
78
|
-
"f:labels": {
|
|
79
|
-
".": {},
|
|
80
|
-
"f:acme.com/lifespan-requested": {}
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
"f:spec": {
|
|
84
|
-
"f:containers": {
|
|
85
|
-
"k:{\"name\":\"lifespan-seven\"}": {
|
|
86
|
-
".": {},
|
|
87
|
-
"f:args": {},
|
|
88
|
-
"f:image": {},
|
|
89
|
-
"f:imagePullPolicy": {},
|
|
90
|
-
"f:name": {},
|
|
91
|
-
"f:resources": {},
|
|
92
|
-
"f:terminationMessagePath": {},
|
|
93
|
-
"f:terminationMessagePolicy": {}
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
"f:dnsPolicy": {},
|
|
97
|
-
"f:enableServiceLinks": {},
|
|
98
|
-
"f:restartPolicy": {},
|
|
99
|
-
"f:schedulerName": {},
|
|
100
|
-
"f:securityContext": {},
|
|
101
|
-
"f:terminationGracePeriodSeconds": {}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
]
|
|
106
|
-
},
|
|
107
|
-
"spec": {
|
|
108
|
-
"volumes": [
|
|
109
|
-
{
|
|
110
|
-
"name": "kube-api-access-65g4k",
|
|
111
|
-
"projected": {
|
|
112
|
-
"sources": [
|
|
113
|
-
{
|
|
114
|
-
"serviceAccountToken": {
|
|
115
|
-
"expirationSeconds": 3607,
|
|
116
|
-
"path": "token"
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
"configMap": {
|
|
121
|
-
"name": "kube-root-ca.crt",
|
|
122
|
-
"items": [
|
|
123
|
-
{
|
|
124
|
-
"key": "ca.crt",
|
|
125
|
-
"path": "ca.crt"
|
|
126
|
-
}
|
|
127
|
-
]
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
"downwardAPI": {
|
|
132
|
-
"items": [
|
|
133
|
-
{
|
|
134
|
-
"path": "namespace",
|
|
135
|
-
"fieldRef": {
|
|
136
|
-
"apiVersion": "v1",
|
|
137
|
-
"fieldPath": "metadata.namespace"
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
]
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
],
|
|
144
|
-
"defaultMode": 420
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
],
|
|
148
|
-
"containers": [
|
|
149
|
-
{
|
|
150
|
-
"name": "lifespan-seven",
|
|
151
|
-
"image": "busybox",
|
|
152
|
-
"args": ["sleep", "3600"],
|
|
153
|
-
"env": [
|
|
154
|
-
{
|
|
155
|
-
"name": "KUBE",
|
|
156
|
-
"value": "true"
|
|
157
|
-
}
|
|
158
|
-
],
|
|
159
|
-
"resources": {},
|
|
160
|
-
"volumeMounts": [
|
|
161
|
-
{
|
|
162
|
-
"name": "kube-api-access-65g4k",
|
|
163
|
-
"readOnly": true,
|
|
164
|
-
"mountPath": "/var/run/secrets/kubernetes.io/serviceaccount"
|
|
165
|
-
}
|
|
166
|
-
],
|
|
167
|
-
"terminationMessagePath": "/dev/termination-log",
|
|
168
|
-
"terminationMessagePolicy": "File",
|
|
169
|
-
"imagePullPolicy": "Always"
|
|
170
|
-
}
|
|
171
|
-
],
|
|
172
|
-
"restartPolicy": "Always",
|
|
173
|
-
"terminationGracePeriodSeconds": 30,
|
|
174
|
-
"dnsPolicy": "ClusterFirst",
|
|
175
|
-
"serviceAccountName": "default",
|
|
176
|
-
"serviceAccount": "default",
|
|
177
|
-
"securityContext": {},
|
|
178
|
-
"schedulerName": "default-scheduler",
|
|
179
|
-
"tolerations": [
|
|
180
|
-
{
|
|
181
|
-
"key": "node.kubernetes.io/not-ready",
|
|
182
|
-
"operator": "Exists",
|
|
183
|
-
"effect": "NoExecute",
|
|
184
|
-
"tolerationSeconds": 300
|
|
185
|
-
},
|
|
186
|
-
{
|
|
187
|
-
"key": "node.kubernetes.io/unreachable",
|
|
188
|
-
"operator": "Exists",
|
|
189
|
-
"effect": "NoExecute",
|
|
190
|
-
"tolerationSeconds": 300
|
|
191
|
-
},
|
|
192
|
-
{
|
|
193
|
-
"key": "acme.com/lifespan-remaining",
|
|
194
|
-
"operator": "Equal",
|
|
195
|
-
"value": "14",
|
|
196
|
-
"effect": "NoSchedule"
|
|
197
|
-
},
|
|
198
|
-
{
|
|
199
|
-
"key": "acme.com/lifespan-remaining",
|
|
200
|
-
"operator": "Equal",
|
|
201
|
-
"value": "13",
|
|
202
|
-
"effect": "NoSchedule"
|
|
203
|
-
},
|
|
204
|
-
{
|
|
205
|
-
"key": "acme.com/lifespan-remaining",
|
|
206
|
-
"operator": "Equal",
|
|
207
|
-
"value": "12",
|
|
208
|
-
"effect": "NoSchedule"
|
|
209
|
-
},
|
|
210
|
-
{
|
|
211
|
-
"key": "acme.com/lifespan-remaining",
|
|
212
|
-
"operator": "Equal",
|
|
213
|
-
"value": "11",
|
|
214
|
-
"effect": "NoSchedule"
|
|
215
|
-
},
|
|
216
|
-
{
|
|
217
|
-
"key": "acme.com/lifespan-remaining",
|
|
218
|
-
"operator": "Equal",
|
|
219
|
-
"value": "10",
|
|
220
|
-
"effect": "NoSchedule"
|
|
221
|
-
},
|
|
222
|
-
{
|
|
223
|
-
"key": "acme.com/lifespan-remaining",
|
|
224
|
-
"operator": "Equal",
|
|
225
|
-
"value": "9",
|
|
226
|
-
"effect": "NoSchedule"
|
|
227
|
-
},
|
|
228
|
-
{
|
|
229
|
-
"key": "acme.com/lifespan-remaining",
|
|
230
|
-
"operator": "Equal",
|
|
231
|
-
"value": "8",
|
|
232
|
-
"effect": "NoSchedule"
|
|
233
|
-
},
|
|
234
|
-
{
|
|
235
|
-
"key": "acme.com/lifespan-remaining",
|
|
236
|
-
"operator": "Equal",
|
|
237
|
-
"value": "7",
|
|
238
|
-
"effect": "NoSchedule"
|
|
239
|
-
}
|
|
240
|
-
],
|
|
241
|
-
"priority": 0,
|
|
242
|
-
"enableServiceLinks": true,
|
|
243
|
-
"preemptionPolicy": "PreemptLowerPriority"
|
|
244
|
-
},
|
|
245
|
-
"status": {
|
|
246
|
-
"phase": "Pending",
|
|
247
|
-
"qosClass": "BestEffort"
|
|
248
|
-
}
|
|
249
|
-
},
|
|
250
|
-
"oldObject": null,
|
|
251
|
-
"dryRun": false,
|
|
252
|
-
"options": {
|
|
253
|
-
"kind": "CreateOptions",
|
|
254
|
-
"apiVersion": "meta.k8s.io/v1",
|
|
255
|
-
"fieldManager": "kubectl-client-side-apply"
|
|
256
|
-
}
|
|
257
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"uid": "f7b55ff2-18ef-403c-87fe-bac8435e0ed7",
|
|
3
|
-
"kind": {
|
|
4
|
-
"group": "",
|
|
5
|
-
"version": "v1",
|
|
6
|
-
"kind": "Service"
|
|
7
|
-
},
|
|
8
|
-
"resource": {
|
|
9
|
-
"group": "",
|
|
10
|
-
"version": "v1",
|
|
11
|
-
"resource": "services"
|
|
12
|
-
},
|
|
13
|
-
"requestKind": {
|
|
14
|
-
"group": "",
|
|
15
|
-
"version": "v1",
|
|
16
|
-
"kind": "Service"
|
|
17
|
-
},
|
|
18
|
-
"requestResource": {
|
|
19
|
-
"group": "",
|
|
20
|
-
"version": "v1",
|
|
21
|
-
"resource": "services"
|
|
22
|
-
},
|
|
23
|
-
"name": "my-service",
|
|
24
|
-
"namespace": "apps",
|
|
25
|
-
"operation": "CREATE",
|
|
26
|
-
"userInfo": {
|
|
27
|
-
"username": "kubernetes-admin",
|
|
28
|
-
"groups": ["system:masters", "system:authenticated"]
|
|
29
|
-
},
|
|
30
|
-
"object": {
|
|
31
|
-
"kind": "Service",
|
|
32
|
-
"apiVersion": "v1",
|
|
33
|
-
"metadata": {
|
|
34
|
-
"name": "my-service",
|
|
35
|
-
"namespace": "apps",
|
|
36
|
-
"creationTimestamp": null,
|
|
37
|
-
"annotations": {
|
|
38
|
-
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Service\",\"metadata\":{\"annotations\":{},\"name\":\"my-service\",\"namespace\":\"apps\"},\"spec\":{\"ports\":[{\"port\":80,\"protocol\":\"TCP\",\"targetPort\":9376}],\"selector\":{\"app.kubernetes.io/name\":\"MyApp\"}}}\n"
|
|
39
|
-
},
|
|
40
|
-
"managedFields": [
|
|
41
|
-
{
|
|
42
|
-
"manager": "kubectl-client-side-apply",
|
|
43
|
-
"operation": "Update",
|
|
44
|
-
"apiVersion": "v1",
|
|
45
|
-
"time": "2023-03-31T19:08:48Z",
|
|
46
|
-
"fieldsType": "FieldsV1",
|
|
47
|
-
"fieldsV1": {
|
|
48
|
-
"f:metadata": {
|
|
49
|
-
"f:annotations": {
|
|
50
|
-
".": {},
|
|
51
|
-
"f:kubectl.kubernetes.io/last-applied-configuration": {}
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
"f:spec": {
|
|
55
|
-
"f:ports": {
|
|
56
|
-
".": {},
|
|
57
|
-
"k:{\"port\":80,\"protocol\":\"TCP\"}": {
|
|
58
|
-
".": {},
|
|
59
|
-
"f:port": {},
|
|
60
|
-
"f:protocol": {},
|
|
61
|
-
"f:targetPort": {}
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
"f:selector": {
|
|
65
|
-
".": {},
|
|
66
|
-
"f:app.kubernetes.io/name": {}
|
|
67
|
-
},
|
|
68
|
-
"f:sessionAffinity": {},
|
|
69
|
-
"f:type": {}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
]
|
|
74
|
-
},
|
|
75
|
-
"spec": {
|
|
76
|
-
"ports": [
|
|
77
|
-
{
|
|
78
|
-
"protocol": "TCP",
|
|
79
|
-
"port": 80,
|
|
80
|
-
"targetPort": 9376
|
|
81
|
-
}
|
|
82
|
-
],
|
|
83
|
-
"selector": {
|
|
84
|
-
"app.kubernetes.io/name": "MyApp"
|
|
85
|
-
},
|
|
86
|
-
"type": "ClusterIP",
|
|
87
|
-
"sessionAffinity": "None"
|
|
88
|
-
},
|
|
89
|
-
"status": {
|
|
90
|
-
"loadBalancer": {}
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
"oldObject": null,
|
|
94
|
-
"dryRun": false,
|
|
95
|
-
"options": {
|
|
96
|
-
"kind": "CreateOptions",
|
|
97
|
-
"apiVersion": "meta.k8s.io/v1",
|
|
98
|
-
"fieldManager": "kubectl-client-side-apply"
|
|
99
|
-
}
|
|
100
|
-
}
|
package/dist/fixtures/loader.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.NS1 = exports.CM1 = exports.DEPLOYMENT1 = exports.SVC1 = exports.POD2 = exports.POD1 = void 0;
|
|
27
|
-
const cm1 = __importStar(require("./data/cm1.json"));
|
|
28
|
-
const deployment1 = __importStar(require("./data/deployment1.json"));
|
|
29
|
-
const ns1 = __importStar(require("./data/ns1.json"));
|
|
30
|
-
const pod1 = __importStar(require("./data/pod1.json"));
|
|
31
|
-
const pod2 = __importStar(require("./data/pod2.json"));
|
|
32
|
-
const svc1 = __importStar(require("./data/svc1.json"));
|
|
33
|
-
function POD1() {
|
|
34
|
-
return cloneObject(pod1);
|
|
35
|
-
}
|
|
36
|
-
exports.POD1 = POD1;
|
|
37
|
-
function POD2() {
|
|
38
|
-
return cloneObject(pod2);
|
|
39
|
-
}
|
|
40
|
-
exports.POD2 = POD2;
|
|
41
|
-
function SVC1() {
|
|
42
|
-
return cloneObject(svc1);
|
|
43
|
-
}
|
|
44
|
-
exports.SVC1 = SVC1;
|
|
45
|
-
function DEPLOYMENT1() {
|
|
46
|
-
return cloneObject(deployment1);
|
|
47
|
-
}
|
|
48
|
-
exports.DEPLOYMENT1 = DEPLOYMENT1;
|
|
49
|
-
function CM1() {
|
|
50
|
-
return cloneObject(cm1);
|
|
51
|
-
}
|
|
52
|
-
exports.CM1 = CM1;
|
|
53
|
-
function NS1() {
|
|
54
|
-
return cloneObject(ns1);
|
|
55
|
-
}
|
|
56
|
-
exports.NS1 = NS1;
|
|
57
|
-
function cloneObject(obj) {
|
|
58
|
-
// JSON to avoid funky typescript silliness on jsonmodules
|
|
59
|
-
return JSON.parse(JSON.stringify(obj));
|
|
60
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
|
|
4
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
-
};
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
const ava_1 = __importDefault(require("ava"));
|
|
9
|
-
const utils_1 = require("./utils");
|
|
10
|
-
(0, ava_1.default)("sanitizeName() sanitizes names correctly", t => {
|
|
11
|
-
const cases = [
|
|
12
|
-
{
|
|
13
|
-
input: "My Test Module",
|
|
14
|
-
expected: "my-test-module",
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
input: "!! 123 @@ Module",
|
|
18
|
-
expected: "123-module",
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
input: "---Test-Module---",
|
|
22
|
-
expected: "test-module",
|
|
23
|
-
},
|
|
24
|
-
];
|
|
25
|
-
for (const { input, expected } of cases) {
|
|
26
|
-
const result = (0, utils_1.sanitizeName)(input);
|
|
27
|
-
t.is(result, expected, `sanitizeName(${input}) should be ${expected}`);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
|
|
4
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
-
};
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
const ava_1 = __importDefault(require("ava"));
|
|
9
|
-
const prompts_1 = __importDefault(require("prompts"));
|
|
10
|
-
const walkthrough_1 = require("./walkthrough");
|
|
11
|
-
(0, ava_1.default)("walkthrough() returns expected results", async (t) => {
|
|
12
|
-
// Inject predefined answers for the prompts
|
|
13
|
-
prompts_1.default.inject(["My Test Module", "A test module for Pepr", 0]);
|
|
14
|
-
const result = await (0, walkthrough_1.walkthrough)();
|
|
15
|
-
// Check the returned object
|
|
16
|
-
t.deepEqual(result, {
|
|
17
|
-
name: "My Test Module",
|
|
18
|
-
description: "A test module for Pepr",
|
|
19
|
-
errorBehavior: 0,
|
|
20
|
-
});
|
|
21
|
-
});
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
|
|
4
|
-
// fetch.test.ts
|
|
5
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
const ava_1 = __importDefault(require("ava"));
|
|
10
|
-
const http_status_codes_1 = require("http-status-codes");
|
|
11
|
-
const nock_1 = __importDefault(require("nock"));
|
|
12
|
-
const fetch_1 = require("./fetch");
|
|
13
|
-
ava_1.default.beforeEach(() => {
|
|
14
|
-
(0, nock_1.default)("https://jsonplaceholder.typicode.com")
|
|
15
|
-
.get("/todos/1")
|
|
16
|
-
.reply(200, {
|
|
17
|
-
userId: 1,
|
|
18
|
-
id: 1,
|
|
19
|
-
title: "Example title",
|
|
20
|
-
completed: false,
|
|
21
|
-
})
|
|
22
|
-
.post("/todos", {
|
|
23
|
-
title: "test todo",
|
|
24
|
-
userId: 1,
|
|
25
|
-
completed: false,
|
|
26
|
-
})
|
|
27
|
-
.reply(200, (uri, requestBody) => requestBody)
|
|
28
|
-
.get("/todos/empty-null")
|
|
29
|
-
.reply(200, undefined)
|
|
30
|
-
.get("/todos/empty-string")
|
|
31
|
-
.reply(200, "")
|
|
32
|
-
.get("/todos/empty-object")
|
|
33
|
-
.reply(200, {})
|
|
34
|
-
.get("/todos/invalid")
|
|
35
|
-
.replyWithError("Something bad happened");
|
|
36
|
-
});
|
|
37
|
-
(0, ava_1.default)("fetch: should return without type data", async (t) => {
|
|
38
|
-
const url = "https://jsonplaceholder.typicode.com/todos/1";
|
|
39
|
-
const { data, ok } = await (0, fetch_1.fetch)(url);
|
|
40
|
-
t.is(ok, true);
|
|
41
|
-
t.is(data["title"], "Example title");
|
|
42
|
-
});
|
|
43
|
-
(0, ava_1.default)("fetch: should return parsed JSON response as a specific type", async (t) => {
|
|
44
|
-
const url = "https://jsonplaceholder.typicode.com/todos/1";
|
|
45
|
-
const { data, ok } = await (0, fetch_1.fetch)(url);
|
|
46
|
-
t.is(ok, true);
|
|
47
|
-
t.is(data.id, 1);
|
|
48
|
-
t.is(typeof data.title, "string");
|
|
49
|
-
t.is(typeof data.completed, "boolean");
|
|
50
|
-
});
|
|
51
|
-
(0, ava_1.default)("fetch: should handle additional request options", async (t) => {
|
|
52
|
-
const url = "https://jsonplaceholder.typicode.com/todos";
|
|
53
|
-
const requestOptions = {
|
|
54
|
-
method: "POST",
|
|
55
|
-
body: JSON.stringify({
|
|
56
|
-
title: "test todo",
|
|
57
|
-
userId: 1,
|
|
58
|
-
completed: false,
|
|
59
|
-
}),
|
|
60
|
-
headers: {
|
|
61
|
-
"Content-type": "application/json; charset=UTF-8",
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
|
-
const { data, ok } = await (0, fetch_1.fetch)(url, requestOptions);
|
|
66
|
-
t.is(ok, true);
|
|
67
|
-
t.is(data["title"], "test todo");
|
|
68
|
-
t.is(data["userId"], 1);
|
|
69
|
-
t.is(data["completed"], false);
|
|
70
|
-
});
|
|
71
|
-
(0, ava_1.default)("fetch: should handle empty (null) responses", async (t) => {
|
|
72
|
-
const url = "https://jsonplaceholder.typicode.com/todos/empty-null";
|
|
73
|
-
const resp = await (0, fetch_1.fetch)(url);
|
|
74
|
-
t.is(resp.data, "");
|
|
75
|
-
t.is(resp.ok, true);
|
|
76
|
-
t.is(resp.status, http_status_codes_1.StatusCodes.OK);
|
|
77
|
-
});
|
|
78
|
-
(0, ava_1.default)("fetch: should handle empty (string) responses", async (t) => {
|
|
79
|
-
const url = "https://jsonplaceholder.typicode.com/todos/empty-string";
|
|
80
|
-
const resp = await (0, fetch_1.fetch)(url);
|
|
81
|
-
t.is(resp.data, "");
|
|
82
|
-
t.is(resp.ok, true);
|
|
83
|
-
t.is(resp.status, http_status_codes_1.StatusCodes.OK);
|
|
84
|
-
});
|
|
85
|
-
(0, ava_1.default)("fetch: should handle empty (object) responses", async (t) => {
|
|
86
|
-
const url = "https://jsonplaceholder.typicode.com/todos/empty-object";
|
|
87
|
-
const resp = await (0, fetch_1.fetch)(url);
|
|
88
|
-
t.deepEqual(resp.data, {});
|
|
89
|
-
t.is(resp.ok, true);
|
|
90
|
-
t.is(resp.status, http_status_codes_1.StatusCodes.OK);
|
|
91
|
-
});
|
|
92
|
-
(0, ava_1.default)("fetch: should handle failed requests without throwing an error", async (t) => {
|
|
93
|
-
const url = "https://jsonplaceholder.typicode.com/todos/invalid";
|
|
94
|
-
const resp = await (0, fetch_1.fetch)(url);
|
|
95
|
-
t.is(resp.data, undefined);
|
|
96
|
-
t.is(resp.ok, false);
|
|
97
|
-
t.is(resp.status, http_status_codes_1.StatusCodes.BAD_REQUEST);
|
|
98
|
-
});
|