From 3fe189bef5694ff88fc3f13ea26b02c44008ad85 Mon Sep 17 00:00:00 2001 From: twobiers <22715034+twobiers@users.noreply.github.com> Date: Thu, 29 Aug 2024 21:10:39 +0200 Subject: [PATCH 1/6] implement helper function for environment variables Signed-off-by: twobiers <22715034+twobiers@users.noreply.github.com> --- README.md | 24 +++--- .../functions/getCompositionEnvVar/README.md | 2 + .../getCompositionEnvVar/composition.yaml | 31 +++++++ .../getCompositionEnvVar/environment.yaml | 6 ++ .../getCompositionEnvVar/functions.yaml | 6 ++ .../functions/getCompositionEnvVar/xr.yaml | 10 +++ function_maps.go | 12 +++ function_maps_test.go | 82 +++++++++++++++++++ 8 files changed, 162 insertions(+), 11 deletions(-) create mode 100644 example/functions/getCompositionEnvVar/README.md create mode 100644 example/functions/getCompositionEnvVar/composition.yaml create mode 100644 example/functions/getCompositionEnvVar/environment.yaml create mode 100644 example/functions/getCompositionEnvVar/functions.yaml create mode 100644 example/functions/getCompositionEnvVar/xr.yaml diff --git a/README.md b/README.md index e6deb00..1cc28fe 100644 --- a/README.md +++ b/README.md @@ -323,17 +323,19 @@ conditions: ## Additional functions -| Name | Description | -|------------------------------------------------------------------|--------------------------------------------------------------| -| [`randomChoice`](example/inline) | Randomly selects one of a given strings | -| [`toYaml`](example/functions/toYaml) | Marshals any object into a YAML string | -| [`fromYaml`](example/functions/fromYaml) | Unmarshals a YAML string into an object | -| [`getResourceCondition`](example/functions/getResourceCondition) | Helper function to retrieve conditions of resources | -| [`getComposedResource`](example/functions/getComposedResource) | Helper function to retrieve observed composed resources | -| [`getCompositeResource`](example/functions/getCompositeResource) | Helper function to retrieve the observed composite resource | -| [`getExtraResources`](example/functions/getExtraResources) | Helper function to retrieve extra resources | -| [`setResourceNameAnnotation`](example/inline) | Returns the special resource-name annotation with given name | -| [`include`](example/functions/include) | Outputs template as a string | +| Name | Description | +| ---------------------------------------------------------------- | ---------------------------------------------------------------------------- | +| [`randomChoice`](example/inline) | Randomly selects one of a given strings | +| [`toYaml`](example/functions/toYaml) | Marshals any object into a YAML string | +| [`fromYaml`](example/functions/fromYaml) | Unmarshals a YAML string into an object | +| [`getResourceCondition`](example/functions/getResourceCondition) | Helper function to retrieve conditions of resources | +| [`getComposedResource`](example/functions/getComposedResource) | Helper function to retrieve observed composed resources | +| [`getCompositeResource`](example/functions/getCompositeResource) | Helper function to retrieve the observed composite resource | +| [`getExtraResources`](example/functions/getExtraResources) | Helper function to retrieve extra resources | +| [`getCompositeResource`](example/functions/getCompositeResource) | Helper function to retreive the observed composite resource | +| [`getCompositionEnvVar`](example/functions/getCompositionEnvVar) | Helper function to retreive an environment variable from the request context | +| [`setResourceNameAnnotation`](example/inline) | Returns the special resource-name annotation with given name | +| [`include`](example/functions/include) | Outputs template as a string | ## Developing this function diff --git a/example/functions/getCompositionEnvVar/README.md b/example/functions/getCompositionEnvVar/README.md new file mode 100644 index 0000000..1d7bc2b --- /dev/null +++ b/example/functions/getCompositionEnvVar/README.md @@ -0,0 +1,2 @@ +# getCompositionEnvVar +The getCompositionEnvVar function is a helper function used to retrieve [environment variables](https://docs.crossplane.io/latest/concepts/environment-configs/) from the request context. Upon successful retrieval, the function returns a string containing the variable. If no variable with the key exists, an empty string is returned. diff --git a/example/functions/getCompositionEnvVar/composition.yaml b/example/functions/getCompositionEnvVar/composition.yaml new file mode 100644 index 0000000..4891dde --- /dev/null +++ b/example/functions/getCompositionEnvVar/composition.yaml @@ -0,0 +1,31 @@ +apiVersion: apiextensions.crossplane.io/v1 +kind: Composition +metadata: + name: example-function-get-composition-env-var +spec: + compositeTypeRef: + apiVersion: example.crossplane.io/v1beta1 + kind: XR + mode: Pipeline + pipeline: + - step: render-templates + functionRef: + name: function-go-templating + input: + apiVersion: gotemplating.fn.crossplane.io/v1beta1 + kind: GoTemplate + source: Inline + inline: + template: | + --- + apiVersion: dbforpostgresql.azure.upbound.io/v1beta1 + kind: FlexibleServer + metadata: + annotations: + {{ setResourceNameAnnotation "flexserver" }} + gotemplating.fn.crossplane.io/ready: "False" + spec: + forProvider: + + # Retrieve AdminLogin from request context + adminLogin: {{ getCompositionEnvVar . "adminLogin" }} \ No newline at end of file diff --git a/example/functions/getCompositionEnvVar/environment.yaml b/example/functions/getCompositionEnvVar/environment.yaml new file mode 100644 index 0000000..6fdeeee --- /dev/null +++ b/example/functions/getCompositionEnvVar/environment.yaml @@ -0,0 +1,6 @@ +apiVersion: apiextensions.crossplane.io/v1alpha1 +kind: EnvironmentConfig +metadata: + name: example-environment +data: + adminLogin: admin \ No newline at end of file diff --git a/example/functions/getCompositionEnvVar/functions.yaml b/example/functions/getCompositionEnvVar/functions.yaml new file mode 100644 index 0000000..6ce853e --- /dev/null +++ b/example/functions/getCompositionEnvVar/functions.yaml @@ -0,0 +1,6 @@ +apiVersion: pkg.crossplane.io/v1beta1 +kind: Function +metadata: + name: function-go-templating +spec: + package: xpkg.upbound.io/crossplane-contrib/function-go-templating:v0.5.0 diff --git a/example/functions/getCompositionEnvVar/xr.yaml b/example/functions/getCompositionEnvVar/xr.yaml new file mode 100644 index 0000000..f5e62b5 --- /dev/null +++ b/example/functions/getCompositionEnvVar/xr.yaml @@ -0,0 +1,10 @@ +apiVersion: example.crossplane.io/v1beta1 +kind: XR +metadata: + name: example +spec: + environment: + environmentConfigs: + - type: Reference + ref: + name: example-environment diff --git a/function_maps.go b/function_maps.go index 6ce1b3b..4867238 100644 --- a/function_maps.go +++ b/function_maps.go @@ -27,6 +27,7 @@ var funcMaps = []template.FuncMap{ "getComposedResource": getComposedResource, "getCompositeResource": getCompositeResource, "getExtraResources": getExtraResources, + "getCompositionEnvVar": getCompositionEnvVar, }, } @@ -143,3 +144,14 @@ func getExtraResources(req map[string]any, name string) []any { return ers } + +func getCompositionEnvVar(req map[string]any, name string) (string, error) { + path := fmt.Sprintf("context[\"apiextensions.crossplane.io/environment\"][\"%s\"]", name) + + env, err := fieldpath.Pave(req).GetString(path) + if err != nil { + return "", err + } + + return env, nil +} diff --git a/function_maps_test.go b/function_maps_test.go index 1bde121..53034a8 100644 --- a/function_maps_test.go +++ b/function_maps_test.go @@ -581,3 +581,85 @@ func Test_getExtraResources(t *testing.T) { }) } } + +func Test_getCompositionEnvVar(t *testing.T) { + type args struct { + req map[string]any + name string + } + + type want struct { + rsp string + err error + } + + cases := map[string]struct { + reason string + args args + want want + }{ + "RetrieveCompositionEnvVar": { + reason: "Should successfully retrieve a composition env var", + args: args{ + req: map[string]any{ + "context": map[string]any{ + "apiextensions.crossplane.io/environment": map[string]any{ + "test": "abc", + }, + }, + }, + name: "test", + }, + want: want{ + rsp: "abc", + err: nil, + }, + }, + "RetrieveCompositionEnvVarCaseInsensitive": { + reason: "Should successfully retrieve a composition env var case insensitive", + args: args{ + req: map[string]any{ + "context": map[string]any{ + "apiextensions.crossplane.io/environment": map[string]any{ + "TEST": "abc", + }, + }, + }, + name: "TEST", + }, + want: want{ + rsp: "abc", + err: nil, + }, + }, + "NotExistingEnvVar": { + reason: "Should return empty string when env var does not exist", + args: args{ + req: map[string]any{ + "context": map[string]any{ + "apiextensions.crossplane.io/environment": map[string]any{}, + }, + }, + name: "test", + }, + want: want{ + rsp: "", + err: cmpopts.AnyError, + }, + }, + } + + for name, tc := range cases { + t.Run(name, func(t *testing.T) { + rsp, err := getCompositionEnvVar(tc.args.req, tc.args.name) + + if diff := cmp.Diff(tc.want.rsp, rsp, protocmp.Transform()); diff != "" { + t.Errorf("%s\ngetCompositionEnvVar(...): -want rsp, +got rsp:\n%s", tc.reason, diff) + } + + if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { + t.Errorf("%s\ntgetCompositionEnvVar(...): -want err, +got err:\n%s", tc.reason, diff) + } + }) + } +} From a50ac982bf95e147f2bf503a551b48fffb55b21a Mon Sep 17 00:00:00 2001 From: twobiers <22715034+twobiers@users.noreply.github.com> Date: Thu, 29 Aug 2024 21:25:03 +0200 Subject: [PATCH 2/6] use backtick string Signed-off-by: twobiers <22715034+twobiers@users.noreply.github.com> --- function_maps.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/function_maps.go b/function_maps.go index 4867238..01c25ec 100644 --- a/function_maps.go +++ b/function_maps.go @@ -146,7 +146,7 @@ func getExtraResources(req map[string]any, name string) []any { } func getCompositionEnvVar(req map[string]any, name string) (string, error) { - path := fmt.Sprintf("context[\"apiextensions.crossplane.io/environment\"][\"%s\"]", name) + path := fmt.Sprintf(`context["apiextensions.crossplane.io/environment"]["%s"]`, name) env, err := fieldpath.Pave(req).GetString(path) if err != nil { From 313e80556768d64a4c11cb70e39c89de95df0eb1 Mon Sep 17 00:00:00 2001 From: twobiers <22715034+twobiers@users.noreply.github.com> Date: Mon, 25 Aug 2025 16:56:15 +0200 Subject: [PATCH 3/6] return `any` type instead of string Signed-off-by: twobiers <22715034+twobiers@users.noreply.github.com> --- function_maps.go | 6 +++--- function_maps_test.go | 44 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/function_maps.go b/function_maps.go index 01c25ec..c5e695e 100644 --- a/function_maps.go +++ b/function_maps.go @@ -145,12 +145,12 @@ func getExtraResources(req map[string]any, name string) []any { return ers } -func getCompositionEnvVar(req map[string]any, name string) (string, error) { +func getCompositionEnvVar(req map[string]any, name string) (any, error) { path := fmt.Sprintf(`context["apiextensions.crossplane.io/environment"]["%s"]`, name) - env, err := fieldpath.Pave(req).GetString(path) + env, err := fieldpath.Pave(req).GetValue(path) if err != nil { - return "", err + return nil, err } return env, nil diff --git a/function_maps_test.go b/function_maps_test.go index 53034a8..5a84adb 100644 --- a/function_maps_test.go +++ b/function_maps_test.go @@ -589,7 +589,7 @@ func Test_getCompositionEnvVar(t *testing.T) { } type want struct { - rsp string + rsp any err error } @@ -632,8 +632,46 @@ func Test_getCompositionEnvVar(t *testing.T) { err: nil, }, }, + "RetrieveCompositionEnvVarList": { + reason: "Should successfully retrieve a composition env var as a list", + args: args{ + req: map[string]any{ + "context": map[string]any{ + "apiextensions.crossplane.io/environment": map[string]any{ + "test": []string{"abc"}, + }, + }, + }, + name: "test", + }, + want: want{ + rsp: []string{"abc"}, + err: nil, + }, + }, + "RetrieveCompositionEnvVarMap": { + reason: "Should successfully retrieve a composition env var as a map", + args: args{ + req: map[string]any{ + "context": map[string]any{ + "apiextensions.crossplane.io/environment": map[string]any{ + "test": map[string]any{ + "key": "abc", + }, + }, + }, + }, + name: "test", + }, + want: want{ + rsp: map[string]any{ + "key": "abc", + }, + err: nil, + }, + }, "NotExistingEnvVar": { - reason: "Should return empty string when env var does not exist", + reason: "Should return nil when env var does not exist", args: args{ req: map[string]any{ "context": map[string]any{ @@ -643,7 +681,7 @@ func Test_getCompositionEnvVar(t *testing.T) { name: "test", }, want: want{ - rsp: "", + rsp: nil, err: cmpopts.AnyError, }, }, From 56953634db6448910595a1251b3be441d8c8dbc0 Mon Sep 17 00:00:00 2001 From: twobiers <22715034+twobiers@users.noreply.github.com> Date: Mon, 25 Aug 2025 16:59:47 +0200 Subject: [PATCH 4/6] update documentation Signed-off-by: twobiers <22715034+twobiers@users.noreply.github.com> --- example/functions/getCompositionEnvVar/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/functions/getCompositionEnvVar/README.md b/example/functions/getCompositionEnvVar/README.md index 1d7bc2b..e0c11f7 100644 --- a/example/functions/getCompositionEnvVar/README.md +++ b/example/functions/getCompositionEnvVar/README.md @@ -1,2 +1,2 @@ # getCompositionEnvVar -The getCompositionEnvVar function is a helper function used to retrieve [environment variables](https://docs.crossplane.io/latest/concepts/environment-configs/) from the request context. Upon successful retrieval, the function returns a string containing the variable. If no variable with the key exists, an empty string is returned. +The getCompositionEnvVar function is a helper function used to retrieve [environment variables](https://docs.crossplane.io/latest/composition/environment-configs) from the request context. Upon successful retrieval, the function returns the value. If no variable with the key exists, nil is returned. From 96e4b9b71c60bc37d38a9d585f78dd2b760c6a20 Mon Sep 17 00:00:00 2001 From: twobiers <22715034+twobiers@users.noreply.github.com> Date: Mon, 25 Aug 2025 17:18:26 +0200 Subject: [PATCH 5/6] fix typo `retreive` -> `retrieve` Signed-off-by: twobiers <22715034+twobiers@users.noreply.github.com> --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1cc28fe..85a2b39 100644 --- a/README.md +++ b/README.md @@ -332,8 +332,8 @@ conditions: | [`getComposedResource`](example/functions/getComposedResource) | Helper function to retrieve observed composed resources | | [`getCompositeResource`](example/functions/getCompositeResource) | Helper function to retrieve the observed composite resource | | [`getExtraResources`](example/functions/getExtraResources) | Helper function to retrieve extra resources | -| [`getCompositeResource`](example/functions/getCompositeResource) | Helper function to retreive the observed composite resource | -| [`getCompositionEnvVar`](example/functions/getCompositionEnvVar) | Helper function to retreive an environment variable from the request context | +| [`getCompositeResource`](example/functions/getCompositeResource) | Helper function to retrieve the observed composite resource | +| [`getCompositionEnvVar`](example/functions/getCompositionEnvVar) | Helper function to retrieve an environment variable from the request context | | [`setResourceNameAnnotation`](example/inline) | Returns the special resource-name annotation with given name | | [`include`](example/functions/include) | Outputs template as a string | From e35630f8556d5a45c6c2791a0ad9a177cbc1673e Mon Sep 17 00:00:00 2001 From: twobiers <22715034+twobiers@users.noreply.github.com> Date: Thu, 28 Aug 2025 10:54:21 +0200 Subject: [PATCH 6/6] Rename to `getCompositionEnvironment` Signed-off-by: twobiers <22715034+twobiers@users.noreply.github.com> --- README.md | 26 +++++++++---------- .../functions/getCompositionEnvVar/README.md | 2 -- .../getCompositionEnvironment/README.md | 2 ++ .../composition.yaml | 4 +-- .../environment.yaml | 0 .../functions.yaml | 0 .../xr.yaml | 6 ++--- function_maps.go | 4 +-- function_maps_test.go | 8 +++--- 9 files changed, 26 insertions(+), 26 deletions(-) delete mode 100644 example/functions/getCompositionEnvVar/README.md create mode 100644 example/functions/getCompositionEnvironment/README.md rename example/functions/{getCompositionEnvVar => getCompositionEnvironment}/composition.yaml (91%) rename example/functions/{getCompositionEnvVar => getCompositionEnvironment}/environment.yaml (100%) rename example/functions/{getCompositionEnvVar => getCompositionEnvironment}/functions.yaml (100%) rename example/functions/{getCompositionEnvVar => getCompositionEnvironment}/xr.yaml (62%) diff --git a/README.md b/README.md index 85a2b39..d99436b 100644 --- a/README.md +++ b/README.md @@ -323,19 +323,19 @@ conditions: ## Additional functions -| Name | Description | -| ---------------------------------------------------------------- | ---------------------------------------------------------------------------- | -| [`randomChoice`](example/inline) | Randomly selects one of a given strings | -| [`toYaml`](example/functions/toYaml) | Marshals any object into a YAML string | -| [`fromYaml`](example/functions/fromYaml) | Unmarshals a YAML string into an object | -| [`getResourceCondition`](example/functions/getResourceCondition) | Helper function to retrieve conditions of resources | -| [`getComposedResource`](example/functions/getComposedResource) | Helper function to retrieve observed composed resources | -| [`getCompositeResource`](example/functions/getCompositeResource) | Helper function to retrieve the observed composite resource | -| [`getExtraResources`](example/functions/getExtraResources) | Helper function to retrieve extra resources | -| [`getCompositeResource`](example/functions/getCompositeResource) | Helper function to retrieve the observed composite resource | -| [`getCompositionEnvVar`](example/functions/getCompositionEnvVar) | Helper function to retrieve an environment variable from the request context | -| [`setResourceNameAnnotation`](example/inline) | Returns the special resource-name annotation with given name | -| [`include`](example/functions/include) | Outputs template as a string | +| Name | Description | +| -------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | +| [`randomChoice`](example/inline) | Randomly selects one of a given strings | +| [`toYaml`](example/functions/toYaml) | Marshals any object into a YAML string | +| [`fromYaml`](example/functions/fromYaml) | Unmarshals a YAML string into an object | +| [`getResourceCondition`](example/functions/getResourceCondition) | Helper function to retrieve conditions of resources | +| [`getComposedResource`](example/functions/getComposedResource) | Helper function to retrieve observed composed resources | +| [`getCompositeResource`](example/functions/getCompositeResource) | Helper function to retrieve the observed composite resource | +| [`getExtraResources`](example/functions/getExtraResources) | Helper function to retrieve extra resources | +| [`getCompositeResource`](example/functions/getCompositeResource) | Helper function to retrieve the observed composite resource | +| [`getCompositionEnvironment`](example/functions/getCompositionEnvironment) | Helper function to retrieve an environment variable from the request context | +| [`setResourceNameAnnotation`](example/inline) | Returns the special resource-name annotation with given name | +| [`include`](example/functions/include) | Outputs template as a string | ## Developing this function diff --git a/example/functions/getCompositionEnvVar/README.md b/example/functions/getCompositionEnvVar/README.md deleted file mode 100644 index e0c11f7..0000000 --- a/example/functions/getCompositionEnvVar/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# getCompositionEnvVar -The getCompositionEnvVar function is a helper function used to retrieve [environment variables](https://docs.crossplane.io/latest/composition/environment-configs) from the request context. Upon successful retrieval, the function returns the value. If no variable with the key exists, nil is returned. diff --git a/example/functions/getCompositionEnvironment/README.md b/example/functions/getCompositionEnvironment/README.md new file mode 100644 index 0000000..330383a --- /dev/null +++ b/example/functions/getCompositionEnvironment/README.md @@ -0,0 +1,2 @@ +# getCompositionEnvironment +The getCompositionEnvironment function is a helper function used to retrieve [environment variables](https://docs.crossplane.io/latest/composition/environment-configs) from the request context. Upon successful retrieval, the function returns the value. If no variable with the key exists, nil is returned. diff --git a/example/functions/getCompositionEnvVar/composition.yaml b/example/functions/getCompositionEnvironment/composition.yaml similarity index 91% rename from example/functions/getCompositionEnvVar/composition.yaml rename to example/functions/getCompositionEnvironment/composition.yaml index 4891dde..fee974c 100644 --- a/example/functions/getCompositionEnvVar/composition.yaml +++ b/example/functions/getCompositionEnvironment/composition.yaml @@ -26,6 +26,6 @@ spec: gotemplating.fn.crossplane.io/ready: "False" spec: forProvider: - + # Retrieve AdminLogin from request context - adminLogin: {{ getCompositionEnvVar . "adminLogin" }} \ No newline at end of file + adminLogin: {{ getCompositionEnvironment . "adminLogin" }} diff --git a/example/functions/getCompositionEnvVar/environment.yaml b/example/functions/getCompositionEnvironment/environment.yaml similarity index 100% rename from example/functions/getCompositionEnvVar/environment.yaml rename to example/functions/getCompositionEnvironment/environment.yaml diff --git a/example/functions/getCompositionEnvVar/functions.yaml b/example/functions/getCompositionEnvironment/functions.yaml similarity index 100% rename from example/functions/getCompositionEnvVar/functions.yaml rename to example/functions/getCompositionEnvironment/functions.yaml diff --git a/example/functions/getCompositionEnvVar/xr.yaml b/example/functions/getCompositionEnvironment/xr.yaml similarity index 62% rename from example/functions/getCompositionEnvVar/xr.yaml rename to example/functions/getCompositionEnvironment/xr.yaml index f5e62b5..0afa08d 100644 --- a/example/functions/getCompositionEnvVar/xr.yaml +++ b/example/functions/getCompositionEnvironment/xr.yaml @@ -5,6 +5,6 @@ metadata: spec: environment: environmentConfigs: - - type: Reference - ref: - name: example-environment + - type: Reference + ref: + name: example-environment diff --git a/function_maps.go b/function_maps.go index c5e695e..54e78e8 100644 --- a/function_maps.go +++ b/function_maps.go @@ -27,7 +27,7 @@ var funcMaps = []template.FuncMap{ "getComposedResource": getComposedResource, "getCompositeResource": getCompositeResource, "getExtraResources": getExtraResources, - "getCompositionEnvVar": getCompositionEnvVar, + "getCompositionEnvironment": getCompositionEnvironment, }, } @@ -145,7 +145,7 @@ func getExtraResources(req map[string]any, name string) []any { return ers } -func getCompositionEnvVar(req map[string]any, name string) (any, error) { +func getCompositionEnvironment(req map[string]any, name string) (any, error) { path := fmt.Sprintf(`context["apiextensions.crossplane.io/environment"]["%s"]`, name) env, err := fieldpath.Pave(req).GetValue(path) diff --git a/function_maps_test.go b/function_maps_test.go index 5a84adb..9daa2e0 100644 --- a/function_maps_test.go +++ b/function_maps_test.go @@ -582,7 +582,7 @@ func Test_getExtraResources(t *testing.T) { } } -func Test_getCompositionEnvVar(t *testing.T) { +func Test_getCompositionEnvironment(t *testing.T) { type args struct { req map[string]any name string @@ -689,14 +689,14 @@ func Test_getCompositionEnvVar(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { - rsp, err := getCompositionEnvVar(tc.args.req, tc.args.name) + rsp, err := getCompositionEnvironment(tc.args.req, tc.args.name) if diff := cmp.Diff(tc.want.rsp, rsp, protocmp.Transform()); diff != "" { - t.Errorf("%s\ngetCompositionEnvVar(...): -want rsp, +got rsp:\n%s", tc.reason, diff) + t.Errorf("%s\ngetCompositionEnvironment(...): -want rsp, +got rsp:\n%s", tc.reason, diff) } if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" { - t.Errorf("%s\ntgetCompositionEnvVar(...): -want err, +got err:\n%s", tc.reason, diff) + t.Errorf("%s\ntgetCompositionEnvironment(...): -want err, +got err:\n%s", tc.reason, diff) } }) }