Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(testResult): transform undefined to null when serializing test result #6380

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion core/src/plugins/kubernetes/test-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type { TestActionHandler } from "../../plugin/action-types.js"
import { runResultToActionState } from "../../actions/base.js"
import type { HelmPodTestAction } from "./helm/config.js"
import type { KubernetesTestAction } from "./kubernetes-type/config.js"
import { GardenError } from "../../exceptions.js"

// TODO: figure out how to get rid of the any cast
export const k8sGetTestResult: TestActionHandler<"getResult", any> = async (params) => {
Expand Down Expand Up @@ -57,7 +58,7 @@ export const k8sGetTestResult: TestActionHandler<"getResult", any> = async (para

export function getTestResultKey(ctx: PluginContext, action: StoreTestResultParams["action"]) {
// change the result format version if the result format changes breaking backwards-compatibility e.g. serialization format
const resultFormatVersion = 1
const resultFormatVersion = 2
const key = `${ctx.projectName}--${action.name}--${action.versionString()}--${resultFormatVersion}`
const hash = hashSync(key, { algorithm: "sha1" })
return `test-result--${hash.slice(0, 32)}`
Expand Down Expand Up @@ -95,6 +96,9 @@ export async function storeTestResult({ ctx, log, action, result }: StoreTestRes
data,
})
} catch (err) {
if (!(err instanceof GardenError)) {
throw err
}
log.warn(`Unable to store test result: ${err}`)
}

Expand Down
5 changes: 3 additions & 2 deletions core/src/util/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ export async function loadYamlFile(path: string): Promise<any> {
}

export function serializeObject(o: any): string {
return Buffer.from(JSON.stringify(o)).toString("base64")
return Buffer.from(JSON.stringify(o === undefined ? null : o)).toString("base64")
}

export function deserializeObject(s: string) {
return JSON.parse(Buffer.from(s, "base64").toString())
const parsed = JSON.parse(Buffer.from(s, "base64").toString())
return parsed === null ? undefined : parsed
}

export function serializeValues(o: { [key: string]: any }): { [key: string]: string } {
Expand Down