From d16d1f81b04df2adce9f39cf629e97e62591b63d Mon Sep 17 00:00:00 2001 From: Phillip Wittrock Date: Tue, 5 May 2020 14:35:27 -0700 Subject: [PATCH] add starlark e2e tests --- cmd/config/internal/commands/e2e/e2e_test.go | 123 ++++++++++++++++++- 1 file changed, 121 insertions(+), 2 deletions(-) diff --git a/cmd/config/internal/commands/e2e/e2e_test.go b/cmd/config/internal/commands/e2e/e2e_test.go index 09a9030b4..93a39427d 100644 --- a/cmd/config/internal/commands/e2e/e2e_test.go +++ b/cmd/config/internal/commands/e2e/e2e_test.go @@ -136,8 +136,11 @@ metadata: }, }, + // + // Starklark function tests + // { - name: "exec_function_config_args", + name: "exec_function_config", args: func(d string) []string { return []string{"--enable-exec"} }, @@ -395,7 +398,7 @@ metadata: }, { - name: "container_function_config_args", + name: "container_function_config", skipIfFalseEnv: "KUSTOMIZE_DOCKER_E2E", args: func(d string) []string { return []string{} }, files: func(d string) map[string]string { @@ -450,6 +453,122 @@ metadata: a-string-value: 'a' a-int-value: '2' a-bool-value: 'true' +`, + } + }, + }, + + { + name: "starlark_function_config", + args: func(d string) []string { return []string{"--enable-star"} }, + files: func(d string) map[string]string { + return map[string]string{ + "script.star": ` +# set the foo annotation on each resource +def run(r, fc): + for resource in r: + resource["metadata"]["annotations"]["a-string-value"] = fc["data"]["stringValue"] + resource["metadata"]["annotations"]["a-int-value"] = fc["data"]["intValue"] + resource["metadata"]["annotations"]["a-bool-value"] = fc["data"]["boolValue"] + +run(ctx.resource_list["items"], ctx.resource_list["functionConfig"]) +`, + "config.yaml": ` +apiVersion: example.com/v1alpha1 +kind: Input +metadata: + name: foo + annotations: + config.kubernetes.io/function: | + starlark: + path: script.star + name: fn +data: + boolValue: true + intValue: 2 + stringValue: a +`, + "deployment.yaml": ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: foo +`, + } + }, + expectedFiles: func(d string) map[string]string { + return map[string]string{ + "config.yaml": ` +apiVersion: example.com/v1alpha1 +kind: Input +metadata: + name: foo + annotations: + a-bool-value: true + a-int-value: 2 + a-string-value: a + config.kubernetes.io/function: | + starlark: + path: script.star + name: fn +data: + boolValue: true + intValue: 2 + stringValue: a +`, + "deployment.yaml": ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: foo + annotations: + a-bool-value: true + a-int-value: 2 + a-string-value: a +`, + } + }, + }, + + { + name: "starlark_function_path", + args: func(d string) []string { + return []string{ + "--enable-star", "--star-path", "script.star", + "--", "stringValue=a", "intValue=2", "boolValue=true", + } + }, + files: func(d string) map[string]string { + return map[string]string{ + "script.star": ` +# set the foo annotation on each resource +def run(r, fc): + for resource in r: + resource["metadata"]["annotations"]["a-string-value"] = fc["data"]["stringValue"] + resource["metadata"]["annotations"]["a-int-value"] = fc["data"]["intValue"] + resource["metadata"]["annotations"]["a-bool-value"] = fc["data"]["boolValue"] + +run(ctx.resource_list["items"], ctx.resource_list["functionConfig"]) +`, + "deployment.yaml": ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: foo +`, + } + }, + expectedFiles: func(d string) map[string]string { + return map[string]string{ + "deployment.yaml": ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: foo + annotations: + a-bool-value: true + a-int-value: 2 + a-string-value: a `, } },