@appthrust/kest 0.3.0 → 0.3.1

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/ts/retry.ts CHANGED
@@ -77,7 +77,6 @@ export async function retryUntil<T>(
77
77
  }
78
78
 
79
79
  retries += 1;
80
- recorder?.record("RetryAttempt", { attempt: retries });
81
80
 
82
81
  try {
83
82
  const value = await fn();
@@ -89,11 +88,6 @@ export async function retryUntil<T>(
89
88
  return value;
90
89
  } catch (err) {
91
90
  lastError = err;
92
- const error = err as Error;
93
- recorder?.record("RetryFailure", {
94
- attempt: retries,
95
- error: { name: error.name, message: error.message },
96
- });
97
91
  }
98
92
  }
99
93
 
@@ -7,6 +7,7 @@ import { applyStatus } from "../actions/apply-status";
7
7
  import { assert } from "../actions/assert";
8
8
  import { assertAbsence } from "../actions/assert-absence";
9
9
  import { assertList } from "../actions/assert-list";
10
+ import { create } from "../actions/create";
10
11
  import { deleteResource } from "../actions/delete";
11
12
  import { exec } from "../actions/exec";
12
13
  import { get } from "../actions/get";
@@ -33,9 +34,9 @@ export interface InternalScenario extends Scenario {
33
34
 
34
35
  export function createScenario(deps: CreateScenarioOptions): InternalScenario {
35
36
  const { recorder, reporter, reverting } = deps;
36
- recorder.record("ScenarioStarted", { name: deps.name });
37
37
  return {
38
38
  apply: createMutateFn(deps, apply),
39
+ create: createMutateFn(deps, create),
39
40
  applyStatus: createOneWayMutateFn(deps, applyStatus),
40
41
  delete: createOneWayMutateFn(deps, deleteResource),
41
42
  label: createOneWayMutateFn(deps, label),
@@ -83,17 +84,25 @@ const createMutateFn =
83
84
  options?: undefined | ActionOptions
84
85
  ): Promise<Output> => {
85
86
  const { recorder, kubectl, reverting } = deps;
86
- const { type, name, mutate } = action;
87
- recorder.record("ActionStart", { action: name, phase: type });
87
+ const { mutate, describe } = action;
88
+ function recordActionStart() {
89
+ recorder.record("ActionStart", {
90
+ description: describe(input),
91
+ });
92
+ }
93
+ function recordActionEnd(error: undefined | Error) {
94
+ recorder.record("ActionEnd", { ok: error === undefined, error });
95
+ }
96
+ recordActionStart();
88
97
  const fn = mutate({ kubectl });
89
- let mutateErr: unknown;
98
+ let mutateErr: undefined | Error;
90
99
  try {
91
100
  const { revert, output } = await retryUntil(() => fn(input), {
92
101
  ...options,
93
102
  recorder,
94
103
  });
95
104
  reverting.add(async () => {
96
- recorder.record("ActionStart", { action: name, phase: "revert" });
105
+ recordActionStart(); // to record revert action start
97
106
  let revertErr: unknown;
98
107
  try {
99
108
  await revert();
@@ -101,25 +110,15 @@ const createMutateFn =
101
110
  revertErr = err;
102
111
  throw err;
103
112
  } finally {
104
- recorder.record("ActionEnd", {
105
- action: name,
106
- phase: "revert",
107
- ok: revertErr === undefined,
108
- error: revertErr as Error,
109
- });
113
+ recordActionEnd(revertErr as Error); // to record revert action end
110
114
  }
111
115
  });
112
116
  return output;
113
117
  } catch (error) {
114
- mutateErr = error;
118
+ mutateErr = error as Error;
115
119
  throw error;
116
120
  } finally {
117
- recorder.record("ActionEnd", {
118
- action: name,
119
- phase: type,
120
- ok: mutateErr === undefined,
121
- error: mutateErr as Error,
122
- });
121
+ recordActionEnd(mutateErr as Error);
123
122
  }
124
123
  };
125
124
 
@@ -137,8 +136,8 @@ const createOneWayMutateFn =
137
136
  options?: undefined | ActionOptions
138
137
  ): Promise<Output> => {
139
138
  const { recorder, kubectl } = deps;
140
- const { name, mutate } = action;
141
- recorder.record("ActionStart", { action: name, phase: "mutate" });
139
+ const { mutate, describe } = action;
140
+ recorder.record("ActionStart", { description: describe(input) });
142
141
  const fn = mutate({ kubectl });
143
142
  let mutateErr: unknown;
144
143
  try {
@@ -148,8 +147,6 @@ const createOneWayMutateFn =
148
147
  throw error;
149
148
  } finally {
150
149
  recorder.record("ActionEnd", {
151
- action: name,
152
- phase: "mutate",
153
150
  ok: mutateErr === undefined,
154
151
  error: mutateErr as Error,
155
152
  });
@@ -170,19 +167,20 @@ const createQueryFn =
170
167
  options?: undefined | ActionOptions
171
168
  ): Promise<Output> => {
172
169
  const { recorder, kubectl } = deps;
173
- const { type, name, query } = action;
174
- recorder.record("ActionStart", { action: name, phase: type });
170
+ const { query, describe } = action;
171
+ recorder.record("ActionStart", { description: describe(input) });
175
172
  const fn = query({ kubectl });
173
+ let queryErr: unknown;
176
174
  try {
177
175
  return await retryUntil(() => fn(input), { ...options, recorder });
178
176
  } catch (error) {
177
+ queryErr = error;
178
+ throw error;
179
+ } finally {
179
180
  recorder.record("ActionEnd", {
180
- action: name,
181
- phase: type,
182
- ok: false,
183
- error: error as Error,
181
+ ok: queryErr === undefined,
182
+ error: queryErr as Error,
184
183
  });
185
- throw error;
186
184
  }
187
185
  };
188
186
 
@@ -202,6 +200,7 @@ const createNewNamespaceFn =
202
200
  return {
203
201
  name: namespaceName,
204
202
  apply: createMutateFn(namespacedDeps, apply),
203
+ create: createMutateFn(namespacedDeps, create),
205
204
  applyStatus: createOneWayMutateFn(namespacedDeps, applyStatus),
206
205
  delete: createOneWayMutateFn(namespacedDeps, deleteResource),
207
206
  label: createOneWayMutateFn(namespacedDeps, label),
@@ -224,6 +223,7 @@ const createUseClusterFn =
224
223
  const clusterDeps = { ...scenarioDeps, kubectl: clusterKubectl };
225
224
  return {
226
225
  apply: createMutateFn(clusterDeps, apply),
226
+ create: createMutateFn(clusterDeps, create),
227
227
  applyStatus: createOneWayMutateFn(clusterDeps, applyStatus),
228
228
  delete: createOneWayMutateFn(clusterDeps, deleteResource),
229
229
  label: createOneWayMutateFn(clusterDeps, label),
package/ts/test.ts CHANGED
@@ -59,7 +59,7 @@ function makeScenarioTest(runner: BunTestRunner): TestFunction {
59
59
  reverting,
60
60
  reporter,
61
61
  });
62
-
62
+ recorder.record("ScenarioStart", { name: label });
63
63
  let testErr: undefined | Error;
64
64
  try {
65
65
  await fn(scenario);
@@ -67,6 +67,7 @@ function makeScenarioTest(runner: BunTestRunner): TestFunction {
67
67
  testErr = error as Error;
68
68
  }
69
69
  await scenario.cleanup();
70
+ recorder.record("ScenarioEnd", {});
70
71
  await report(recorder, scenario, testErr);
71
72
  if (testErr) {
72
73
  throw testErr;
File without changes